How can I draw a CGContextRef created with CGBitmapContextCreate() to a NSView?
Should I convert it to a image first? If that’s the case, wouldn’t it be an expensive operation?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Yes. You can use
CGBitmapContextCreateImage, then use that to draw into the graphics context fromdrawRect:.CGBitmapContext->CGImageone option among multiple – use the best for the task. If you make good design decisions, it’s rarely an obstacle.CGImage,NSImage, andUIImageare immutable. They avoid copying you might expect when they are created.Larger images can obviously consume a good amount of memory, and it can be expensive to draw the image to the bitmap, and then to draw the image at a size other than its native size.
Reuse the images you create, and hold on to them appropriately. Profile now and then to see how things are going.