diff options
-rw-r--r-- | printing/image_win.cc | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/printing/image_win.cc b/printing/image_win.cc index de731e0..fdf99c8 100644 --- a/printing/image_win.cc +++ b/printing/image_win.cc @@ -4,11 +4,15 @@ #include "printing/image.h" +#include "base/win/scoped_gdi_object.h" +#include "base/win/scoped_hdc.h" +#include "base/win/scoped_select_object.h" #include "printing/metafile.h" #include "skia/ext/platform_device.h" #include "ui/gfx/gdi_util.h" // EMF support #include "ui/gfx/rect.h" + namespace { // A simple class which temporarily overrides system settings. @@ -50,7 +54,7 @@ bool Image::LoadMetafile(const Metafile& metafile) { DisableFontSmoothing disable_in_this_scope; // Create a temporary HDC and bitmap to retrieve the rendered data. - HDC hdc = CreateCompatibleDC(NULL); + base::win::ScopedCreateDC hdc(::CreateCompatibleDC(NULL)); BITMAPV4HEADER hdr; DCHECK_EQ(rect.x(), 0); DCHECK_EQ(rect.y(), 0); @@ -62,12 +66,12 @@ bool Image::LoadMetafile(const Metafile& metafile) { size_ = rect.size(); gfx::CreateBitmapV4Header(rect.width(), rect.height(), &hdr); - void* bits; - HBITMAP bitmap = CreateDIBSection(hdc, - reinterpret_cast<BITMAPINFO*>(&hdr), 0, - &bits, NULL, 0); + unsigned char* bits = NULL; + base::win::ScopedBitmap bitmap( + ::CreateDIBSection(hdc, reinterpret_cast<BITMAPINFO*>(&hdr), 0, + reinterpret_cast<void**>(&bits), NULL, 0)); DCHECK(bitmap); - DCHECK(SelectObject(hdc, bitmap)); + base::win::ScopedSelectObject select_object(hdc, bitmap); skia::InitializeDC(hdc); @@ -77,11 +81,7 @@ bool Image::LoadMetafile(const Metafile& metafile) { size_t bytes = row_length_ * size_.height(); DCHECK(bytes); - data_.resize(bytes); - memcpy(&*data_.begin(), bits, bytes); - - DeleteDC(hdc); - DeleteObject(bitmap); + data_.assign(bits, bits + bytes); return success; } |