小编flo*_*xxy的帖子

UIGraphicsGetImageFromCurrentImageContext - 将图像拆分为两个会创建一个黑色背景

我想将UIImage分成两个单独的图像.我使用以下(工作)代码.

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

UIImageView *original = [[UIImageView alloc] initWithImage:splitMeInTwo];
[self.view addSubview:original];
[original release];

// The size of each part is half the height of the whole image
CGSize size = CGSizeMake([splitMeInTwo size].width, [splitMeInTwo size].height/2);

// Create image-based graphics context for top half
UIGraphicsBeginImageContextWithOptions(size, TRUE, 0.0);

// Draw into context, bottom half is cropped off
//[image drawAtPoint:CGPointMake(0.0,0.0)];
[splitMeInTwo drawAtPoint:CGPointMake(0.0,0.0) blendMode:kCGBlendModeNormal alpha:1.0];

// Grab the current contents of the context as a UIImage 
// and add it to our …
Run Code Online (Sandbox Code Playgroud)

iphone objective-c uiimage ios

16
推荐指数
1
解决办法
6186
查看次数

标签 统计

ios ×1

iphone ×1

objective-c ×1

uiimage ×1