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

📄 zoomimage.cpp

📁 一些自己做的关于图象处理的程序(如傅立叶变换
💻 CPP
字号:
// ZoomImage.cpp : implementation file
//

#include "stdafx.h"
#include "photostar.h"
#include "ZoomImage.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CZoomImage dialog


CZoomImage::CZoomImage(CWnd* pParent /*=NULL*/)
	: CDialog(CZoomImage::IDD, pParent)
{
	//{{AFX_DATA_INIT(CZoomImage)
	m_xration = 2.0f;
	m_yration = 2.0f;
	//}}AFX_DATA_INIT
}


void CZoomImage::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CZoomImage)
	DDX_Text(pDX, IDC_FXZOOMRADIO, m_xration);
	DDX_Text(pDX, IDC_FYZOOMRATIO, m_yration);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CZoomImage, CDialog)
	//{{AFX_MSG_MAP(CZoomImage)
	ON_BN_CLICKED(IDOK, OnEnhanceZoomSize)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CZoomImage message handlers





void CZoomImage::OnEnhanceZoomSize() 
{
	UpdateData(TRUE);
	
    CDialog::OnOK();
	
	
	
		
	
}

BOOL CZoomImage::OnZoomImage()
{
    int iWidth = m_pImageObject->GetWidth();
	int iHeight = m_pImageObject->GetHeight();
	
	/******************************the old image*****************************/
	unsigned char *pOldBuffer, *pNewBuffer, *pOldBits, *pNewBits;
	BITMAPFILEHEADER *pOldBFH, *pNewBFH;
	BITMAPINFOHEADER *pOldBIH, *pNewBIH;
	RGBQUAD *pOldPalette, *pNewPalette;
	int nWidthBytes, nNumColors;
	
	pOldBuffer = (unsigned char *) m_pImageObject->GetDIBPointer(&nWidthBytes, m_pImageObject->GetNumBits());

	
	
	pOldBFH = (BITMAPFILEHEADER *) pOldBuffer;
	pOldBIH = (BITMAPINFOHEADER *) &pOldBuffer[sizeof(BITMAPFILEHEADER)];
	nNumColors = m_pImageObject->GetNumColors();
	pOldPalette = (RGBQUAD *)  &pOldBuffer[sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER)];
	pOldBits = (unsigned char *) &pOldBuffer[sizeof(BITMAPFILEHEADER)
		+sizeof(BITMAPINFOHEADER)+nNumColors*sizeof(RGBQUAD)];
	
	/*****************************the new image*****************************/
	DWORD dwNewSize;
	HGLOBAL hNewDib;
	
	//Allocate a global memory block for the new image
	dwNewSize = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) 
		+ nNumColors * sizeof(RGBQUAD)
		+ (int)(nWidthBytes*m_xration+0.5) * (m_pImageObject->GetHeight()*m_yration+0.5);
	hNewDib = ::GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT, dwNewSize);
	if (hNewDib == NULL)
	{
		m_pImageObject->m_nLastError = IMAGELIB_MEMORY_ALLOCATION_ERROR;
		::GlobalUnlock(m_pImageObject->GetDib());
		
	}
	
	//Get the pointer to the new memory block
	pNewBuffer = (unsigned char *) ::GlobalLock(hNewDib);
	if (pNewBuffer == NULL)
	{
		::GlobalFree( hNewDib );
		m_pImageObject->m_nLastError = IMAGELIB_MEMORY_LOCK_ERROR;
		::GlobalUnlock(m_pImageObject->GetDib());
		
	}
    
	
	pNewBFH = (BITMAPFILEHEADER *) pNewBuffer;
	pNewBIH = (BITMAPINFOHEADER *) &pNewBuffer[sizeof(BITMAPFILEHEADER)];
	pNewPalette = (RGBQUAD *) &pNewBuffer[sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER)];
	pNewBits = (unsigned char *) &pNewBuffer[sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER)+nNumColors*sizeof(RGBQUAD)];
	//Make a copy of the old image
	memcpy(pNewBuffer,pOldBuffer,dwNewSize);
	//change the new image size
	pNewBIH->biHeight = (int)(m_pImageObject->GetHeight()*m_yration+0.5);
	while (pOldBIH->biWidth%4 !=0) //更改新图像的宽度信息时应先把旧图像的宽度信息补为4的倍数
	{							   //因为旧图像的nWidthBytes系统已经自动补为4的倍数	
		pOldBIH->biWidth++;
	}
	
	pNewBIH->biWidth = (int)(m_pImageObject->GetWidth()*m_xration+0.5);//可直接用nWidthBytes代替pOldBIH->biWidth
	while (pNewBIH->biWidth%4 !=0) //再把新图像的宽度信息补为4的倍数
	{							   	
		pNewBIH->biWidth++;
	}
	pNewBIH->biSizeImage = pNewBIH->biHeight*pNewBIH->biWidth;
	pNewBFH->bfSize = sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER)+
		nNumColors*sizeof(RGBQUAD)+pNewBIH->biSizeImage;
	
    /*******************************Zoom Image****************************/

	switch(m_pImageObject->GetNumBits())
	{
	case 8:
		int i,j;
		int nNewWidthBytes;
		iNewHeight=int(iHeight*m_yration+0.5);
		iNewWidth=int(iWidth*m_xration+0.5);
		nNewWidthBytes=(int)(nWidthBytes*m_xration+0.5);
		for(i=0;i<iNewHeight;i++)
		{
			for(j=0;j<iNewWidth;j++)
			{
				
				pNewBits[(iNewHeight-1-i)*nNewWidthBytes+j]= pOldBits[(iHeight-1-(int)(i/m_yration+0.5))*nWidthBytes+(int)(j/m_xration+0.5)];
				
			}
		}
		break;
	case 16:
		break;
	}
		
	//Free the memory for the old image
	::GlobalUnlock(m_pImageObject->GetDib());
	::GlobalFree(m_pImageObject->GetDib());
	
	//Update the DIB in the object pointed by m_pImaeObject
	::GlobalUnlock(hNewDib); 
	m_pImageObject->SetDib(hNewDib);
	return TRUE;
		
}

⌨️ 快捷键说明

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