TWAIN Working Group

Newsletter Signup
Donate
Help keep TWAIN free
  • About TWAIN
    • What’s New?
    • News
    • Events
    • Membership
    • Consider a Donation
    • Contact Us
  • Why TWAIN?
  • Developers
    • Driver Developer
    • Application Developer
    • TWAIN Features
    • Specification & Tools
    • Self Certification Process
  • Support Forums
  • Scanner End-User
  • Find Certified Drivers
    • Facebook
    • LinkedIn
    • Vimeo

Reply To: BitDepth Set for B/W (C#)

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
kitchenam
Participant
  • Topics - 1
  • Replies - 2
  • Total Posts - 3

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;
}

Quick Links

Service Providers
TWAIN Support Forums
Membership
Contact Us
Privacy Policy

Newsletter Signup

TWAIN Working Group Family

TWAIN Working Group
TWAIN Direct®
TWAIN Resources
TWAIN Certified Drivers
PDF/raster

  • Facebook
  • GitHub
  • LinkedIn
  • Vimeo

Recent Topics

  • EPSON V600 TWAIN and WIA on Windows 10
  • When and how to use WaitForEvents command ?
  • Problem enumerating list of installed scanners in windows server 2012
  • Failed to create TWAIN progress! Error code is 1260.
  • To get the list of scanners from javascript client side (browser)
  • Quarterly Newsletter
  • TWAIN Working Group Membership
  • Logo Usage
  • TWAIN License
  • Contact Us
Privacy Policy • Privacy Tools • Copyright © 2021 TWAIN Working Group • by iHwy, LLC • Log in