// Draw images through resources
Static void drawbitmap (uint bitmap, CDC * PDC, crect rect)
{
Cbitmap BMP;
If (BMP. loadbitmap (Bitmap ))
{
Bitmap BMP Info;
BMP. getbitmap (& BMP info );
CDC dcmemory;
Dcmemory. createcompatibledc (PDC );
Dcmemory. SelectObject (& BMP );
PDC-> setstretchbltmode (halftone );
PDC-> stretchblt (rect. left, rect. top, rect. width (), rect. height (), & dcmemory, 0, BMP info. bmwidth, BMP info. bmheight, srccopy );
}
}
// Draw a picture using a BMP file
Static void drawbitmapformfile (cstring bitmapfilepath, CDC * PDC, crect rect)
{
Handle filehandle =: LoadImage (null, bitmapfilepath, image_bitmap, 0, 0, lr_loadfromfile );
If (filehandle! = NULL)
{
Cbitmap BMP;
If (BMP. Attach (filehandle ))
{
Bitmap BMP Info;
BMP. getbitmap (& BMP info );
CDC dcmemory;
Dcmemory. createcompatibledc (PDC );
Dcmemory. SelectObject (& BMP );
PDC-> setstretchbltmode (halftone );
PDC-> stretchblt (rect. left, rect. top, rect. width (), rect. height (), & dcmemory, 0, BMP info. bmwidth, BMP info. bmheight, srccopy );
BMP. Detach ();
}
}
}
// Draw images through resources
Static void drawbitmap (uint bitmap, CDC * PDC, crect rect)
{
Cbitmap BMP;
If (BMP. loadbitmap (Bitmap ))
{
Bitmap BMP Info;
BMP. getbitmap (& BMP info );
CDC dcmemory;
Dcmemory. createcompatibledc (PDC );
Dcmemory. SelectObject (& BMP );
PDC-> setstretchbltmode (halftone );
PDC-> stretchblt (rect. left, rect. top, rect. width (), rect. height (), & dcmemory, 0, BMP info. bmwidth, BMP info. bmheight, srccopy );
}
}
// Draw a picture using a BMP file
Static void drawbitmapformfile (cstring bitmapfilepath, CDC * PDC, crect rect)
{
Handle filehandle =: LoadImage (null, bitmapfilepath, image_bitmap, 0, 0, lr_loadfromfile );
If (filehandle! = NULL)
{
Cbitmap BMP;
If (BMP. Attach (filehandle ))
{
Bitmap BMP Info;
BMP. getbitmap (& BMP info );
CDC dcmemory;
Dcmemory. createcompatibledc (PDC );
Dcmemory. SelectObject (& BMP );
PDC-> setstretchbltmode (halftone );
PDC-> stretchblt (rect. left, rect. top, rect. width (), rect. height (), & dcmemory, 0, BMP info. bmwidth, BMP info. bmheight, srccopy );
BMP. Detach ();
}
}
}
View plaincopy to clipboardprint?
Bool cshowbitmapview: showjpggif (CDC * PDC, cstring strpath, int X, int y) // open jpg and other image files by reading file information
{
Istream * PSTM;
Cfilestatus fstatus;
Cfile file;
Long CB;
// Open the file and check the file Validity
If (file. Open (strpath, cfile: moderead )&&
File. getstatus (strpath, fstatus )&&
(Cb = fstatus. m_size )! =-1 ))
{
Hglobal = globalalloc (gmem_moveable, CB );
Lpvoid pvdata = NULL;
If (hglobal! = NULL)
{
Pvdata = globallock (hglobal );
If (pvdata! = NULL)
{
// File. readhuge (pvdata, CB); // This function may be used in 6.0.
File. Read (pvdata, CB); // use this function in vc2005.net
Globalunlock (hglobal );
Createstreamonhglobal (hglobal, true, & PSTM );
}
}
}
Else
{
Return false;
} // The end of opening the file
// Display JPEG and GIF images. a GIF can only display one frame, but not an animation,
// Use the Active Control to display animated GIF images.
Ipicture * PPIC;
// Load image from file stream
If (succeeded (oleloadpicture (PSTM, fstatus. m_size, true, iid_ipicture, (lpvoid *) & PPIC )))
{
Ole_xsize_himetric hmwidth;
Ole_ysize_himetric hmheight;
PPIC-> get_width (& hmwidth );
PPIC-> get_height (& hmheight );
Double FX, FY;
// Get image height and width
FX = (double) PDC-> getdevicecaps (horzres) * (double) hmwidth/(double) PDC-> getdevicecaps (horzsize) * 100.0 );
FY = (double) PDC-> getdevicecaps (vertres) * (double) hmheight/(double) PDC-> getdevicecaps (vertsize) * 100.0 );
// Use render function display image
If (failed (PPIC-> render (* PDC, X, Y, (DWORD) FX, (DWORD) FY, 0, hmheight, hmwidth,-hmheight, null )))
{
PPIC-> release ();
Return false;
}
PPIC-> release ();
}
Else
{
Return false;
}
Return true;
}
This article from the csdn blog, reproduced please indicate the source: http://blog.csdn.net/logic_nut/archive/2009/11/20/4843923.aspx