PDA

View Full Version : reload a saved bmp file to memory buffer



WK Ho
May 12, 2008, 05:23:57
Hi there

I save the file with the IC3.0 and then later on I want to load in and process it but cannot find a corresponding methods? If one available or need to use the VC's API?

Stefan Geissler
May 13, 2008, 10:55:00
Hi,

I am very sorry, but there is no load function for bmp files. If it is realy needed and you are not able to load a bmp file with the Windows GDI functions, then please let me know. I will try to create a sample. I know, the Windows GDI functions are a little bit "tricky".

WK Ho
June 3, 2008, 07:13:19
Hi Stefan
It would be nice if you can do that

Stefan Geissler
June 3, 2008, 10:43:28
I have a question: For what isse do you need to load a bmp file into a memory buffer? It gives you no advantage, because you can not display it with IC. You can load a bitmap and display it with the standard GDI functions like BitBlt().

Also for image processing you only have the bitmap info header and a pointer to the image data, thus there is no advantage.

Loading a bitmap in Windows is simple:

HBITMAP hBitmap = (HBITMAP)LoadImage( NULL,"bitmap.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE);

Retrieving information about the bitmap is done as follows:


BITMAP BitmapData;
GetObject(hBitmap,sizeof( BITMAP ),&BitmapData);

Stefan Geissler
June 3, 2008, 11:50:04
This is a sample code for loading a BMP file into a membuffer:


bool LoadBitmapIntoBuffer( const smart_ptr<MemBuffer>& buffer, LPCWSTR path )
{
HBITMAP hBmp = (HBITMAP)::LoadImage( NULL, path, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE|LR_CREATEDIBSECTION );
if( hBmp == NULL )
return false;

BITMAP bmp = { 0 };
::GetObject( hBmp, sizeof(bmp), &bmp );

if( bmp.bmWidth != buffer->getSize().cx )
return false;
if( bmp.bmHeight != buffer->getSize().cy )
return false;
if( bmp.bmBitsPixel != buffer->getBitsPerPixel() )
return false;

memcpy( buffer->getPtr(), bmp.bmBits, buffer->getFrameType().buffersize );

DeleteObject(hBmp );
return true;
}

Please keep in mind, the Membuffer exists only, after the live video has been started once (startLive()) or has been perapred once. Otherwise an access violation will happen.

ertem
January 14, 2010, 17:31:30
Hi Stefan,

Do you have any code that will copy a loaded bitmap onto the overlay bitmap. Presumably with a BitBlt.

Note that it is a static image. So I only want to do this once at startup, not for every frame.



hPictureBitmap = (HBITMAP)::LoadImage (0, "Picture.bmp",
IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);


Then, in the overlay callback I have.


pBitmap->beginPaint();
OverlayDC = pBitmap->getDC();
ImageDC=CreateCompatibleDC(OverLayDC);
pBitmap->fill(RGB(0,0,0));
pBitmap->setDropOutColor(RGB(0,0,0)); // for occlusion!
// there is a bunch of pBitmap->draw stuff here
InsertPicture();
// more pBitmap->draw stuff here
pBitmap->endPaint();


Essentially the question is, what is the source hDC in InsertPicture()?
How did the hPictureBitmap get associated with the hdcSrc, which is
resumably going to be ImageDC.


void InsertPicture(void){
BitBlt(
OverlayDC , // handle to destination DC
0, // x-coord of destination upper-left corner
0, // y-coord of destination upper-left corner
50, // width of destination rectangle
50, // height of destination rectangle
hdcSrc, // handle to source DC <- What is this???
0, // x-coordinate of source upper-left corner
0, // y-coordinate of source upper-left corner
SRCCOPY// raster operation code
);


Presumably the dropout color still works for the copied bitmap too, right?

Not specifically an IC question, just simple Windows stuff, but you're my only hope ObiWan... :-)

Thanks

ertem
January 14, 2010, 17:52:34
Actually, instead of BitBlt, I probably should have said AlphaBlend...

BOOL AlphaBlend(
HDC hdcDest, // handle to destination DC
int nXOriginDest, // x-coord of upper-left corner
int nYOriginDest, // y-coord of upper-left corner
int nWidthDest, // destination width
int nHeightDest, // destination height
HDC hdcSrc, // handle to source DC
int nXOriginSrc, // x-coord of upper-left corner
int nYOriginSrc, // y-coord of upper-left corner
int nWidthSrc, // source width
int nHeightSrc, // source height
BLENDFUNCTION blendFunction // alpha-blending function
);


But how does windows copy a bitmap to a dc?

Stefan Geissler
January 15, 2010, 09:34:51
Hello ertem,

First of all, if your bitmap is static, that means it does not change and behaves like a station logo on TV, then you can blit the image only once after a live start call on your Overlaybitmap. You do not need the OverlayUpdate event.

The DC you receive from the Overlay is a memory DC that holds a memory bitmap. The bits of the memory bitmap are copied, not blitted on the video frames. Thus your alphablend call has no effect.

For doing alphablending I suggest to use a framefilter instead of the Overlay Bitmap. In the framefilter you can copy your image bits on your own on the live video bytes. I am very sorry, but there is no better solution available.

May be we can develop such a filter together.

Edwyn15
October 16, 2013, 20:22:42
Hello,

I have a similar problem. I'm trying to overlay a bitmap picture from a file on top of the live video in LabVIEW, any idea on how to accomplish this? Camera is a DFK 23UP031. I'll appreciate the help.

Stefan Geissler
October 21, 2013, 10:03:59
Hello,

we only showed, how to do this in Visual Basic 6 at
http://www.imagingcontrol.com/en_US/support/documentation/activex/GraphicOverlay.htm
in the sub chapter "GDI Functions in Visual Basic 6"

Unfortunately my LabVIEW knowledge is not good enough, so I do not know, whether LabVIEW can handle a Windows Device Context and use the Windows GDI functions.