gpt4 book ai didi

iphone - UIGraphicsGetImageFromCurrentImageContext - 将图像分成两部分创建黑色背景

转载 作者:IT王子 更新时间:2023-10-29 08:17:40 26 4
gpt4 key购买 nike

我想将一个 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 array
UIImage *top = UIGraphicsGetImageFromCurrentImageContext();
UIImageView *topV = [[UIImageView alloc] initWithImage:top];
CGRect frameTop = topV.frame;
frameTop.origin.x += 360.0f;
topV.frame = frameTop;
[self.view addSubview:topV];
[topV release];

UIGraphicsEndImageContext();

此代码运行良好,但我从 UIGraphicsGetImageFromCurrentImageContext 获取的 UIImage 始终为黑色背景。

如何拆分 splitMeInTwo UIImage 并保持透明背景?

最佳答案

尝试将不透明参数设置为NO

UIGraphicsBeginImageContextWithOptions(size, NO, 0.0);

关于iphone - UIGraphicsGetImageFromCurrentImageContext - 将图像分成两部分创建黑色背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7939494/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com