我有一个UIImage
(称为图片),我希望与另一个UIView
(称为overlayView)合并,其中包含不同的子视图,例如。 UILabels
,UIImageViews
等等,以制作新的UIImage
(称为mergedImage)。这是我的代码,直到现在:
-(UIImage *) mergeViewWithImage: (UIImage *) image{
//The mergedImage need to be the same size as the image
UIGraphicsBeginImageContext(image.size);
//I'm doing this to get the layer, when i renderInContext, other ways?
UIImageView *temp = [[UIImageView alloc] initWithImage:image];
//This is working, the view gets its new frame, but the subviews won't scale up
[overlayView setFrame:CGRectMake(0, 0, image.size.width, image.size.height)];
[temp.layer renderInContext:UIGraphicsGetCurrentContext()];
[overlayView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *mergedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
//Need to set the frame to the initial one
[overlayView setFrame:CGRectMake(0, 0, 320, 320)];
return mergedImage;
}
This screenshot is what I really want it to look like
你看到的是广场上的AVCaptureVideoPreviewLayer
(320 * 320),我有一个UIView
,名为overlayView(320 * 320),位于顶部。当我按下“Take”按钮时,我会使用AVCaptureStillImageOutput
进行缩放,裁剪等操作,然后运行mergeViewWithImage
- 方法。此时图像为968 * 968,但overlayView仍然是320 * 320(有一个蓝色边框,只是知道它在哪里)。当我setFrame:
到overlayView
时,子视图,例如。左下角的Luca Toni的示例图像无法缩放,如此截图中所示
所以你看,背景图像(白色墙壁)保持不变,并且overlayView确实调整了大小,但是Luca Toni的图像要小得多,它不会缩放...请帮忙。
我尝试过很多东西,比如设置这个:
//imageOne is the picture with Luca Toni...
[[overlayView imageOne] setAutoresizingMask: UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth];
overlayView在Interface Builder中以.xib形式生成,UIView
带有UIImageVIew
(imageOne),并且有自己的UIVIew
自定义类(此处没有任何内容) ,只参考imageOne(Luca Toni))。 overlayView在MainViewController
中启动,如下所示:
[self overlayView:[[OverlayView alloc] init]];
overlayView = [[[NSBundle mainBundle] loadNibNamed:@"OverlayView" owner:self options:nil] objectAtIndex:0];
并添加到主视图中:
[[self view] addSubview:overlayView];