Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Draw portion of image in CGBitmapContext

I have created a CGBitmapContext of 256 x 256 and I have a CGImageRef that I want to draw into this context. My goal is to crop the image (and ultimately create tiles of an image), but if I use CGContextDrawImage, Core Graphics scales the image to fit the context.

So the question is, how do I make sure that only a portion of the CGImageRef is drawn into the CGBitmapContext (no scaling)?

like image 425
Bart Jacobs Avatar asked Jan 27 '26 06:01

Bart Jacobs


1 Answers

CGContextDrawImage takes a CGRect parameter. It sounds like you are passing the bounds of your context. Instead, try passing the bounds of the image, offset appropriately to draw the desired part of it.

like image 160
JWWalker Avatar answered Jan 31 '26 22:01

JWWalker