Iphone Sdk 将 2 张图像重叠为一张

发布于 2024-09-18 08:21:21 字数 76 浏览 2 评论 0原文

我有 2 个图像..如何重叠它们以便获得 1 个 UIImage?将图像 2 的位置设置在图像 1 的 X、Y 处

谢谢!

I have 2 images.. How can i overlap them so i can get 1 UIImage? Setting the position of image 2 inside image 1 at X, Y

Thanks!

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

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

发布评论

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

评论(2

一刻暧昧 2024-09-25 08:21:21

Zapacila,您找到问题的答案了吗?你可以这样做:

#define imageWidth 40
#define imageHeight 60

UIImage *image1 = [UIImage imageNamed:@"firstimage.png"];
UIImage *image2 = [UIImage imageNamed: @"secondimage.png"];

CGSize itemSize = CGSizeMake(imageWidth, imageHeight);

UIGraphicsBeginImageContext(itemSize);

CGRect imageRect = CGRectMake(0.0, 0.0, itemSize.width, itemSize.height);
[image1 drawInRect:imageRect];
[image2 drawInRect:imageRect];

UIImage *overlappedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

UIImageoverlapedImage 是一个新图像,其中包含重叠的初始图像。老实说,我不知道这是否是实现这一结果的最佳方法,但我知道它绝对有效。

如果同时您找到了更有效的解决方案,请告诉我!

Zapacila, have you found an answer to your question? You could do it like this:

#define imageWidth 40
#define imageHeight 60

UIImage *image1 = [UIImage imageNamed:@"firstimage.png"];
UIImage *image2 = [UIImage imageNamed: @"secondimage.png"];

CGSize itemSize = CGSizeMake(imageWidth, imageHeight);

UIGraphicsBeginImageContext(itemSize);

CGRect imageRect = CGRectMake(0.0, 0.0, itemSize.width, itemSize.height);
[image1 drawInRect:imageRect];
[image2 drawInRect:imageRect];

UIImage *overlappedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

The UIImage overlappedImage is a new image which contains the initial ones, overlapped. To be honest, I don't know if this is the best method to achieve this result, but I know it definitely works.

If in the meantime you found a more efficient solution, let me know!

分开我的手 2024-09-25 08:21:21

为什么不直接有一个 UIView 并将两个图像作为子视图放入其中?

UIImageView *image = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"myimage.png"]];
UIView *imagesView = [[UIView alloc] initWithFrame:image.frame];
[imagesView addSubview:image];

UIImageView *imageToOverlay = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"myimagetooverlay.png"]];
[imageToOverlay setCenter:CGPointMake(10,10)];
[imagesView addSubview:imageToOverlay];

[self.view addSubview:imagesView];

Why don't you just have a UIView and put the two images into that as subviews?

UIImageView *image = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"myimage.png"]];
UIView *imagesView = [[UIView alloc] initWithFrame:image.frame];
[imagesView addSubview:image];

UIImageView *imageToOverlay = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"myimagetooverlay.png"]];
[imageToOverlay setCenter:CGPointMake(10,10)];
[imagesView addSubview:imageToOverlay];

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