T
Teis Johansen
Hi
First of, I am posting to this newsgroup as it seemed best suited even though I am writing C++ for a standard Windows application. The application uses GDI+ which forms the basis of the System.Drawing namespace...anyway here goes:
I am trying to create a 1 bit per pixel mask to use as an overlay. The data for the mask i generated dynamically based on user input and is available as a byte array. I get the first failure when trying to create the mask bitmap, the code is a follows:
/**
* Utiliy method, creates a mask bitmap and modifes the palette accordingly.
* @param size Size of the mask.
* @param color Color of the mask.
* @param pixels The pixels.
*/
Bitmap* createMask( const Size& size, const Color& color, Byte* pixels ) {
Bitmap* mask = new Bitmap( size.width, size.height, ((size.width+3)>>2)*4/8, PixelFormat1bppIndexed, pixels );
UInt paletteSize = mask->GetPaletteSize();
if( paletteSize > 0 ) {
ColorPalette* palette = (ColorPalette*)malloc( paletteSize );
mask->GetPalette( palette, paletteSize );
if( palette->Count == 2 ) {
palette->Entries[0] = Gdiplus::Color::Black;
palette->Entries[1] = Gdiplus::Color::MakeARGB( color.GetA(), color.GetR(), color.GetG(), color.GetB() );
}
mask->SetPalette( palette );
free( palette );
}
return mask;
}
Since that didn't work, I tried letting GDI+ create a mask bitmap of the specified size and the copy the pixels into that bitmap. But when I try to display the image I either get nothing or a GPF. My display code is very simple:
// Bitmap *maskBitmap; // Defined elsewhere
Graphics g( hDC );
g.DrawImage( maskBitmap, 0, 0 );
So it basically just creates Graphics object and attempts to draw the image. The latter fails however...
Teis Johansen
First of, I am posting to this newsgroup as it seemed best suited even though I am writing C++ for a standard Windows application. The application uses GDI+ which forms the basis of the System.Drawing namespace...anyway here goes:
I am trying to create a 1 bit per pixel mask to use as an overlay. The data for the mask i generated dynamically based on user input and is available as a byte array. I get the first failure when trying to create the mask bitmap, the code is a follows:
/**
* Utiliy method, creates a mask bitmap and modifes the palette accordingly.
* @param size Size of the mask.
* @param color Color of the mask.
* @param pixels The pixels.
*/
Bitmap* createMask( const Size& size, const Color& color, Byte* pixels ) {
Bitmap* mask = new Bitmap( size.width, size.height, ((size.width+3)>>2)*4/8, PixelFormat1bppIndexed, pixels );
UInt paletteSize = mask->GetPaletteSize();
if( paletteSize > 0 ) {
ColorPalette* palette = (ColorPalette*)malloc( paletteSize );
mask->GetPalette( palette, paletteSize );
if( palette->Count == 2 ) {
palette->Entries[0] = Gdiplus::Color::Black;
palette->Entries[1] = Gdiplus::Color::MakeARGB( color.GetA(), color.GetR(), color.GetG(), color.GetB() );
}
mask->SetPalette( palette );
free( palette );
}
return mask;
}
Since that didn't work, I tried letting GDI+ create a mask bitmap of the specified size and the copy the pixels into that bitmap. But when I try to display the image I either get nothing or a GPF. My display code is very simple:
// Bitmap *maskBitmap; // Defined elsewhere
Graphics g( hDC );
g.DrawImage( maskBitmap, 0, 0 );
So it basically just creates Graphics object and attempts to draw the image. The latter fails however...
Teis Johansen