Closed kolomiets closed 4 years ago
Commented by neticous on 2015-10-13 20:32 UTC I added some using statements so the above would compile.
using System; using System.Runtime.InteropServices; using System.Diagnostics; using System.Drawing; using System.IO; using System.Threading; using System.Reflection;
Commented by chenar-kostya on 2015-10-16 17:47 UTC Thank you, it really helped.
Updated by mlmcl on 2015-10-18 00:42 UTC
Commented by mlmcl on 2015-10-18 00:42 UTC Thanks for the help. I found the root cause of the problem. The GlobalLock is the key, with a GPTR it returns the same value, with a GHND it returns the pointer. I managed to get a scanner that exhibits the problem as described in this ticket, and confirmed the fix, you'll see the way I did it in the code update that should come out tomorrow. I'll leave the ticket open for confirmation that it's working...
Updated by mlmcl on 2015-10-18 09:28 UTC
Commented by mlmcl on 2015-10-18 09:28 UTC The new code is up, please let me know if it makes a difference...
Reported by neticous on 2015-10-13 20:27 UTC Assuming // Windows uses a DIB, the first usigned short is 40... if (u16Magic == 40) Is not exactly true. For instance the Canoscan Lide 90, 100, 200 sends a DIB back but yoour code does not recognize it and sends back a null bitmap. I added an else to the NativeTobitmap method inorder for this to work. I also cleaned up a leak in the code that assumes if (u16Magic == 40). I have pasted the code below. You can diff to see the changes.
I hope it is OK to paste code here.
///
/// Get .NET 'Bitmap' object from memory DIB via stream constructor.
/// This should work for most DIBs.
///
/// Our operating system
/// The pointer to something (presumably a BITMAP or a TIFF image)
/// C# Bitmap of image
private static Bitmap NativeToBitmap(Platform a_platform, IntPtr a_intptrNative)
{
// We need the first two bytes to decide if we have a DIB or a TIFF...
ushort u16Magic;
u16Magic = (ushort)Marshal.PtrToStructure(a_intptrNative, typeof(ushort));