JPG, Dynamic GIF, BMP Some common solutions

xiaoxiao2021-03-06  59

JPG, Dynamic GIF, BMP Some common solutions

Common way 0, use GIF89A class: Advantage: A strike is all over the day, up to dynamic GIF, down to static JPG, BMP two sentences, simple and convenient and disadvantages: sometimes edge effects, some images will be very obvious :  # include "gif89a.h" CGIF89A * GIF;  Add:  gif = new cgif89a (this-> m_hwnd);  gif-> Load ("Test.gif");  gif-> setPosition (100, 100);  gif-> play ();  // gif-> pause (true); // pause True) To pause GIF play  // gif-> pause (false); // pause (false) To continue with GIF Playing Common Ways 1, use iPicture: Advantages: MS early picture class, you can display all Static picture, display dynamic GIF still needs a GIF image storage structure gifimage, if you are interested, you can see how Xuebi shows dynamic GIF disadvantages in VC: users are not very convenient, Xue Bi Articles are introduced RC static editing shows dynamic GIF approach, I originally intended to rewrite the GIF class, found GIF89a, so I didn't make more work modes:  cstring spath; sspath = _t ("1.jpg" );  // cdc * PDC = getdlgitem (IDC_Control) -> getdc (); // get control DC CRECT ZCRECT;  GetClientRect (& ZCRECT);  Showjpggif (PDC, Spath, ZcRect.Left, ZcRect .top, zcRect.width (), zcRect.Height ()); Function Implementation BOOL Showjpggif (CDC * PDC, CString Strpath, Int x, Int Y, Int Width, Int Height) { iStream * PSTM;  cfilestatus fstatus;  cfile file;  long cb;  // Open file and detect validity of files  IF (file. Open (StrPath, Cfile & :: ModeRead &&) File.GetStatus (StrPath, FSTA Tus) &&  ((cb = fstatus.m_size)! = -1))  {HGLOBAL HGLOBAL = GLOBALLOC (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 file end  // Display Pictures in JPEG and GIF formats, GIF can only display one frame, but also not display movies,  ​​// To display animation GIF, please use Active control //.

 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  (failed (ppic-> render (* PDC, X, Y, Width, Height, 0,  hmheight , hmwidth, null))  { ppic-> release ();  return false; }  PPIC-> Release (); } ELSE {Return false; } ​​return true;} Common way 2, using MS CIMAGE Advantages: MS CIMAGE Advantages: MFC / ATL Universal, should be reliable, easy to use Easy, more flexible, dedicated to replacing the iPicture class shortcomings: or to solve dynamic GIF issues, #include cimage m_image; // ps: The following insertion function  CString strfilter;   csimpler Ray 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! "); RETURN; }  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 (HRESULT))  {messagebox ("calling image file failed!"); return; }   // Set the main window title bar content  CString STR;

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

New Post(0)