IOS Retina Display Masking Bug

I am currently using two images for the menu that I created. I used this code some time ago for conventional display systems, and it worked fine, with the retina display I had some problems with CGImageRef, creating an image in reverse masks when I click on the background display. I tried to import using image extensions for retinal images. Images are delivered using:

[UIImage imageNamed:@"filename.png"]

I presented both a standard and a retinal image with the names filename.png and filename@2x.png.

The problem arises when choosing a mask for the selected area. The code works fine with lower resolution resources and the main high resolution resource, but when I use

CGImageCreateWithImageInRect

And indicate the rectangle in which I want to create the image inside, the image scale is increased, which means that the resolution of the main button is fine, but the image that comes back and overlays the button down is not the correct resolution, but it scales oddly to a density of two. that looks awful.

I tried both

    UIImage *img2 = [UIImage imageWithCGImage:cgImg scale:[img scale] orientation:[img imageOrientation]];
    UIImage *scaledImage = [UIImage imageWithCGImage:[img2 CGImage] scale:4.0 orientation:UIImageOrientationUp];

And I don't seem to get anything when I take the image and drawInRect: (Selected Rect)

I tore off my hair for about 2 hours and cannot find a suitable solution, does anyone have any ideas?

+3
source share
1 answer

, . , CGRect

- (UIImage *)imageFromImage:(UIImage *)image inRect:(CGRect)rect {
rect.size.height = rect.size.height * [image scale];
rect.size.width = rect.size.width * [image scale];
rect.origin.x = rect.origin.x * [image scale];
rect.origin.y = rect.origin.y * [image scale];
CGImageRef sourceImageRef = [image CGImage];
CGImageRef newImageRef = CGImageCreateWithImageInRect(sourceImageRef, rect);
UIImage *newImage = [UIImage imageWithCGImage:newImageRef scale:[image scale] orientation:[image imageOrientation]];
CGImageRelease(newImageRef);
return newImage;
}

, .

+16

Source: https://habr.com/ru/post/1793484/


All Articles