сохранение изображений в папке документов с высоким разрешением в iphone - PullRequest
0 голосов
/ 27 сентября 2011

Я хочу сохранить изображение, нарисованное на экране iphone, в папке документов с высоким разрешением.Здесь я могу сохранить изображения в папке документов, но разрешение очень низкое.Может кто-нибудь сказать мне, как решить эту задачу.

Вот мой код

    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();

}

1 Ответ

1 голос
/ 27 сентября 2011

Попробуйте это:

- (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);
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...