⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 webimgview.cpp

📁 快速处理基于 Web 的各种图象文件.zip
💻 CPP
📖 第 1 页 / 共 5 页
字号:
		else
			CurrentFrameItem=1;
		
		//First draw the frame and then wait
		DrawFrame(CurrentFrameItem);
		
		//This is the delay between each image
		DWORD Now = GetTickCount() + GetAnimationDelayTime(CurrentFrameItem);

		//While waiting process the messages 
		DWORD Future = GetTickCount();
		while (Now > Future) 
		{
			if (ExitingApp) break;
			PumpMessages();
			Future = GetTickCount();
		}
	  }
	  break;
 }
 InTimer = false;

 CView::OnTimer(nIDEvent);
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//get the number of loops from the header. "Also called NetScape loops"
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int CWebImgView::GetAnimationLoops() 
{
	if (ExitingApp) return 0;
	TMyGifAnimation *PMyGif = (TMyGifAnimation*) GifList[1];
	if (PMyGif)
	{
	  return PMyGif->NetLoops;
	}
	return 0;
}


//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//get the miliseconds to delay from the header
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int CWebImgView::GetAnimationDelayTime(int frame) 
{
	TMyGifAnimation *PMyGif = (TMyGifAnimation*) GifList[frame];
	if (PMyGif)
	{
	  return PMyGif->DelayTime*10;
	}
	return 0;
}


//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Start the animation sequence
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CWebImgView::OnStartanimation() 
{
	KillTimer(IDAnimateTimer);
	FirstFileDrawing = false;
	OnDraw(GetDC());
    
	SetTimer(IDAnimateTimer, 15 ,NULL);

}


//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Stop the animation sequence and/or stop loading
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CWebImgView::OnStopanimation() 
{
	KillTimer(IDLoadTimer);
	KillTimer(IDAnimateTimer);
	CancelLoadImage=0;
}


//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
HANDLE CWebImgView::MakeMaskDib(HANDLE hsDIB,
								long new_width,
                   				long new_height,
								UINT TransparentColorIndex)
{
  HANDLE H;
  LPBITMAPINFOHEADER lpBI;        
  LPBITMAPINFO       lpBMI;        
  BYTE               *lpBits;      
  LPBITMAPINFOHEADER MasklpBI;        
  LPBITMAPINFO       MasklpBMI;       
  BYTE               *MasklpBits;      
  BYTE				 LowerSource;
  BYTE				 UpperSource;

  int                szImageBits, i;

  
  //MAKE MASK 
  switch (GetDIBBitPerPixel(hsDIB))
  {
	case 1:
		{
          //This is easy, just return a copy or the inverted copy of the dib
		  if (TransparentColorIndex == 1)
		  {
			H = CopyDIB(hsDIB);
		  }
		  else
		  {
			H = CopyAndInvert1BitDIB(hsDIB);
		  }
		}
		break;

	case 4:
		{
		  //H is a handle to a 4 bit image
		  H = CreateNewDib(new_width,new_height,4);

		  //This is gone be the nasty one

		  lpBMI = (LPBITMAPINFO) GlobalLock(hsDIB);  
		  lpBI  = (LPBITMAPINFOHEADER) lpBMI;
		  if (!lpBI) { GlobalUnlock(hsDIB); return NULL;}
		  lpBits = GetDIBBits(lpBI);

		  MasklpBMI = (LPBITMAPINFO) GlobalLock(H);  
		  MasklpBI  = (LPBITMAPINFOHEADER) MasklpBMI;
		  if (!MasklpBI) { GlobalUnlock(H); return NULL;}
		  MasklpBits = GetDIBBits(MasklpBI);

		  MasklpBMI->bmiColors[0].rgbRed=0;
		  MasklpBMI->bmiColors[0].rgbGreen=0;
		  MasklpBMI->bmiColors[0].rgbBlue=0;

		  MasklpBMI->bmiColors[15].rgbRed=255;
		  MasklpBMI->bmiColors[15].rgbGreen=255;
		  MasklpBMI->bmiColors[15].rgbBlue=255;

		  szImageBits = (GetDIBStorageWidth(hsDIB) * new_height) / 2;
		  for (i=1; i < szImageBits;i++)
		  {
			UpperSource = *lpBits / 16;
			LowerSource = *lpBits++ & 15;

			if (UpperSource == TransparentColorIndex)
			{
				*MasklpBits = (BYTE) 255 << 4;
			}
			else
			{
				*MasklpBits = (BYTE) 0 << 4;
			}
 
			if (LowerSource == TransparentColorIndex)
			{
				*MasklpBits++ |= 255;
			}
			else
			{
				*MasklpBits++ |= 0;
			}
		  }
		  GlobalUnlock(hsDIB);     
		  GlobalUnlock(H);     
		}
		break;

	case 8:
		{
		  //H is a handle to a 8 bit image
		  H = CreateNewDib(new_width,new_height,8);

		  lpBMI = (LPBITMAPINFO) GlobalLock(hsDIB);  
		  lpBI  = (LPBITMAPINFOHEADER) lpBMI;
		  if (!lpBI) { GlobalUnlock(hsDIB); return NULL;}
		  lpBits = GetDIBBits(lpBI);

		  MasklpBMI = (LPBITMAPINFO) GlobalLock(H);  
		  MasklpBI  = (LPBITMAPINFOHEADER) MasklpBMI;
		  if (!MasklpBI) { GlobalUnlock(H); return NULL;}
		  
		  MasklpBits = GetDIBBits(MasklpBI);

		  MasklpBMI->bmiColors[0].rgbRed=0;
		  MasklpBMI->bmiColors[0].rgbGreen=0;
		  MasklpBMI->bmiColors[0].rgbBlue=0;

		  MasklpBMI->bmiColors[255].rgbRed=255;
		  MasklpBMI->bmiColors[255].rgbGreen=255;
		  MasklpBMI->bmiColors[255].rgbBlue=255;

		  szImageBits = GetDIBStorageWidth(hsDIB) * new_height;
		  for (i=1; i < szImageBits;i++)
		  {
			if (*lpBits++ == TransparentColorIndex)
				*MasklpBits++=255;
			else
				*MasklpBits++=0;
		  }
		  GlobalUnlock(hsDIB);     
		  GlobalUnlock(H);     
		}
		break;
  }
  //END MAKE MASK 

  return H;
}









//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CWebImgView::OnFileOpen() 
{
	OnStopanimation();
  	OPENFILENAME ofn;
	char szFile[256], szFileTitle[256];
	LPSTR szFilter = "GIF\0*.gif\0\0";
	szFile[0] = '\0';
	ofn.lStructSize = sizeof(OPENFILENAME);
	ofn.hwndOwner = m_hWnd;
	ofn.lpstrFilter = szFilter;
	ofn.lpstrCustomFilter = (LPSTR) NULL;
	ofn.nMaxCustFilter = 0;
	ofn.nFilterIndex = 1;
	ofn.lpstrFile = szFile;
	ofn.nMaxFile = sizeof(szFile);
	ofn.lpstrFileTitle = szFileTitle;
	ofn.nMaxFileTitle = sizeof(szFileTitle);
	ofn.lpstrInitialDir = NULL; // lpDefPath;
	ofn.lpstrTitle = NULL;
	ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST; 
	ofn.nFileOffset = 0;
	ofn.nFileExtension = 0;
	ofn.lpstrDefExt = NULL;
	ofn.lpfnHook = NULL;
	if (GetOpenFileName( &ofn ))
	{
    	ClearList();
	    CurrentFrameItem = 0;
		LoadTimerSet=false;
		LoadingImage=true;
		CancelLoadImage=1;
		InTimer = false;
		FirstFileDrawing = true;
		InvalidateRect(NULL, false);
		if (My_an_rdgiffiledib)
			My_an_rdgiffiledib(ofn.lpstrFile, 
								RGB(0,0,0),
								pfcallapp,
								(long) this,
								"unilzw",
								0);
		KillTimer(IDLoadTimer);
		LoadingImage=false;
		CurrentFrameItem = 1;	
		
		

	}
		


}




void CWebImgView::OnFileSave() 
{
	OnStopanimation();
  	OPENFILENAME ofn;
	char szFile[256], szFileTitle[256];
	LPSTR szFilter = "GIF\0*.gif\0\0";
	szFile[0] = '\0';
	ofn.lStructSize = sizeof(OPENFILENAME);
	ofn.hwndOwner = m_hWnd;
	ofn.lpstrFilter = szFilter;
	ofn.lpstrCustomFilter = (LPSTR) NULL;
	ofn.nMaxCustFilter = 0;
	ofn.nFilterIndex = 1;
	ofn.lpstrFile = szFile;
	ofn.nMaxFile = sizeof(szFile);
	ofn.lpstrFileTitle = szFileTitle;
	ofn.nMaxFileTitle = sizeof(szFileTitle);
	ofn.lpstrInitialDir = NULL; // lpDefPath;
	ofn.lpstrTitle = NULL;
	ofn.Flags = OFN_OVERWRITEPROMPT; 
	ofn.nFileOffset = 0;
	ofn.nFileExtension = 0;
	ofn.lpstrDefExt = "GIF";
	ofn.lpfnHook = NULL;
	if (GetSaveFileName( &ofn ))
	{
		SaveCurrentFrame = false;
		TMyGifAnimation *PG = (TMyGifAnimation*) GifList[0];
		
		short Resolution;
		Resolution =GetDIBBitPerPixel(PMyGifAnimation->HDib); 
		if (Resolution  >8)
			Resolution = 8;
	
		if (My_an_wtgiffiledib)
			My_an_wtgiffiledib(ofn.lpstrFile, 
							   (short) GifList.Size()-1,
                               PG->ScreenWidth,
                               PG->ScreenHeight,
                               (short)PG->BackGroundColor,
                               Resolution,
                               0,
                               PG->NetLoops,
							   savegifcallapp,
							   (long) this,
							   "unilzw",
							   0);
								


	}
	
		
}

void CWebImgView::OnFileSavecurrentframe() 
{
	OnStopanimation();
  	OPENFILENAME ofn;
	char szFile[256], szFileTitle[256];
	LPSTR szFilter = "GIF\0*.gif\0\0";
	szFile[0] = '\0';
	ofn.lStructSize = sizeof(OPENFILENAME);
	ofn.hwndOwner = m_hWnd;
	ofn.lpstrFilter = szFilter;
	ofn.lpstrCustomFilter = (LPSTR) NULL;
	ofn.nMaxCustFilter = 0;
	ofn.nFilterIndex = 1;
	ofn.lpstrFile = szFile;
	ofn.nMaxFile = sizeof(szFile);
	ofn.lpstrFileTitle = szFileTitle;
	ofn.nMaxFileTitle = sizeof(szFileTitle);
	ofn.lpstrInitialDir = NULL; // lpDefPath;
	ofn.lpstrTitle = NULL;
	ofn.Flags = OFN_OVERWRITEPROMPT; 
	ofn.nFileOffset = 0;
	ofn.nFileExtension = 0;
	ofn.lpstrDefExt = "GIF";
	ofn.lpfnHook = NULL;
	if (GetSaveFileName( &ofn ))
	{
		
		TMyGifAnimation *PG = (TMyGifAnimation*) GifList[0];
		SaveCurrentFrame = true;

		if (My_an_wtgiffiledib)
			My_an_wtgiffiledib(ofn.lpstrFile, 
							   (short)GifList.Size()-1,
                               PG->ScreenWidth,
                               PG->ScreenHeight,
                               (short)PG->BackGroundColor,
                               GetDIBBitPerPixel(PG->HDib),
                               0,
                               PG->NetLoops,
							   savegifcallapp,
							   (long) this,
							   "unilzw",
							   0);
								
		SaveCurrentFrame = false;

	}
	
}

void CWebImgView::OnFileOpenpng() 
{
	OnStopanimation();
  	OPENFILENAME ofn;
	char szFile[256], szFileTitle[256];
	LPSTR szFilter = "All suported file formats (PNG,JPG,BMP)\0*.png;*.jpg;*.bmp\0PNG\0\*.png\0JPG\0\*.jpg\0BMP\0\*.bmp\0\0";
	szFile[0] = '\0';
	ofn.lStructSize = sizeof(OPENFILENAME);
	ofn.hwndOwner = m_hWnd;
	ofn.lpstrFilter = szFilter;
	ofn.lpstrCustomFilter = (LPSTR) NULL;
	ofn.nMaxCustFilter = 0;
	ofn.nFilterIndex = 1;
	ofn.lpstrFile = szFile;
	ofn.nMaxFile = sizeof(szFile);
	ofn.lpstrFileTitle = szFileTitle;
	ofn.nMaxFileTitle = sizeof(szFileTitle);
	ofn.lpstrInitialDir = NULL; // lpDefPath;
	ofn.lpstrTitle = NULL;
	ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST; 
	ofn.nFileOffset = 0;
	ofn.nFileExtension = 0;
	ofn.lpstrDefExt = NULL;
	ofn.lpfnHook = NULL;
	
	if (GetOpenFileName( &ofn ))
	{
    	ClearList();
		CurrentFrameItem = 1;
		LoadTimerSet=false;
		LoadingImage=false;
		CancelLoadImage=1;
		InTimer = false;
		FirstFileDrawing = true;
		InvalidateRect(NULL, false);
		
		
		char * DotPosition = 0;
		short FileNameLen;
		short ExtensionLen;
		char * FileExt;
		DotPosition = strrchr(ofn.lpstrFile, '.');

		if (DotPosition <= 0) 
			return;		
		FileNameLen = strlen(ofn.lpstrFile);
		Extens

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -