Home › Forums › TWAIN Classic › BitDepth Set for B/W (C#) › Reply To: BitDepth Set for B/W (C#)
August 22, 2008 at 1:34 pm #24597
I thought I’d post the working SaveDIBAs method code for reference if anyone else runs across this issue.
public static bool SaveDIBAs( string fileName, IntPtr bminfo, IntPtr pixdat )
{
Guid clsid;
if( ! GetCodecClsid( fileName, out clsid ) )
{
MessageBox.Show( "Unknown picture format for extension " + Path.GetExtension( fileName ), "Image Codec", MessageBoxButtons.OK, MessageBoxIcon.Information );
return false;
}
IntPtr img = IntPtr.Zero;
int st = GdipCreateBitmapFromGdiDib( bminfo, pixdat, ref img );
if( (st != 0) || (img == IntPtr.Zero) )
return false;
// obtain managed bitmap image from gdiplus dll
MethodInfo mi = typeof(Bitmap).GetMethod("FromGDIplus", BindingFlags.Static | BindingFlags.NonPublic);
Bitmap bmp = (Bitmap)mi.Invoke(null, new object[] {img});
bmp.Save(fileName);
bmp.Dispose();
// causing the image to be saved in a default 24 bpp inflated format
//st = GdipSaveImageToFile( img, fileName, ref clsid, IntPtr.Zero );
GdipDisposeImage( img );
return st == 0;
}