I need to perform UIImageJPEGRepresentation method and after that save it NOT to file, I need to save it to UIImage. Help please..
you can use this:
NSData *imageData = UIImageJPEGRepresentation(uiimageObject,1.0);
UIImage *imageObj = [UIImage imageWithData:imageData];
I have no idea why you are wanting to go from a UIImage to jpeg data and then right back to a UIImage, but [UIImage imageWithData:jpegdata] should do it.
Eh? UIImageJPEGRepresentation converts an image to JPEG data...
Related
Please help
Currently looking to create a new NSImage by resizing an original and then send it over to a web service along with its original EXIF data. I can resize the image no problem but the EXIF data is not present. The call to representationUsingType takes in the propertiesDict which is correct as per the Apple Docs :)
Can someone please point me in the correct dirrection please, here is my current implementation:
NSData *imageData = [resizedImage TIFFRepresentation]; //resized image is a my resized NSImage
NSBitmapImageRep * image = [[NSBitmapImageRep alloc] initWithData:imageData]; //NEED NSBitmapImageRepObject
NSMutableDictionary * propertiesDict = [[NSMutableDictionary alloc]init];
[propertiesDict setObject:[NSNumber numberWithInt:self.imageSizeSlider.floatValue] forKey:NSImageCompressionFactor];
[propertiesDict setObject:metaDataDict forKey:NSImageEXIFData];
NSData * shrunkImage = [image representationUsingType:NSJPEGFileType properties:propertiesDict];
If i writeToFile the shrunkImage object I get the image but with only the color profile in the exif? :(
The metaDataDict object has all the exif in I need and can be NSLogged to show that.
Any help much appreciated.
Regards,
Lee
You haven't shrunk the image, you've made a new image that's smaller than the original. Your new image has only the metadata that you give it.
Read the docs on NSImage and NSImageRep, and look up how to get and set EXIF data.
This question already has answers here:
UIImageWriteToSavedPhotosAlbum saves to wrong size and quality
(2 answers)
Closed 7 years ago.
I'm using code like the following to save the current screen to the photos library:
UIGraphicsBeginImageContext(self.view.bounds.size);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage* result = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum(result, nil,nil, nil);
This works, but the quality looks a lot like a compressed JPG (and the file name saved is in the standard IMG_XXXX.JPG format), even though nowhere in this code is the type of image or its quality specified. Is there a way to control quality? I.e. could I have it saved as an uncompressed PNG instead?
You can save it as a PNG by utilizing the UIImagePNGRepresentation() method for NSData, do something like this:
....
UIImage* result = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSData* data = UIImagePNGRepresentation ( result );
UIImage* pngImage = [UIImage imageWithData:data];
UIImageWriteToSavedPhotosAlbum(pngImage, nil, nil, nil);
Hope this helps.
I am looking for a class that will allow the user to draw?(the main purpose is to get their signature).
I checked Cocoa Controls but couldn't find such a class. Just want to now if there's any before I start writing it myself.
Thanks
Look at this tutorial: http://www.ifans.com/forums/showthread.php?t=132024
To get a JPG or PNG file, you can use the functions UIImageJPEGRepresentation or UIImagePNGRepresentation. They take a UIImage as input. And to get a UIImage from a UIView, you can use something like this.
UIGraphicsBeginImageContext(view.frame.size);
[view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
is it possible to convert the HTML page to image in cocoa?
Actually i have created the complete view in the HTML and now i want to convert the whole html preview to the image (any jpeg or png etc.).
I couldn't find any resource or sample on the web, which provides some sort of help on my above queries.It's highly appreciated if someone could share his wisdom on how I can achieve this.
Thanks in advance..
First off, I'd like to thank sergio... his answer got me started but I thought I'd share some of the code that I didn't find obvious that I had to write to make it work:
Here's how to make a thumbnail for a page without ever having it displayed:
// Your width and height can be whatever you like, but if you want this to render
// off screen, you need an x and y bigger than the superview's width and height
UIWebView* webView = [[UIWebView alloc] initWithFrame:CGRectMake(largerScreenDimension, largerScreenDimension, largerScreenDimension, largerScreenDimension)];
[self.view addSubview:webView]; // UIWebViews without an assigned superview don't load ever.
webView.delegate = self; // or whoever you have implement UIWebViewDelegate
webView.scalesToFit = YES; // This zooms the page appropriately to fill the entire thumbnail.
[webView loadRequest:[NSURLRequest requestWithURL:url]];
Then implement this in your delegate:
- (void)webViewDidFinishLoad:(UIWebView *)webView {
UIGraphicsBeginImageContext(webView.bounds.size);
[webView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *webViewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSData *thumbnailData = UIImagePNGRepresentation(webViewImage);
[webView removeFromSuperview];
}
Finally, to display this thumbnail you'll need something like:
thumbnailImageView.image = [UIImage imageWithData:thumbnailData];
As a bonus thing I'll mention, I wanted multiple thumbnails to be generated at once. I found using objc_setAssociatedObject() and objc_getAssociatedObject() to be very helpful with keeping track of which webView was loading which thumbnail. Going into detail on how that worked is beyond the scope of this question, though.
You can draw your view in an image context, like this:
UIWebView* view = ...
....
UIGraphicsBeginImageContext(view.bounds.size);
[view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSData *imagedata = UIImagePNGRepresentation(viewimage);
NSString *encodedString = [imageData base64Encoding];
Another option would be using Quartz PDF engine to create a PDF.
I Use the following code to load png image:
UIImage *imageBack1 = [UIImage imageNamed:#"Bar1.png"];
UIImage *imageBack2 = [UIImage imageNamed:#"Bar2.png"];
imageBack1 work right when imageBack2's value is nil, Bar1.png and Bar2.png are located at the same place,but why Bar2.png couldn't be load?
In fact , the problem come from the png file,but not cocoa. Iphoto couldn't recognize it.