从iPhone上的其他两个UIImages创建一个UIImage [英] Create a UIImage from two other UIImages on the iPhone

查看:107
本文介绍了从iPhone上的其他两个UIImages创建一个UIImage的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正试图在iPhone上写一个动画,没有太大成功,崩溃似乎没什么用。

I'm trying to write an animation on the iPhone, without much success, getting crashes and nothing seems to work.

我想做的事情看似简单,创造一个UIImage,并将另一个UIImage的一部分绘制到其中,我对上下文和图层和东西有点混淆。

What I wanna do appears simple, create a UIImage, and draw part of another UIImage into it, I got a bit confused with the context and layers and stuff.

有人可以解释如何写这样的东西(有效地),带有示例代码?

Could someone please explain how to write something like that (efficiently), with example code?

推荐答案

为了记录,事实证明这是相当简单的 - 你需要知道的一切在下面的示例中的某处:

For the record, this turns out to be fairly straightforward - everything you need to know is somewhere in the example below:

+ (UIImage*) addStarToThumb:(UIImage*)thumb
{
   CGSize size = CGSizeMake(50, 50);
   UIGraphicsBeginImageContext(size);

   CGPoint thumbPoint = CGPointMake(0, 25 - thumb.size.height / 2);
   [thumb drawAtPoint:thumbPoint];

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

   CGPoint starredPoint = CGPointMake(0, 0);
   [starred drawAtPoint:starredPoint];

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

   return result;
}

这篇关于从iPhone上的其他两个UIImages创建一个UIImage的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆