Advertisement
Guest User

Untitled

a guest
Dec 9th, 2016
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. void Quartz2DDrawingPanel::DrawImage(wxWindowDC& dc, wxImage* im)
  2. {
  3. NSView* view = (NSView*)(GetWindow()->GetHandle());
  4.  
  5. wxImagePixelData wx_data(*im);
  6. wxImagePixelData::Iterator p = wx_data.GetPixels();
  7.  
  8. size_t w = std::ceil(width * scale);
  9. size_t h = std::ceil(height * scale);
  10. size_t size = w * h * 3;
  11.  
  12. UInt8 pixel_data[size];
  13.  
  14. for(size_t i = 0; i < size; ++p) {
  15. pixel_data[i++] = p.Red();
  16. pixel_data[i++] = p.Green();
  17. pixel_data[i++] = p.Blue();
  18. }
  19.  
  20. CGDataProviderRef provider = CGDataProviderCreateWithData(NULL, pixel_data, size, NULL);
  21.  
  22. CGColorSpaceRef color_space = CGColorSpaceCreateDeviceRGB();
  23.  
  24. CGImageRef image = CGImageCreate(
  25. w, h, 8, 24, w * 3, color_space,
  26. kCGBitmapByteOrderDefault,
  27. provider, NULL, true, kCGRenderingIntentDefault
  28. );
  29.  
  30. // draw the image
  31.  
  32. [view lockFocus];
  33.  
  34. CGContextRef context = (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort];
  35.  
  36. CGContextDrawImage(context, view.bounds, image);
  37.  
  38. [view unlockFocus];
  39.  
  40. // and release everything
  41.  
  42. CGDataProviderRelease(provider);
  43. CGColorSpaceRelease(color_space);
  44. CGImageRelease(image);
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement