Get image data for resizableImageWithCapInsets: after resizing

I have a png, which I use as the image mask for another image. Both images have rounded corners, which are saved with resizableImageWithCapInsets :. The image (and not the mask) is automatically selected because it is a progressImage UIProgressView.

The problem I am facing is that if I use CGImageMaskCreate to create a mask and just give it the width of the UIProgressView, the mask image is stretched (i.e. it does not save the cap).

What I would like to do is create a new resizable UIImage, manually resize the image (possibly by placing it in a UIImageView), get the data representation of the resized version of the mask image, and then create a new image with this data and use this image as a mask . It seems, however, that even if I create a UIImageView with an image and then adjust the UIImageView frame accordingly to bring the image back from the view, my original image.

Is there any way to get the result of a resizableImageWithCapInsets: image without actually drawing it into the user interface?

+4
source share
2 answers

I would try drawing the image in parts in a CGContext, where you can access the data provider or extract the NSData by creating a UIImage

0
source
- (UIImage*) drawImage:(UIImage *)image atSize:(CGSize) size { UIGraphicsBeginImageContext(size); CGContextRef context = UIGraphicsGetCurrentContext(); [image drawInRect:CGRectMake(0, 0, size.width, size.height)]; CGImageRef cgImage = CGBitmapContextCreateImage(context); UIImage *outImage = [UIImage imageWithCGImage:cgImage]; CGImageRelease(cgImage); UIGraphicsEndImageContext(); return outImage; } 
0
source

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


All Articles