iOS: storing thumbnail images in Core Data - objective-c

I need to take some images from the iPhone / iPad photo library from within my app and store them in a Core Data entity, and display them as small thumbnail images (48x48 pixels) in a UITableViewCell, and about 80x80 pixels in a detail UIView. I've followed the Recipes sample app, where they use UIImageJPEGRepresentation(value, 0.1) to convert to NSData and store the bytes inside Core Data, and it doesn't end up taking much space, which is good. But when retrieve the data, using UIImage *uiImage = [[UIImage alloc] initWithData:value]; and display it as a thumbnail image with "Aspect Fit", it looks terrible and grainy. I tried changing the image quality variable in the JPEG compression, but even setting it to 0.9 doesn't help.
Is that normal? Is there a better way to compress the image that doesn't cause so much grainee-ness? Since I just want to show a small thumbnail, and then a slightly bigger thumbnail, I feel Core Data would be great for storing this, since it should (theoretically) also support iCloud. But if it's going to look terrible, then I'll have to reconsider.

Two things, are you resizing the image to the right size? Have you tried UIImagePNGRepresentation()? That should compress it without losing quality.

If UIImagePNGRepresentation (which is lossless) is giving you bad images, then the problem is in your image resizing code. Core Data is just giving you what you back what you put in, so if you get bad images out, it's because you put bad images in.
Is one of your iPhone/iPad retina and the other isn't? If so, perhaps the problem is that you don't really want 48x48 pixel images, you want 48x48 point (which means you'll need 2x images 96x96 for retina quality display).

Related

How to save UIView with subviews without losing quality?

I am trying to save the view with its subview, but the saved image is little bit blurry (especially the label's text)
I tried all the solutions given in stackoverflow - no use.
Can anyone help me on the same?
I am using the below code
UIGraphicsBeginImageContextWithOptions(view.bounds.size, NO, 0);
[view drawViewHierarchyInRect:view.bounds afterScreenUpdates:YES];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
And getting the blurred text, also the picture quality is low.
You could try a higher resolution image. It should be fine if you compress a high resolution image to down, but scaling up a low resolution image to a larger size will generally blur the image contents, as it stretches everything.
The preferred approach is [UIView snapshotViewAfterScreenUpdates:]. You should only use drawViewHierarchyInRect:afterScreenUpdates: if you plan to apply additional effects.
That said, there are several likely causes, depending on how you're manipulating or saving the image. For example, saving text in JPEG format will cause blurriness. Rotating or scaling the image without great care can make the text blurry. Drawing the image incorrectly (for instance, failing to pixel-align it) can make the text blurry. You should simplify your problem if you're making multiple steps, and validate the quality at each step. To discuss it further on StackOverflow, you need to provide details on how you're manipulating and displaying the image, not just how you generate it.
Text is extremely susceptible to artifacts. If you must take pictures of it (something you generally should avoid if at all possible), you should make sure to manipulate it as little as possible. It is always better to manipulate the text before it's drawn rather than after.

Titanium Images Wrong Size

I have a Titanium app where I am using the same ImageView for alot of different images. I am changing the image in the image view by setting it's image property.
The problem is some of the images are not showing at their full size sometimes, it is kinda random, but sometimes they show full size sometimes not.
I have width and height set to "auto" on the image view.
Anyone come across this issue.
A potentially more reliable way would be too dynamically resize the image before handing it off to the ImageView by using Titanium.Blob.imageAsReized.
Try to integrate this in your code, first you have to load the image as a blob though.
// Get the blob of your image first, then call this method
imageView.image = imageBlob.imageAsResized(newWidth, newHeight);

How to get crisp image for search result suggestion in Windows 8?

I'm using a 40 x 40 sized image as a search result suggestion image in Windows 8 search. Only advice about the image format I can find is to have correct size for it (http://msdn.microsoft.com/en-us/library/windows/apps/Hh700542.aspx: "Windows will scale or crop smaller or larger images").
However, the correctly sized image blurs annoyingly. The same thing happens whether I use jpg or png. Original image looks fine, but the result suggestion in the search charm is very ugly, being still of same size! Is Windows converting the image somehow, and how could I get the image to stay crisp?
I haven't noticed blurring with photo-like images, but this image contains clear lines and areas which are vulnerable to any scaling etc.
Update Sep 24:
Here is the test image I used when trying to figure out the problem. I also created different scale versions, but in my case the 100% version was used (that's why the "100" marking) - as I supposed because the resulting image really is 40x40. As you can see, the resulting image (right) is of same size as original (left), but blurry.
it does not happen that often but it seems the right solution in this case was simply to wait ;) I haven't done anything new regarding result suggestion images in my solution and today I realized that the images became crisp. Probably fixed by any of the windows updates.
[Took a stab at answering what seems the related question mentioned in the comments, so I'm posting here as well.]
It sounds like this could be related to automatic scaling of the images. Windows will automatically scale up/down based on pixel density, and you can help things scale well by either using vector-based images or, for bitmap images, supplying scale-specific versions.
For example, to scale an image referenced in markup as "AppLogo.jpg", you'd include these images:
AppLogo.scale-100.jpg
AppLogo.scale-140.jpg
AppLogo.scale-180.jpg
You can also use folders, e.g. "\scale-140\AppLogo.jpg".
For search result images, the 100% image is the 40x40 pixel version, 140 is 56x56, and 180 is 72x72. Just reference the image as "AppLogo.jpg" and the appropriate version will be used automatically. (You can also detect scale with DisplayProperties.ResolutionScale and manually choose an image.)
Here's a couple of articles with more examples/details:
"Guidelines for scaling to pixel density"
"Quickstart: Using file or image resources"
There's also some scaling discussion in the forums (general, not specific to search) here and here.

Making Images Viewed By UIWebView Smaller

i have a list of entries from a database and I'm feeding them in to HTML to a UIWebView that is making a list of the database entries on the page.
(Much Easyer/Better then extending UITableView Cells)
My Problem is with UITableView i was able to grab an image on a server as NSData and with UIImageJpegRepresentation set the quality for the image a bit lower to be better on the iPhone's cellular downloads.
Now i can go and grab an image from the server as NSData Compress the image then convert it to base 64string and spit it into the WebView but is there any other way to do this?
TLDR: How can i decrease the size of images seen in a HTML Page?
I fixed this by feeding the page i was going to visit to a web service. The web service then returns a set of images compressed at lower quality.
Because the only pages the app is going to visit were my own with user avatars and stuff i was able to profile what images would be needed.
On the iPhone i rebuilt the webpage with the set of those smaller images in a UIWebView.
So in the end i downloaded less cellular data and problem is solved.

Ideal image size and format

I'm building an image gallery type of application and i want to know what is the best image size and format (.png or .jpg) to be stored in the app.
I also want to know what is the best and most efficient way to store and load images natively.
PNGs are optimized for the OS when they are added to your app bundle. To improve performance of your app you want to:
Make sure the images have no alpha channel in them, otherwise the OS will try and blend them.
Resize your images to be the size they will end up in the UI. This will reduce the read bandwidth for the drawing, saving you memory and boosting performance.
Images in the app bundle can be read into UIImageViews:
UIImageView *newImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"myimage.png"]];
This will cache the image for you, which is good for lots of small images re-used a lot. For larger infrequently used images you want to use +imageFromContentsOfFile: instead of +imageNamed:
As far as I know iOS and xCode optimizes PNG formats and performs better with them.
You may want to check out this :
http://bjango.com/articles/pngcompression/