Click here to Skip to main content
15,896,726 members
Home / Discussions / C#
   

C#

 
GeneralRe: Hashtable question Pin
Arjan Einbu17-Jul-03 0:16
Arjan Einbu17-Jul-03 0:16 
GeneralRe: Hashtable question Pin
Frank Olorin Rizzi17-Jul-03 5:13
Frank Olorin Rizzi17-Jul-03 5:13 
GeneralRe: Hashtable question Pin
Jim Stewart17-Jul-03 5:14
Jim Stewart17-Jul-03 5:14 
GeneralRe: Hashtable question Pin
Arun Bhalla22-Jul-03 15:16
Arun Bhalla22-Jul-03 15:16 
GeneralAssigning text or name of button to variable Pin
eggie516-Jul-03 22:38
eggie516-Jul-03 22:38 
GeneralRe: Assigning text or name of button to variable Pin
fool16-Jul-03 23:39
fool16-Jul-03 23:39 
GeneralRe: Assigning text or name of button to variable Pin
eggie517-Jul-03 10:48
eggie517-Jul-03 10:48 
GeneralConvert HDIB to Bitmap, so close and yet so far Pin
Brendan Tregear16-Jul-03 22:29
Brendan Tregear16-Jul-03 22:29 
Hi Guys..

I've been going crazy for two days now, and I feel I'm very close. I've got a 3rd party DLL that returns a HANDLE to a DIB (GDI). I've retrieved the BITMAPINFO structure, created a Bitmap and locked the bits. However, when I try and copy the data in, I always get an unhandled exception. Here's my code:

<br />
IntPtr lpArray = CaptureAndFetch(); // Returns a HANDLE to a DIB<br />
IntPtr pDib = GlobalLock(lpArray);<br />
BITMAPINFO pbmi = (BITMAPINFO)Marshal.PtrToStructure(pDib, typeof(BITMAPINFO));  // Get pointer to the BITMAPINFO structure<br />
<br />
bitmap = new Bitmap(pbmi.bmiHeader.biWidth, pbmi.bmiHeader.biHeight, PixelFormat.Format24bppRgb);<br />
<br />
BitmapData bmData;	<br />
Rectangle rect = new Rectangle(0, 0, pbmi.bmiHeader.biWidth, pbmi.bmiHeader.biHeight );<br />
bmData = bitmap.LockBits(rect, ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb );<br />
<br />
GCHandle hSrc = GCHandle.Alloc(pDib, GCHandleType.Pinned ); // Get GCHandle to DIB<br />
IntPtr pBits = hSrc.AddrOfPinnedObject();<br />
<br />
// Now get location of bits. These are *after* the BITMAPINFO structure in a packed DIB<br />
Int32 pAddress = (Int32)pBits;<br />
// Add on length of structure...<br />
pAddress += Marshal.SizeOf(pbmi);<br />
pBits = (IntPtr)pAddress;<br />
<br />
GCHandle hDest = GCHandle.Alloc(bmData.Scan0, GCHandleType.Pinned);<br />
IntPtr pDest = hDest.AddrOfPinnedObject();<br />
<br />
int length = pbmi.bmiHeader.biHeight * bmData.Stride;<br />
<br />
// Copy the data from memory to the Scan0 property of our Bitmap<br />
byte databyte;<br />
for (int idx = 0; idx <= length; idx++)<br />
{<br />
	databyte = Marshal.ReadByte(pBits, idx); // CRASHES HERE AFTER 2000 loops!<br />
	Marshal.WriteByte(pDest, idx, databyte);<br />
}<br />
<br />
bitmap.UnlockBits( bmData );<br />
hSrc.Free();<br />
hDest.Free();<br />
GlobalUnlock(lpArray);<br />

GeneralRe: Convert HDIB to Bitmap, so close and yet so far Pin
Stephane Rodriguez.17-Jul-03 3:23
Stephane Rodriguez.17-Jul-03 3:23 
GeneralRe: Convert HDIB to Bitmap, so close and yet so far Pin
J. Dunlap17-Jul-03 8:23
J. Dunlap17-Jul-03 8:23 
GeneralRe: Convert HDIB to Bitmap, so close and yet so far Pin
J. Dunlap17-Jul-03 8:22
J. Dunlap17-Jul-03 8:22 
GeneralRe: Convert HDIB to Bitmap, so close and yet so far Pin
Brendan Tregear17-Jul-03 16:01
Brendan Tregear17-Jul-03 16:01 
GeneralIs that possible Pin
Kerad16-Jul-03 22:18
Kerad16-Jul-03 22:18 
GeneralRe: Is that possible Pin
leppie17-Jul-03 7:23
leppie17-Jul-03 7:23 
GeneralGDI+ help Pin
r916-Jul-03 21:36
r916-Jul-03 21:36 
GeneralRe: GDI+ help Pin
r916-Jul-03 23:01
r916-Jul-03 23:01 
GeneralRe: GDI+ help Pin
J. Dunlap17-Jul-03 8:07
J. Dunlap17-Jul-03 8:07 
GeneralRe: GDI+ help Pin
r917-Jul-03 22:55
r917-Jul-03 22:55 
GeneralRe: GDI+ help Pin
J. Dunlap18-Jul-03 11:38
J. Dunlap18-Jul-03 11:38 
GeneralRe: GDI+ help Pin
r918-Jul-03 12:22
r918-Jul-03 12:22 
GeneralFunction Keys Pin
Riaan van der Westhuizen16-Jul-03 20:40
Riaan van der Westhuizen16-Jul-03 20:40 
GeneralRe: Function Keys Pin
fool16-Jul-03 23:55
fool16-Jul-03 23:55 
GeneralRe: Function Keys Pin
Jim Stewart17-Jul-03 5:18
Jim Stewart17-Jul-03 5:18 
QuestionVertical Text? Pin
peenu16-Jul-03 18:59
peenu16-Jul-03 18:59 
AnswerRe: Vertical Text? Pin
fool17-Jul-03 0:01
fool17-Jul-03 0:01 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.