Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/38.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 组合多个UIImageView并保持分辨率_Iphone_Uiimageview_Uiimage - Fatal编程技术网

Iphone 组合多个UIImageView并保持分辨率

Iphone 组合多个UIImageView并保持分辨率,iphone,uiimageview,uiimage,Iphone,Uiimageview,Uiimage,我正在设计一个应用程序,其中一个用户将多个UIImageView相互放置。当用户决定将其保存到相册时,我必须组合所有这些UIImageView并将其保存到照片库。在结合他们的时候,我需要保持他们的立场和决心,佐德。我尝试的方法是创建一个类似于容器的父UIView。用户将所有UIImageView放置在此UIView中。在保存时,我截取UIView的屏幕并保存它。尽管这种方法有效,但它并不能保持分辨率。最终图像的分辨率与父UIView大小的分辨率相同(宽度和高度为300像素)。有没有办法维持决议?

我正在设计一个应用程序,其中一个用户将多个UIImageView相互放置。当用户决定将其保存到相册时,我必须组合所有这些UIImageView并将其保存到照片库。在结合他们的时候,我需要保持他们的立场和决心,佐德。我尝试的方法是创建一个类似于容器的父UIView。用户将所有UIImageView放置在此UIView中。在保存时,我截取UIView的屏幕并保存它。尽管这种方法有效,但它并不能保持分辨率。最终图像的分辨率与父UIView大小的分辨率相同(宽度和高度为300像素)。有没有办法维持决议?或者至少有更高的分辨率,比如高达1024x768像素?任何提示/代码示例都将不胜感激

如果UIView的大小高于最大图像的大小,那么保存UIView是一个非常好的主意,但事实几乎并非如此。 你要做的是创建一个图形上下文(CGContextRef),大小与你最大的图像一样大,按z顺序对图像进行排序,然后开始在那里绘制这些图像。 我将尝试用一些伪代码来帮助您:

-(UIImage *)mergeFlag{

UIImage * mergedImage = nil;

//In some pace you need to fill these values with the biggest width of all your images and the biggest height;
int Max_Width;
int Max_Height;

//Use here your image with the biggest Z-order.
CGImageRef image;

size_t cWitdh = Max_Width;
size_t cHeight = Max_Height;
size_t bitsPerComponent = 8;//If 8 isn't right you should use CGImageGetBitsPerComponent(image) with some image.
size_t bytesPerRow = 4 * Max_Width;// I use 4 assuming you have 8 Bits per component and you have 4 components (R,G,B,A) , if you have an image specifically, you can use CGImageGetBytesPerRow(image)

//Now we build a Context with those dimensions.
CGContextRef context = CGBitmapContextCreate(nil, cWitdh, cHeight, bitsPerComponent, bytesPerRow, CGColorSpaceCreateDeviceRGB(), CGImageGetBitmapInfo(image));

//The code of this cycle is to ilustrate what you have to do:
for(image in your Images ordered by z-Order)
{
    //The location where you draw your image on the context is not always the same location you have in your UIView, 
    //this could change and you need to calculate that position according to the scale between you images real size, and the size of the UIImage being show on the UIView.
    CGContextDrawImage(context, CGRectMake(currentImage.frame.origin.x, currentImage.frame.origin.y, CGImageGetWidth(currentImage), CGImageGetHeight(currentImage), currentImage);
}

CGImageRef mergeResult  = CGBitmapContextCreateImage(context);
mergedImage = [[UIImage alloc] initWithCGImage:tmp];
CGContextRelease(context);
CGImageRelease(mergeResult);
return mergedImage;}
希望能有帮助