在我的应用程序中,我有三个不同的图像视图,三个图像视图应该合并为单个uiimage。 用于从图库/相机中拾取图像的第一个imageview 帧图像的第二个imageview Overlay图像的第三个imageview(这些放在第一个图像view.my问题!是分享我需要将这三个合并为单个uiimage 在运行它时只显示第二张图像,第三张合并第一张图像没有查看。如果有人知道这个问题,请回答我。谢谢提前 这是我的分享代码,请帮助我。
[self.OverLayImgView setAlpha:0.6]; UIImage *FirstImage = ImgView.image;
UIImage *ScndImage=self.FramesAppliedImg.image;
UIImage *ThirdImg=self.OverLayImgView.image;
CGSize firstImagSize=[FirstImage size];
UIGraphicsBeginImageContext(firstImagSize);
[FirstImage drawInRect:CGRectMake(20,20,315,315)];
[ScndImage drawInRect:CGRectMake(0,0,355,355)];
[ThirdImg drawInRect:CGRectMake(20, 20, 315,315)];
UIImage *newImage=UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
答案 0 :(得分:0)
试试这个:
一些视图类只使用UIView而不是:
- (UIImage *)stitchedImageWithSize:(CGSize)size
borderOffset:(CGFloat)borderOffset
borderColor:(UIColor *)borderColor
{
UIImageView *v = [[UIImageView alloc] initWithFrame:CGRectMake(0.f, 0.f, size.width, size.height)];
v.backgroundColor = self.backgroundColor;
v.image = self.image;
v.contentMode = self.contentMode;
for (NSUInteger i = 0; i < self.subviews.count; i++) {
id obj = self.self.subviews[i];
if ([obj isKindOfClass:[V_freeStitchingCell class]]) {
V_freeStitchingCell *cell = obj;
CGRect rect = cell.rect_first;
//make rect with center
rect.origin.x = cell.center.x - (rect.size.width / 2.f);
rect.origin.y = cell.center.y - (rect.size.height / 2.f);
//make rect with scale
rect.size.width = rect.size.width * size.width / self.frame.size.width;
rect.size.height = rect.size.height * size.height / self.frame.size.height;
rect.origin.x = rect.origin.x * size.width / self.frame.size.width;
rect.origin.y = rect.origin.y * size.height / self.frame.size.height;
if (cell.pImg_value) {
UIView *sv = [[UIView alloc] initWithFrame:rect];
sv.backgroundColor = borderColor;
CGSize tmpsize = cell.frame.size;
UIImage *img = [UIImage imageWithImage:cell.pImg_value inRect:CGRectZero size:&tmpsize errMsg:nil];
UIImageView *vimg = [[UIImageView alloc] initWithFrame:CGRectMake(borderOffset, borderOffset, rect.size.width - (borderOffset * 2), rect.size.height - (borderOffset * 2))];
vimg.image = img;
[sv addSubview:vimg];
[v addSubview:sv];
sv.transform = cell.transform;
}
}
}
UIGraphicsBeginImageContext(size);
CGContextRef contxt = UIGraphicsGetCurrentContext();
[v.layer renderInContext:contxt];
UIImage *des = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return des;
}