在 UIImageView 上获取图像

发布于 2024-11-11 05:24:21 字数 629 浏览 4 评论 0原文

我目前正在制作一个应用程序,用户可以在其中拍摄照片或从相册中选择照片,然后将叠加层放置在图像上。然后用户可以缩放、旋转和保存图像。

目前,我有 2 个 xib 文件。第一个有覆盖图片的缩略图可供选择。单击其中一个会转到另一个 xib 文件,其中有 2 个 UIImageView。一张用于覆盖层,一张用于相机。以前我只是使用界面生成器在属性中设置图像。但如果有 20 个覆盖层,则意味着我必须使用 20 个 xib。所以我认为最好的方法是通过代码添加图片,这样我就可以使用这个第二个 xib 作为覆盖的模板。这就是我被困住的时候。当我单击第一个 xib 文件中的缩略图时,如何告诉第二个 xib 文件将叠加层存储在 UIImageView 中?

对于相机,我正在使用

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

并且效果很好。我什至可以将它保存到相册中。我以为我可以使用下面的代码进行叠加,但这不起作用。

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

希望有人能帮忙。非常感谢。

哈基莫

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 the 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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

睫毛上残留的泪 2024-11-18 05:24:21

在这种情况下,您根本不需要使用 xib。手动创建 UIImageView,设置其框架和图像,将其作为子视图添加到 viewControllers.view 中。您可以根据需要拥有任意数量的 UIImageView。将它们制作一个数组。你的案例显然是滥用 xibs 概念。 Xib 通常用于需要创建一些复杂的视图,其中包含许多不会在代码中使用的子视图,例如标签、装饰图像等。

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];

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];
攒一口袋星星 2024-11-18 05:24:21

我认为你可以有两个控制器。正如你所说,第一个控制器是静态的。您可以将第二个控制器声明为带有出口和 ivars 的类。然后,每当您使用适当的 IMageviews(或图像)单击第一个控制器上的两个控件中的任何一个时,您都可以创建该类的实例。这只是概念。我认为您可以轻松编写此代码。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文