【问题标题】:Save image in library将图像保存在库中
【发布时间】:2012-01-27 19:51:57
【问题描述】:

我必须将图像保存在 iPhone 和 iPad 的库中,所以这里是它的代码

UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);

但问题是我想用子视图保存图像意味着 UIImageView 中有一些其他视图,如 UILabel 和 UIImageView 那么我如何用所有子视图保存图像。

屏幕截图是一种方式,但屏幕尺寸是固定的,但我想要用户捕获的图像的实际尺寸。

提前致谢。

【问题讨论】:

    标签: iphone ios ipad uiimageview uiimage


    【解决方案1】:

    如果你这样做,这也是可能的

    // Take a UIView of the image size
    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0,0,img.size.width,img.size.height)];
    UIImageVIew *imgView = [[UIImageView alloc]initWithFrame:view.frame];
    [imgView setImage:img];
    [view addSubview:imgView];// after this give the positioning of your labels in the view and then perform this operation.
    
    UIGraphicsBeginImageContext(view.frame.size);
    [view.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    

    此代码肯定会起作用,但如果您无法提供正确的框架,标签的位置将会从您实际放置它们的位置移动。

    【讨论】:

      【解决方案2】:

      类似这样的:

      UIGraphicsBeginImageContext(self.view.frame.size);
      [self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
      UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
      UIGraphicsEndImageContext();
      

      【讨论】:

      • 这是工作,但它仍然捕获当前屏幕 320x460 但我需要捕获由相机 iPhone 4s 捕获的全尺寸图像,因此它的尺寸很大。有没有其他方法可以捕获全尺寸图像..
      猜你喜欢
      • 2017-05-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-14
      • 2020-06-01
      • 1970-01-01
      相关资源
      最近更新 更多