Remove UIImageView Rectangle

I want to know how I can delete my own rectangle (with, for example, UIViewin IBor something else) UIImageViewto display another UIImageViewone located below it.


enter image description here

I was not able to do this using some kind of answer on the forum ...

+3
source share
3 answers

This will clear the image rectangle:

- (UIImage *)clearRect:(CGRect)rect inImage:(UIImage *)image {

    if (UIGraphicsBeginImageContextWithOptions != NULL)
        UIGraphicsBeginImageContextWithOptions([image size], NO, 0.0);
    else
        UIGraphicsBeginImageContext([image size]);

    CGContextRef context = UIGraphicsGetCurrentContext();

    [image drawInRect:CGRectMake(0.0, 0.0, [image size].width, [image size].height)];
    CGContextClearRect(context, rect);

    UIImage *result = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

    return result;
}

Just load the image and clear the rectangles before assigning it to the image:

UIImage *image = [UIImage imageNamed:@"Image.png"];
UIImage *maskedImage = [self clearRect:CGRectMake(10.0, 10.0, 50.0, 50.0) inImage:image];
[imageView setImage:maskedImage];
+9
source

probably not the best solution, but you can take a different path and take 4 parts around the rectangle separately and merge them after that without an inner rectangle. You will repeat this if you have the opportunity to cut.

+1

You cannot clear the UIImageView itself, because it just draws the UIImage. This way you cleared the rectangle in UIImage. Create a raster image context, paste the image into it. Remove the part you want to view using CGContextClearRect. When creating a new new image from the context of the raster image.

+1
source

All Articles