开发者

Getting image on UIImageView

I'm currently making an app where the user takes a photo or select it from an album, then an overlay is placed over the image. The user can then scale, rotate and save the image.

For now, I have 2 xib files. The first one has thumbnails for overlay pictures to choose from. Clicking on one of them goes to another xib file where I have 2 UIImageViews. One for the overlay and one for t开发者_运维技巧he camera. Previously I just used interface builder to set an image at the attributes. But if have 20 overlays, it means I have to use 20 xibs. So I thought the best way is to add pictures through code so I can use this 2nd xib as a template for the overlays. Here's when I'm stuck. When I click on a thumbnail in the 1st xib file, how do tell the 2nd xib file to store an overlay in the UIImageView?

For the camera, I'm using

imageView.image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];

and it works fine. I can even save it to the album. I thought I could use the code below for the overlays but that didn't work.

UIImage *image = [UIImage imageNamed: @"char1.png"];

Hope someone can help. Thanks very much.

Hakimo


You don't need to use xib at all in this situation. Create UIImageView by hands, set its frame and image, add it as a subview to your viewControllers.view . You can have as many UIImageViews as you need. Make an array of them. Your case is obviously misuse of xibs concept. Xibs are usually used when there is need to create some complicated view with many subviews that wouldn't be used in code, like labels, decoration images etc.

CGRect frameForImage = CGRectMake(100, 100, 200, 300);
UIImageView *originalImage = [[UIImageView alloc] initWithFrame:frameForImage];
originalImage.image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
[self.view addSubview:originalImage];
[originalImage release];

frameForImage.origin.x += 400;
UIImageView *resizedImage = [[UIImageView alloc] initWithFrame:frameForImage];
resizedImage.image = [info objectForKey:@"UIImagePickerControllerWhateverImage"];
[self.view addSubview:resizedImage];
[resizedImage release];


I think you can have two controllers.As you said first one will be static. You can declare the second controller as a class with outlets and ivars. Then you can create instances of that class whenever you you click either of the two controls on the first controller with the appropriate IMageviews (or Images).This is just the concept. I assume you can code this easily.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜