Re: Using SetDIBitsToDevice with C#?
- From: dzar <dzar@xxxxxxxxxxxxx>
- Date: Mon, 01 May 2006 11:00:20 -0500
> .Net Winform uses GDI+ internally, I am not sure if this is the problem.
> Also, SetDIBitstoDevice should be replaced by StretchDIBits API, because it
> is a superset of SetDIBitstoDevice.
>
I'll look into this. I do care A LOT about speed, so if it's slower, I'm not terribly interested (unless it fixes this color map problem).
> Anyway, is it possible for you to create a sample small project to
> demonstrate the problem? Then we may understand the problem better. Thanks
>
See below...
> Best regards,
> Jeffrey Tan
> Microsoft Online Community Support
> ==================================================
> When responding to posts, please "Reply to Group" via your newsreader so
> that others may learn and benefit from your issue.
> ==================================================
> This posting is provided "AS IS" with no warranties, and confers no rights.
>
Here is some code. Since we're trying to use a couple external DLLs that I cannot post (in public) I cannot give you something that will compile, but here is what my C# guy (who is quite capable) is trying. Again, he gets a window with the bitmap displayed, but the color map is wrong.
-----------------
FILE: BmodeDLL.cs
// all within the same namespace and class BmodeDll
// some constants
public const int NumRGBQUAD = 256;
// some functions
public static void InitializeDIB(ref BmBitmapInfoStruct bmi, int winXSize, int winYSixe)
{ // set up the DIB information just like I would do in C using only
// the win32 API
bmi.bmiHeader.biSize = 0x28;
bmi.bmiHeader.biWidth = winXSize;
bmi.bmiHeader.biHeight = -winYSixe;
bmi.bmiHeader.biPlanes = 1;
bmi.bmiHeader.biBitCount = 8;
bmi.bmiHeader.biCompression = 0;
bmi.bmiHeader.biXPelsPerMeter = 0;
bmi.bmiHeader.biYPelsPerMeter = 0;
bmi.bmiHeader.biClrUsed = 0;
bmi.bmiHeader.biClrImportant = 0;
// sets up gray scale colormap... we're using a 24-bit display so this works
for(int i=0; i<NumRGBQUAD; i++ )
{
bmi.bmiColors[i].rgbRed = (Byte) i;
bmi.bmiColors[i].rgbBlue = (Byte) i;
bmi.bmiColors[i].rgbGreen = (Byte) i;
bmi.bmiColors[i].rgbReserved = 0;
}
return;
}
------------------
FILE: ShowImage.cs
// initialize the bitmap and initialize it
private unsafe void InitWindow()
{
bmi = new BmodeDll.BmBitmapInfoStruct();
bmi.bmiColors = new BmodeDll.RGBQUAD[BmodeDll.NumRGBQUAD];
BmodeDll.InitializeDIB(ref bmi, (Int32) winXSize, (Int32) winYSize);
// more init stuff...
}
// This is trying to implement what I'd do in C.
// GetDC()
// CreateCompatibleBitmap()
// get a pointer to the bitmap bits for use in the display routine
// ReleaseDC()
// previously,
// hwnd = ImagePanel.Handle;
// in another initialization routine
private unsafe void SetupBitmap4CLand()
{
try
{
IntPtr hwDC = BmodeDll.GetDC(hwnd); // hwnd is the handle
// to the form
Size clientSize = imagePanel.ClientSize;
IntPtr hData = BmodeDll.CreateCompatibleBitmap(hwDC,
bm.bmWidth, bm.bmHeight);
bm = new BmodeDll.BITMAP();
BmodeDll.GetObject(hData, sizeof (BmodeDll.BITMAP), ref bm);
byBits = new Byte[(bm.bmWidth+16)*(bm.bmHeight+4)];
BmodeDll.ReleaseDC(hwnd, hwDC);
}
// exception processing here...
}
// Now try to draw the bitmap. What's happening in the DLLs is that
// UsbProbeDll.usbCineFramePtr() returns a pointer to an array of bits
// that will be used to calculate the display image.
// Then BmodeDll.bmDrawImage will use those bits, the DIB and such to form
// the image and display it in the window contained in hwnd.
//
// bmDrawImage returns bm (the device dependent bitmap) as well,
// so we might be able to use that,
// but this is a real-time imaging application and we would rather have finer
// control than passing this data around and letting .NET display it - previous
// experience with this method has proved to be (much) slower,
// but that was in earlier
// versions of .NET, VS, C++ and such... We use this for things like saving
// a bitmap to disk.
public unsafe void DrawBmodeImageCLand()
{
try
{
bsptr = UsbProbeDll.usbCineFramePtr();
fixed (byte* pByBits = byBits)
{
BmodeDll.bmDrawImage(hwnd, bsptr, bm, pByBits, ref bmi);
}
}
// exception processing here...
}
I hope this helps. I'm new to the C# world so let me know what else you might want to know and I'll try to get you that.
Regards,
Dave
.
- Follow-Ups:
- Re: Using SetDIBitsToDevice with C#?
- From: dzar
- Re: Using SetDIBitsToDevice with C#?
- References:
- RE: Using SetDIBitsToDevice with C#?
- From: "Jeffrey Tan[MSFT]"
- RE: Using SetDIBitsToDevice with C#?
- Prev by Date: RE: Using SetDIBitsToDevice with C#?
- Next by Date: Re: Using SetDIBitsToDevice with C#?
- Previous by thread: RE: Using SetDIBitsToDevice with C#?
- Next by thread: Re: Using SetDIBitsToDevice with C#?
- Index(es):
Relevant Pages
|