Image overlapping in photo viewer on three20 framework? - iphone

I just integrated the photo viewer from three20 framework. Its working fine but some time images are overlapping, that ia happening only for thumnail image while original image is perfectly loaded. Till the original image loaded , at that point of time images are overlapping.
Did any one face this problem and have any solution for that?
Thanks

If images are overlapping, you are not correctly setting their size when you are including them in the photo view controller. You have to (unfortunately) tell three20 the exact size so it knows how to display them in paging mode of the scrollview.
Make sure you are resizing your thumbnails similar sizes to his (somewhere around 100 pixels tall or wide, based on if it's in portrait or landscape)
[[[MockPhoto alloc]
initWithURL:#"http://farm4.static.flickr.com/3444/3223645618_13fe36887a_o.jpg"
smallURL:#"http://farm4.static.flickr.com/3444/3223645618_f5e2fa7fea_t.jpg"
size:CGSizeMake(320, 480) // see how he sets the size here for each and every photo? this is crucial
caption:#"These are the wood tiles that we had installed after the accident."] autorelease],
If you look at the thumbnail, it is 67pixels by 100pixels: http://farm4.static.flickr.com/3444/3223645618_f5e2fa7fea_t.jpg
If you look at the regular photo, it is 320pixels by 480pixels. : http://farm4.static.flickr.com/3444/3223645618_13fe36887a_o.jpg
These are two independent files, the three20 code does not create the thumbnail for you based on the larger photo. You must do this manually or subclass whatever container class he uses to do it for you.

Just by setting line 135 of TTPhotoView.m to
self.contentMode = UIViewContentModeScaleAspectFit
will help.

Related

Camera images not displaying correctly

In my app, the user picks an image with UIImagePickerController. They can then view a gallery of the pictures they've selected. If they pick screenshots taken with the iphone, the images display correctly, but if they pick images taken with the camera (or take a new photo with the camera), after a short while an image will appear black, followed by every other image appearing black. I've tried for days to get rid of this behaviour without any success. The code is pretty straight forward:
if ([[info objectForKey:UIImagePickerControllerMediaType] isEqualToString:#"public.image"]) {
[mediaSource addImage:[info objectForKey:UIImagePickerControllerOriginalImage]];
}
mediaSource adds the image to an NSDictionary, and then the gallery puts this image into a uiimageview when it's needed, although for testing purposes i've tried simply displaying the image straight off, which gives the same result. The key variable here seems to be that it only happens with images from the camera, so perhaps the solution is to somehow remake these images before displaying them again.
Any ideas?
Its not [info objectForKey:UIImagePickerControllerOriginalImage].
Change this to [info valueForKey:UIImagePickerControllerOriginalImage] and try it.
And BTW, what is thumbnail?

Loading a 20MB png in a UIImageView embedded in a UIScrollView

I have a large png Image that I need to Zoom&Move.
I therefore created a UIScrollView and embedded a UIImageView.
The App works fine in the simulator, but when running it on the device (8GB iPod Touch) it crashes as soon as the view is loaded.
I tried with a smaller test Image (4MB) works fine and suspect the iPod can't handle a 20MB PNG. I also tried different other formats, such as JPG (in various save patterns), but that did't help either.
Any clues how I can solve this?
Ouch, 20M is a large image. The first thought that comes to mind is can you dice up the image? I.e. instead of one image have a whole bunch of small images which together make up the larger image. Then you can load on demand the same way google maps downloads image squares.
have a look at the ScrollViewSuite Example from apple. Sounds exactly like what you are trying to do.
3_Tiling demonstrates:
How to subclass UIScrollView to add content tiling
Reusing tiles to optimize performance and memory use
Changing the resolution of the content in response to zooming
I suggest the Example Photoscroller. It demonstrates CATiledLayer which you can use to tile your image and even use smaller images as lod images. It's much smaller then the complete ScrollViewSuite example but has everything you need to do what you want. It contains only 2 classes which you should be able to use in your project with minor edits.
You might want to check the WWDC 2010 Session #104 "Desinging Apps with Scroll Views"... they handle and explain that example.
You will need to tile your image. I suggest imagemagick for that :)

Image tiles on iPhone 4

I am very new to iPhone development, and I am working on modifying an app which was written a year ago. Recently with the release of the new iphone 4 we have noticed that the screen which was previously displaying an image just fine, has not started to tile that image. And instead of one large image I am now seeing 4 smaller ones. I have tried increasing the size of this image but that does not help. Anyone know what this can be? Resolution? How do I fix this?
Thanks,
Natasha
You need to create another double-resolution version of the file with #2x in the filename. For example, if your original graphic is
tile.png
You need to create your double-resolution one as:
tile#2x.png
This will be used on the iPhone 4 and should fix your problem.
Update
If you have no control over the images you will have to detect whether you are running on a high-resolution device and set the contentScaleFactor property on the image appropriately. Something like this:
UIScreen *screen = [UIScreen mainScreen];
if ([screen respondsToSelector:#selector(scale)] &&
[imageView respondsToSelector:#selector(setContentScaleFactor:)]) {
/* Set image view's scale factor to that of the native screen */
[imageView setContentScaleFactor:[screen scale]];
}
This uses an imageView, but it sounds like in your case a view is using a [UIColor colorWithPatternImage:...] on its background, so you may have to set the scale on something else. This might affect the position of subviews as well.
Why are you not able to create a new #2x version of the image and include it in your bundle?

Thumbnail view of images

I want to show some images as a thumbnail in View controller but i dont know how to do this. Can anyone please give me some ideas or sample code if possible.
Are you asking how to create thumbnails from larger images, or about how to build a view controller which displays them nicely?
Building a view controller:
You could use TTPhotoViewController from the Three20 project (description), which acts similarly to the iPhone's built in camera roll to view images.
You can look at the Scrolling sample code from apple, referred to in this question about using it for thumbnails.
If you want to build one yourself, you might consider using a GridView from the moriarty library, either as a large grid in a UIScrollView, or on a more efficient row-by-row basis in a UITableView. There's a previous question on optimized image loading in a UIScrollView.
Creating thumbnails from larger images:
The code-easiest way to scale down an image is to simply display it in a UIImageView with a frame set to the smaller size that you want - it's scaled for you.
If you want to save a thumbnail, or care about memory usage, you can create a hard-scaled version. The sample code below is taken from this blog post, and can be added to UIImage as a category method:
- (UIImage*) imageScaledToSize: (CGSize) newSize {
UIGraphicsBeginImageContext(newSize);
[self drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)];
UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}
Finally, here's a previous question on masking out round corners on an image, similar to the app icons used on the home screen.
Added
Using an image's built-in thumbnail:
There's a nice function called CGImageSourceCreateThumbnailAtIndex that understands built-in thumbnails in certain image data formats. You can see some useful sample code for this under Creating a Thumbnail Image from an Image Source in the Image I/O Programming Guide from Apple.
There are multiple issues with thumbnails; perhaps you could clarify which ones you are most concerned about?
How to display a smaller version of an existing image
How to speed up paging by caching the thumbnails (instead of just dynamically shrinking the originals)
How to allow the user to page through the thumbnails
How to synchronize the thumbnails with the originals, in the event that your images are editable or the user can add to them

Pictures are very small when added to UIimageview in Interface Builder

I have 6 images, all the same size (65x65). When I create an imageview and add this image through the "image view attributes" in the interface builder, the picture is very small. Maybe 5x5. The pictures also show up small when viewing them in the resource folder however, when running the program, they are the right size. Is there some setting I need to change to get the images to show the full size/full resolution within the interface builder?
Thanks.
Make sure your UIImageView is active, then go to Layout -> Size to Fit (Command + '=' should also do the trick). This way the UIImageView will resize to fit the image and it'll look nice when looking at your stuff in IB.
Adjust the resolution of your image files to 72 dpi.