I have a problem, and i don't know how resolved.. I'm using the drive twain to do scanner some documents, and i don't get create a new BitMap when i'm scanning a big number of the files.. So.. i need help to solution this.. my code is:
public static Bitmap FromHDib(IntPtr dibPtrArg, out ServiceError error)
{
error = null;
try
{
Win32.BITMAPINFOHEADER bmi;
IntPtr pixptr;
var ptr = Win32.GlobalLock(dibPtrArg);
GetPixelInfo(ptr, out pixptr, out bmi);
Bitmap bitMap = new Bitmap(bmi.biWidth, bmi.biHeight);
Graphics scannedImageGraphics = Graphics.FromImage(bitMap);
**IntPtr hdc = scannedImageGraphics.GetHdc();** //parameter is not valid
SetDIBitsToDevice(
hdc,
0, // XDest
0, // YDest
bmi.biWidth,
bmi.biHeight,
0, // XSrc
0, // YSrc
0, // uStartScan
bmi.biHeight, // cScanLines
pixptr, // lpvBits
ptr, // lpbmi
0); // 0 = literal RGB values rather than palette
scannedImageGraphics.ReleaseHdc(hdc);
const float inchPerMeter = 39.3700787F;
bitMap.SetResolution(bmi.biXPelsPerMeter / inchPerMeter, bmi.biYPelsPerMeter / inchPerMeter);
Win32.GlobalUnlock(dibPtrArg);
Win32.GlobalFree(dibPtrArg);
Win32.DeleteDC(hdc);
bitMap.Dispose();
return bitMap;
}
catch (OutOfMemoryException memoryEx)
{
return new Bitmap(0, 0);
}
catch (ArgumentException argEx)
{
return new Bitmap(0, 0);
}
}