簡體   English   中英

在iPhone中以高分辨率將圖像保存在documents文件夾中

[英]saving images in documents folder with high resolution in iphone

我想以高分辨率將保存在iPhone屏幕上的圖像保存在documents文件夾中。 在這里我可以將圖像保存在documents文件夾中,但是分辨率很低。 誰能告訴我如何完成這項任務。

這是我的代碼

    UIImage *image = [[UIImage alloc]init];
double resolution = 50;

    //CGSize pageSize = CGSizeMake(612, 792);
    // CGRect boundsRect = CGRectMake(50, 50, 512, 692);
CGRect boundsRect = CGRectMake(0, 0, 612, 792);

double imageWidth = image.size.width * image.scale * 72 / resolution;
double imageHeight = image.size.height * image.scale * 72 / resolution;

double sx = imageWidth / boundsRect.size.width;
double sy = imageHeight / boundsRect.size.height;

    // At least one image edge is larger than maxBoundsRect
if ((sx > 1) || (sy > 1)) {
    double maxScale = sx > sy ? sx : sy;
    imageWidth = imageWidth / maxScale;
    imageHeight = imageHeight / maxScale;
}

    // Put the image in the top left corner of the bounding rectangle
CGRect bounds = CGRectMake(boundsRect.origin.x, boundsRect.origin.y + boundsRect.size.height - imageHeight, imageWidth, imageHeight);

CGSize size = bounds.size;

    //  UIGraphicsBeginImageContextWithOptions(size,NO,10.0f); 

UIGraphicsBeginImageContext(size);
{
    [self.layer renderInContext:UIGraphicsGetCurrentContext()];
    image = UIGraphicsGetImageFromCurrentImageContext();

}

嘗試這個:

- (UIImage *)screenshotImage {
    UIView* screen = self.view;
    CGSize imageSize = screen.bounds.size;

    UIGraphicsBeginImageContext(imageSize);
    CGContextRef imageContext = UIGraphicsGetCurrentContext();
    [screen.layer renderInContext: imageContext];
    UIImage* screenshotImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    return screenshotImage;
}

收到圖像並保存后:

UIImage *screenshotImage = [self screenshotImage];
UIImageWriteToSavedPhotosAlbum(screenshotImage,nil,nil,nil);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM