bool BitmapImage::getHBITMAPOfSize(HBITMAP bmp, LPSIZE size) { ASSERT(bmp); BITMAP bmpInfo; GetObject(bmp, sizeof(BITMAP), &bmpInfo); ASSERT(bmpInfo.bmBitsPixel == 32); int bufferSize = bmpInfo.bmWidthBytes * bmpInfo.bmHeight; CGContextRef cgContext = CGBitmapContextCreate(bmpInfo.bmBits, bmpInfo.bmWidth, bmpInfo.bmHeight, 8, bmpInfo.bmWidthBytes, deviceRGBColorSpaceRef(), kCGBitmapByteOrder32Little | kCGImageAlphaPremultipliedFirst); GraphicsContext gc(cgContext); IntSize imageSize = BitmapImage::size(); if (size) drawFrameMatchingSourceSize(&gc, FloatRect(0.0f, 0.0f, bmpInfo.bmWidth, bmpInfo.bmHeight), IntSize(*size), ColorSpaceDeviceRGB, CompositeCopy); else draw(&gc, FloatRect(0.0f, 0.0f, bmpInfo.bmWidth, bmpInfo.bmHeight), FloatRect(0.0f, 0.0f, imageSize.width(), imageSize.height()), ColorSpaceDeviceRGB, CompositeCopy); // Do cleanup CGContextRelease(cgContext); return true; }
bool BitmapImage::getHBITMAPOfSize(HBITMAP bmp, const IntSize* size) { ASSERT(bmp); BITMAP bmpInfo; GetObject(bmp, sizeof(BITMAP), &bmpInfo); // If this is a 32bpp bitmap, which it always should be, we'll clear it so alpha-wise it will be visible if (bmpInfo.bmBitsPixel == 32 && bmpInfo.bmBits) { int bufferSize = bmpInfo.bmWidthBytes * bmpInfo.bmHeight; memset(bmpInfo.bmBits, 255, bufferSize); } unsigned char* bmpdata = (unsigned char*)bmpInfo.bmBits + bmpInfo.bmWidthBytes*(bmpInfo.bmHeight-1); cairo_surface_t* image = cairo_image_surface_create_for_data(bmpdata, CAIRO_FORMAT_ARGB32, bmpInfo.bmWidth, bmpInfo.bmHeight, -bmpInfo.bmWidthBytes); cairo_t* targetRef = cairo_create(image); cairo_surface_destroy(image); GraphicsContext gc(targetRef); IntSize imageSize = BitmapImage::size(); if (size) drawFrameMatchingSourceSize(&gc, FloatRect(0.0f, 0.0f, bmpInfo.bmWidth, bmpInfo.bmHeight), *size, ColorSpaceDeviceRGB, CompositeCopy); else draw(&gc, FloatRect(0.0f, 0.0f, bmpInfo.bmWidth, bmpInfo.bmHeight), FloatRect(0.0f, 0.0f, imageSize.width(), imageSize.height()), ColorSpaceDeviceRGB, CompositeCopy, BlendModeNormal, ImageOrientationDescription()); // Do cleanup cairo_destroy(targetRef); return true; }