How to append a UIImage or CGImage to an AVAssetWriter? - objective-c

Is it possible to convert a UIImage instance to a CMSampleBufferRef so that it can be appended to a specified output file using AVAssetWriter's appendSampleBuffer: method?
If so ... how?
Thanks

While I haven't really tried this one possibility is to create a CVPixelBuffer using CVPixelBufferCreateWithBytes, and pointing it to the raw pixels from the UIImage.
Once this is done, since CVPixelBuffers are just CVImageBuffers you can use CMSampleBufferCreateForImageBuffer to get a CMSampleBufferRef that you can then use the appendSampleBuffer method.
As I said previously I haven't ever tried this, but it looks plausible.

Related

Why is TIFFRepresentation bigger than the actual image file?

Here's the code I use:
NSImage *image = [[NSBundle bundleForClass:[self class]] imageForResource:#"test.jpg"];
NSData *originalData = [image TIFFRepresentationUsingCompression:NSTIFFCompressionJPEG factor:1.];
The originalData.length gives me 1802224 bytes (1.7MB). While the image size on the disk is 457KB. Why does TIFFRepresentation get larger and which representation I should use in order to get original image (i want to transfer image over the network)?
TIFF is much bigger than JPEG. No surprise there.
However, the answer to your actual question is: don't use any "representation". You have the data (namely, the file itself); send it! Don't turn the image file into an NSImage; grab it as an NSData.

Is it possible to create multiple images of different size given in json file from one single image using objective c or swift

Is it possible to create multiple images of different size given in json file from one single image using objective c or swift?
Please anyone can help me out,as I am new to this?
Yes it's possible.
UIGraphicsBeginImageContext(CGSizeMake(reSize.width, reSize.height));
[image drawInRect:CGRectMake(0, 0, reSize.width, reSize.height)];
UIImage *reSizeImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

Objective C - bold and change string text size for drawing text onto pdf

I've created a .xib file with a uiview solely for the pdf document that I have created. I've primarily followed this tutorial for code:
http://www.raywenderlich.com/6818/how-to-create-a-pdf-with-quartz-2d-in-ios-5-tutorial-part-2
From the above, I can't edit labels (plain or attributed) from the interface builder as even after changing size, it doesn't apply when the app is run. (I suspect the issue may lie within the methods drawText or drawLabels).
I then tried to create an attributed string, however the methods don't take it. I tried to convert the drawtext by copying and taking the argument of an nsmutableattributedstring however this caused problems with the CFStringRef.
I appreciate your time for any help.
Solved it by making a separate method as below (I used + since I have this inside an NSObject and is a class method rather than in a UIViewController):
+(void)addText:(NSString*)text withFrame:(CGRect)frame withFont:(UIFont*)font;
{
[text drawInRect:frame withFont:font];
}
Outside the method, declaring inputs and calling it:
UIFont *font = [UIFont fontWithName:#Helvetica-Bold" size:7];
[self addText: yourStringHere
withFrame:CGRectMake(yourXPosition, yourYPOsition, yourFrameWidth, yourFrameHeight)
withFont:font];
I wonder if it's much simplified like so because the tutorial I used is now outdated?
If anything I hope this helps others :)

How we can store CMTimeRange into NSMutableArray

I need to store CMTimeRange of different videos in array later i will merge these videos.
please answer if anybody know about it.any answer will be appreciated.....
Use CMTimeRangeCopyAsDictionary to create a CFDictionaryRef from your CMTimeRange, and use CMTimeRangeMakeFromDictionary to get your CMTimeRange back from the dictionary.
It should be possible to use the CMTimeRangeCopyAsDictionary function and save an array of dictionaries or failing that, you could save each time range using NSValue perhaps?

UIImage imageNamed size

New to Objective-C, Cocoa, and compiled languages in general so forgive my ignorance:
UIImage *myImage = [UIImage imageNamed:#"1-filter.jpg"];
NSLog(#"myImage.size=%#", myImage.size);
Results in
Thread 1: Porgram received signal: "EXC_BAD_ACCESS".
Why? How do I get the size of a UIImage?
The size is a structure.
Use either size.width, size.height or NSStringFromCGSize(myImage.size) for NSLog output.
This is a subtle, annoying-for-beginners error. (I actually just ran into this last week.)
When you use the format string %# in an NSLog, the argument must be some kind of Objective-C object. (Behind the scenes, when you do NSLog(#"%#", foo), the system calls [foo description] to figure out what string to output. If the variable you pass to NSLog is not an Objective-C object, the system will try to send a message to something that isn’t an object and then throw this error.)
In this particular case, you’re going to be getting an integer, so replace %# with %d in your format string to make everything work okay.
Additionally, as Eugene mentioned, you want to be accessing a part of the size object. So try
NSLog(#"size.height=%d", myImage.size.height);
Edit: this should actually be %f instead of %d, and please read the comments on this answer.