问题描述
Xcode 5,iOS 7
Xcode 5, iOS 7
两个UIView并排放置-viewA和viewB.每个视图都包含一个UIImage-imageA和imageB.这两个图像在视图之间的边界处相遇,因此它们看起来是无缝的:imageAimageB.
Two UIViews side-by-side - viewA and viewB.Each view contains a UIImage - imageA and imageB.Both images meet at border between the views so that they appear seamless:imageAimageB.
如何将两个图像并排保存到一个图像文件中,就像它们是一个图像一样?
How can I save the two images into a single image file, side-by-side, as though they were one image?
我知道我可以截取屏幕截图,但这会降低分辨率,并且不会考虑到屏幕外部分图像(由于缩放或定位).
I know I could take a screenshot, but that would lower the resolution, and would not account for portions of the images which may be off-screen (due to scaling or positioning).
这可能会回答我自己的问题,但是我能想到的最好的办法是创建一个新的UIImage(imageC),调整其大小以适应imageA和imageB,然后根据它们的相对位置将这些图像复制到imageC中.
This may answer my own question but the best I can think of to create a new UIImage (imageC), size it to account for imageA and imageB, then copy the images into imageC based on their relative positions.
有没有更简单的方法?
推荐答案
在界面中使用2个UIImageView,对每个图像使用UIImagePicker之后,可以使用以下代码进行调试:
using 2 UIImageView in you interface, after using the UIImagePicker for each, you can marge with this code:
- (IBAction)margeSave:(id)sender{
//here you get you two different image
UIImage *bottomImage = self.imageViewPick.image;
UIImage *image = self.myImage.image;
//here you have to crop each image with the code below
//using here a crop code and adjust for your Image
// create a new size for a merged image
CGSize newSize = CGSizeMake(640, 640);
UIGraphicsBeginImageContext( newSize );
[bottomImage drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];
[myImage drawInRect:CGRectMake(0,0,newSize.width,newSize.height) blendMode:kCGBlendModeNormal alpha:1.0];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum(newImage, nil, nil, nil);
//option if you are in other view when save
//[self.navigationController popViewControllerAnimated:YES];
}
您可以集成以下代码来裁剪图像:
You can integrate this code to crop a image:
在InterfaceBuilder中使用图像的2部分以所需的特定大小进行拾取,例如在iPhone上使用2 UIImageView
W:150 H:300
总共il 300x300
,并使用尺寸合适的裁剪图像.
in InterfaceBuilder using 2 part of image for picking with the specific size you want, for example on iPhone using 2 UIImageView
W:150 H:300
total il a 300x300
and using a crop image with size.
CGRect clippedRect = CGRectMake(self.view.frame.origin.x+91, self.view.frame.origin.y, self.view.frame.size.width-91*2, self.view.frame.size.height-220);
CGImageRef imageRef = CGImageCreateWithImageInRect([image CGImage], clippedRect);
UIImage *imageCrop = [UIImage imageWithCGImage:imageRef];
CGImageRelease(imageRef);
希望对您有帮助
这篇关于将两个UIImage并排保存为一个组合图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!