Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/40.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/27.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 缩放后绘制图像并将其旋转到其他图像_Iphone_Objective C_Ios_Image_Uiimage - Fatal编程技术网

Iphone 缩放后绘制图像并将其旋转到其他图像

Iphone 缩放后绘制图像并将其旋转到其他图像,iphone,objective-c,ios,image,uiimage,Iphone,Objective C,Ios,Image,Uiimage,我有一个比原始图像更小的图像和UIImageView。然后我在主imageview中添加了许多其他UIImageView作为子视图。我还缩放和旋转许多子视图(imageview)。现在,我想从原始图像创建图像,并将所有子视图图像附加到imageview上,但保留位置。我的问题是如何在缩放和旋转后将多个子视图图像绘制成原始图像。我使用了CGContextRotateCTM,但似乎旋转太多了。请帮帮我 我的示例代码是 CGContextRef context = UIGraphicsGetCurre

我有一个比原始图像更小的图像和UIImageView。然后我在主imageview中添加了许多其他UIImageView作为子视图。我还缩放和旋转许多子视图(imageview)。现在,我想从原始图像创建图像,并将所有子视图图像附加到imageview上,但保留位置。我的问题是如何在缩放和旋转后将多个子视图图像绘制成原始图像。我使用了CGContextRotateCTM,但似乎旋转太多了。请帮帮我 我的示例代码是

CGContextRef context = UIGraphicsGetCurrentContext();
[originalImage drawAtPoint:CGPointZero];
for(UIView *aView in [self.mainImageView subviews]){
    float rate = 1000/self.mainImageView.frame.size.width;
    if(aView.tag != DELETE_ATTACH_IMAGEVIEW_TAG && aView.tag != ROTATE_ZOOM_IMAGEVIEW_TAG){
        CGRect rect = CGRectMake(aView.frame.origin.x*rate, aView.frame.origin.y*rate, aView.frame.size.width *rate, aView.frame.size.height*rate);
        if([aView isKindOfClass:[CustomImageView class]]){
            CustomImageView *temp = (CustomImageView *)aView;
            float rotation = [temp rotation];
            UIImage *tempImage= temp.image;
            CGContextRotateCTM(context, rotation);
            [tempImage drawInRect:rect];
        }

    }

}
originalImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

只需捕获整个视图,并在使用完整个图像中的一个图像后即可

- (UIImage *)captureView {

   //hide controls if needed
    CGRect rect = [self.view bounds];

    UIGraphicsBeginImageContext(rect.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    [self.view.layer renderInContext:context];   
    UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return img;

}

捕获此图像后,将其设置为背景,如果不需要,请删除其他所有图像。

我不确定是否正确理解了您的问题。主视图是否包含所有旋转的子视图?或者你只是想在另一个上面画一些视图,你想读什么就读什么??您想将当前视图保存为目录中的图像??否,例如,我有大小为(1000,1000)的原始图像,但在UIImageView中,我将原始图像的大小调整为新的大小100 x 100,然后将许多小图像添加到UIImageView(大小100x100)。现在我想画所有小图像(子视图)到原始图像,尺寸为1000x1000,位置相同谢谢你的帮助,但我想要原始图像的全尺寸,我曾经尝试过你的代码,如果我改变尺寸,我会得到大图像中的小图像context@QuangPhạmCôong hey mate我不明白你想要什么,但如果你只想捕获背景的背景图像或完整图像,那么使用背景图像的边界,如果你不想使用原始图像捕获,还可以隐藏一些图像或控件。。我希望你能理解,伙计:)]我只想将uiimage视图及其上的所有子视图保存为一幅图像,但分辨率高,尺寸大于uiimageview框架哦,好的,伙计如果我得到了有关您此要求的解决方案,那么我将发布代码ok,伙计…..)