iphone - 从 iPhone 上的另外两个 UIImage 创建一个 UIImage

标签 iphone uiimage

我正在尝试在 iPhone 上编写动画,但没有取得太大成功,经常崩溃,而且似乎没有任何效果。

我想做的事情看起来很简单,创建一个 UIImage,并将另一个 UIImage 的一部分绘制到其中,我对上下文、图层和其他东西有点困惑。

有人可以用示例代码解释如何(有效地)编写类似的东西吗?

最佳答案

郑重声明,这相当简单 - 您需要了解的所有内容都在下面的示例中:

+ (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 - 从 iPhone 上的另外两个 UIImage 创建一个 UIImage,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/679245/

相关文章:

iPhone 如何从 NSData 取回图像

iphone - 崩溃: UIImage style crash with code for iOS 6?

iphone - `[UIImage imageNamed:]` 从哪里加载图像,我如何在运行时将图像插入其中?

objective-c - 在远程通知中添加文本字段,iOS 8

ios - 陀螺仪、运动和加速度之间的物理区别是什么?

iphone - 如何更改 UIPickerView 中的字体大小?

google-maps - iOS 中使用 GMSSyncTileLayer 的透明图 block 叠加

iphone - UIImagePNGRepresentation() 返回不同的字节

ios - NSOperation 在后台任务结束之前完成

iphone - SSCollectionView 边距/间距