About commonly used JPG, dynamic GIF, BMP and other common solutions (honors, enthusiasm, wisdom, dreams, are all from Open sour

xiaoxiao2021-03-06  69

This article demonstration code package download: pic_test.rar <- temporarily unable to download, A bird looks for new free space common way 0, use GIF89A class: advantage: a quick and easy to eat, dynamic GIF two sentences, simple and convenient and shortcomings : Sometimes edge effects, some images will be very obvious: #include "gif89a.h" CGIF89A * GIF; Add: gif = new cgif89a (this-> m_hwnd); gif-> loading Test.gif "); GIF-> setPosition (100, 100); GIF-> Play ();

// gif-> pause (true); // pause (true) is a playback of GIF // gif-> pause (false); // pause (false) To continue with GIF playback Common Ways 1, use iPicture: advantage : MS early picture class, you can display all static pictures, display dynamic GIF still need a GIF image storage structure Gifimage, if you are interested, you can see how Xuebi shows dynamic GIF shortcomings in VC: user independent definition Not very convenient, Xue Bi Article is introduced in RC static editing to display dynamic GIF approach. I originally intended to rewrite the GIF class, I found GIF89a, so I didn't make excess work modulation method: cstring spath;

Spath = _t ("1.jpg"); // CDC * PDC = getDLGITEM (IDC_Control) -> getdc (); // Get control DC CRECT ZCRECT; getClientRect (& zcRect); showjpgif (PDC, Spath, ZcRect.Left, ZcRect.top, zcRect.width (), zcRect.height ());

Function implementation

Bool Showjpgif (CDC * PDC, CString Strpath, Int x, Int Y, Int Width, Int Height)

{

IStream * PSTM;

CFILESTATUS FSTATUS;

CFILE FILE;

Long Cb;

// Open the file and detect the validity of the file

IF (file.open (strpath, cfile :: moderead) &&

File.getStatus (StrPath, FStatus) &&

((cb = fStatus.m_size)! = -1)))

{

Hglobal Hglobal = GlobalAlloc (GMEM_MOVEABLE, CB);

LPVOID PVDATA = NULL;

IF (hglobal! = null)

{

Pvdata = Globalock (Hglobal);

IF (PVData! = NULL)

{

File.read (PVDATA, CB);

GlobalUnlock (Hglobal);

CreatestReamonhglobal (Hglobal, True, & PSTM);

}

}

}

Else

{

Return False;

} // Open the end of the file

/ / Display images in JPEG and GIF formats, GIF can only display one frame, but also no animation,

/ / To display an animation GIF, use the Active control //.

IPicture * PPIC;

// load image from File Stream

IF (Succeeded (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, Width, Height, 0,

Hmheight, hmwidth,-hmheight, null)) {

PPIC-> Release ();

Return False;

}

PPIC-> Release ();

}

Else

{

Return False;

}

Return True;

} Common way 2, use MS CIMAGE Advantages: MS CiMage, MFC / ATL Universal, should be reliable, easy to use is very simple, more flexible, destination should be the disadvantage of Ipicture class: still can't make perfect solution Dynamics GIF Question, #include cimage m_image; // ps: The following insertion call function CString strfilter; csimpleArray AguidFileTypes; HRESULT HRESULT; / / CIMAGE M_IMAGE

/ / Get filter string of image file supported by CImage HRESULT = m_image.GETEXPORTERFILTERSTRING (Strfilter, AguidFileTypes, _T ("all Image files")); if (failed (hResult) {MessageBox ("GetExporterfilter call failed!"); Cfiled; cfiledialog DLG (True, NULL, NULL, OFN_FILEMUSTEXIST, STRFILTER); if (iDok! = DLG.DOMODAL ()) Return;

m_image.destroy (); // Load the external image file into the CImage object HRESULT = M_Image.Load (DLG.GetFileName ()); if (Failed) {MessageBox ("calling image file failed!"); Return }

/ / Set the main window title bar content cstring str; str.loadstring (AFX_IDS_APP_TITLE); AFXGETMAINWND () -> setWindowText (STR "-" DLG.GetFileName ());

Invalidate (); // Forced call overdraw // ps: The following insertion Heavy Pictures VOID CTEMP7VIEW :: OnDRAW (CDC * PDC) {ctemp7doc * pdoc = getDocument (); assert_valid (pdoc); // Todo: here This machine data adds drawing code if (! M_image.isnull ()) {crect zcRect; getClientRect (& zcRect); m_image.draw (pdc-> m_hdc, zcRect.Width (), zcRect.height (), zcRect.height ());

}

转载请注明原文地址:https://www.9cbs.com/read-90655.html

New Post(0)