Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void Quartz2DDrawingPanel::DrawImage(wxWindowDC& dc, wxImage* im)
- {
- NSView* view = (NSView*)(GetWindow()->GetHandle());
- wxImagePixelData wx_data(*im);
- wxImagePixelData::Iterator p = wx_data.GetPixels();
- size_t w = std::ceil(width * scale);
- size_t h = std::ceil(height * scale);
- size_t size = w * h * 3;
- UInt8 pixel_data[size];
- for(size_t i = 0; i < size; ++p) {
- pixel_data[i++] = p.Red();
- pixel_data[i++] = p.Green();
- pixel_data[i++] = p.Blue();
- }
- CGDataProviderRef provider = CGDataProviderCreateWithData(NULL, pixel_data, size, NULL);
- CGColorSpaceRef color_space = CGColorSpaceCreateDeviceRGB();
- CGImageRef image = CGImageCreate(
- w, h, 8, 24, w * 3, color_space,
- kCGBitmapByteOrderDefault,
- provider, NULL, true, kCGRenderingIntentDefault
- );
- // draw the image
- [view lockFocus];
- CGContextRef context = (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort];
- CGContextDrawImage(context, view.bounds, image);
- [view unlockFocus];
- // and release everything
- CGDataProviderRelease(provider);
- CGColorSpaceRelease(color_space);
- CGImageRelease(image);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement