在视图中添加图像并将视图转换为ios中的jpeg图像

时间:2014-01-21 05:21:39

标签: ios uiviewcontroller

-(void)drawJPEG
{
    NSArray* objects = [[NSBundle mainBundle] loadNibNamed:@"View" owner:nil options:nil];

    UIView* mainView = [objects objectAtIndex:0];

    for (UIView* view in [mainView subviews]) {
        if([view isKindOfClass:[UIImageView class]])
        {
            UIImage* PassportSizePhoto = [UIImage imageNamed:@"1.jpeg"];
            [self drawImage:PassportSizePhoto inRect:view.frame];
        }
    }
    UIImage *image;
    UIGraphicsBeginImageContext(mainView.bounds.size);
    {
        [mainView.layer renderInContext:UIGraphicsGetCurrentContext()];
        image = UIGraphicsGetImageFromCurrentImageContext();
    }
    UIGraphicsEndImageContext();
    UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);
}

1 个答案:

答案 0 :(得分:-1)

请不要期待通过间接利用其他人辛苦获得的专业知识来实现​​已经烘焙过的代码。

请给自己一些时间阅读Apple关于图片的文档。

  1. 阅读Apple文档中的UIImageJPEGRepresentation
  2. 搜索Stack-overflow以将图片大小调整为所需大小。
  3. 这是一个非常简单的东西,在堆栈溢出时问了几百万次。