dflplot 0.01

Michal Minich michal.minich at gmail.com
Sat Jul 10 01:06:07 PDT 2010


On Sat, 10 Jul 2010 04:40:04 +0000, dsimcha wrote:

> 2. There is currently no "proper" way to save a plot. This is because
> DFL's Bitmap object doesn't provide a way to obtain the underlying
> pixels yet, and core.stdc.windows doesn't seem to provide the necessary
> stuff to do it manually via the Windows API.

When using classical windows api, I'm almost entirely sure that only way 
to have accessible bitmap pixels, while still being able to draw them to 
window is using dib section.

HANDLE cDC;

HBITMAP hBitmap;

BITMAPINFO bmi;
bmi.bmiHeader.biSize = BITMAPINFOHEADER.sizeof;
bmi.bmiHeader.biWidth = w; // must  be rounded to 4
bmi.bmiHeader.biHeight = -h; // must  be rounded to 4
bmi.bmiHeader.biPlanes = 1;
bmi.bmiHeader.biBitCount = 24;
bmi.bmiHeader.biCompression = BI_RGB;

VOID* ppvBits;

HANDLE cDC = CreateCompatibleDC (hDC);

hBitmap = CreateDIBSection (cDC, &bmi, DIB_RGB_COLORS, &ppvBits, null, 0);

if (hBitmap == NULL || ppvBits == NULL)
    throw new Exception ("Failed to Create Device Independed Bitmap 
(DIB)");

HGDIOBJ selectObj = SelectObject (cDC, hBitmap);

if (selectObj == NULL)
    throw new Exception ("Failed to SelectObject the DIB");

ColorBgr* pixRgb = cast (ColorBgr*) ppvBits; // ppvBits are initialized 
bitmap data

//struct ColorBgr { ubyte blue; ubyte green; ubyte red; }


// to display
BITMAPINFO bi;

bi.bmiHeader.biSize = BITMAPINFO.sizeof;
bi.bmiHeader.biWidth = image.size.width;
bi.bmiHeader.biHeight = 0 - image.size.height;
bi.bmiHeader.biPlanes = 1;
bi.bmiHeader.biBitCount = 24;

SetDIBitsToDevice (hDC, 
      0, 0,
      image.size.width, image.size.height,
      0, image.size.height, 
      image.size.height, image.size.height, 
      &image.pixels[0], &bi, DIB_RGB_COLORS);


More information about the Digitalmars-d-announce mailing list