Note that there are some explanatory texts on larger screens.

plurals
  1. POObjective c - UIImage resizing issue
    primarykey
    data
    text
    <p>I have a resource (.png file) that show a picture frame (border).<br> This .png file is size 100x100px, and the border width is 10px. </p> <p><img src="https://i.stack.imgur.com/6Y1Ts.png" alt="my original image"></p> <p><strong>My Question:</strong> </p> <p>How can I create another UIImage from this image, with a different size, without ruin the border's width?</p> <p><strong>The Problem:</strong></p> <p>When I try to draw the new image from the original image with <code>CGContextDrawImage</code> I get a new image with the new size, but my border proportion is ruin. </p> <pre><code> CGRect newRect = CGRectIntegral(CGRectMake(0, 0, newWidth, newHeight)); CGImageRef imageRef = //... the image // Build a context that's the same dimensions as the new size CGContextRef bitmap = CGBitmapContextCreate(NULL, newRect.size.width, newRect.size.height, CGImageGetBitsPerComponent(imageRef), 0, CGImageGetColorSpace(imageRef), CGImageGetBitmapInfo(imageRef)); // Set the quality level to use when rescaling CGContextSetInterpolationQuality(bitmap, kCGInterpolationHigh); // Draw into the context; this scales the image CGContextDrawImage(bitmap, newRect, imageRef); // Get the resized image from the context and a UIImage CGImageRef newImageRef = CGBitmapContextCreateImage(bitmap); UIImage *newImage = [UIImage imageWithCGImage:newImageRef]; // Clean up CGContextRelease(bitmap); CGImageRelease(newImageRef); </code></pre> <p>For example, when I tried to create an image size 800x100p, I get an image with very thin top and bottom border. </p> <p><img src="https://i.stack.imgur.com/bCnDa.png" alt="the bad result I get"> </p> <p>What I need is that the border will stay the same width<br> <img src="https://i.stack.imgur.com/YxX64.png" alt="enter image description here"></p> <p><strong>*note</strong><br> Using <code>resizableImageWithCapInsets:</code> wont help me, because I need a new image with the new size to save on the disc.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload