我编写了一个MFC应用(单文档)想实现在客户区显示的图片(.jpg或者.tiff格式)的旋转 但不想使用GDI+ 我编写了如下代码 但不知如何继续
double sinx = sin (3.1415926536*90/180.0);
double cosx = cos (3.1415926536*90/180.0);
DWORD neww=hmHeight*sinx+hmWidth*cosx+1.0;
DWORD newh=hmHeight*cosx+hmWidth*sinx+1.0;
poi[0].x=hmHeight*sinx;
poi[1].x=min(neww-1,hmHeight*sinx+hmWidth*cosx);
poi[1].y=hmWidth*sinx;
poi[2].y=hmHeight*cosx;
其中hmHeight是图片的高 hmWidth为图片的宽 望高手指点如何将代码加入显示函数 使图片实现旋转
double sinx = sin (3.1415926536*90/180.0);
double cosx = cos (3.1415926536*90/180.0);
DWORD neww=hmHeight*sinx+hmWidth*cosx+1.0;
DWORD newh=hmHeight*cosx+hmWidth*sinx+1.0;
poi[0].x=hmHeight*sinx;
poi[1].x=min(neww-1,hmHeight*sinx+hmWidth*cosx);
poi[1].y=hmWidth*sinx;
poi[2].y=hmHeight*cosx;
其中hmHeight是图片的高 hmWidth为图片的宽 望高手指点如何将代码加入显示函数 使图片实现旋转
int Rotation(LPBITMAPINFOHEADER lpBi, LPVOID lpBmpData)
{
// 源图片的size信息
int nSrcImgWidth = abs(lpBi->biWidth);// 图片的宽度(象素为单位)
int nSrcImgHeight = abs(lpBi->biHeight);// 图片的高度(象素为单位)
// 源图片一行所占用的字节数
int nSrcLineBytes= (DWORD)WIDTHBYTES(nSrcImgWidth * lpBi->biBitCount); // 注意四字节对齐
// 获取图片使用颜色数
DWORD dwSrcNumColors;
int nLen = 1;
if (lpBi->biClrUsed != 0)
{
dwSrcNumColors = (DWORD)lpBi->biClrUsed;
}
else
{
switch (lpBi->biBitCount)
{
case 1:
dwSrcNumColors = 2;
break;
case 4:
dwSrcNumColors = 16;
break;
case 8:
dwSrcNumColors = 256;
break;
case 24:
dwSrcNumColors = 0;
break;
default:
return -1;
}
}
// 获取旋转90后的图像实际尺寸
int nDstImgWidth =(LONG) nSrcImgHeight;
int nDstImgHeight = (LONG) nSrcImgWidth;
// 更新图片的尺寸
lpBi->biWidth = nDstImgWidth;
lpBi->biHeight = nDstImgHeight;
// 计算新图像每行的字节数
int nDstLineBytes = (DWORD)WIDTHBYTES(nDstImgWidth * lpBi->biBitCount);
// 更新图片数据
int nDstImgDataSize = (DWORD)nDstLineBytes*nDstImgHeight;
HGLOBAL hDstImgData = LocalAlloc(LHND, nDstImgDataSize);
if (hDstImgData == NULL)
{
return -1;
}
LPVOID lpDstImgData = LocalLock(hDstImgData);
char *pSrcData = NULL;
char *pDstData = NULL;
DWORD i0 = 0;
DWORD j0 = 0;
for(DWORD i=0; i<(DWORD)nDstImgWidth; i++)
{
for (DWORD j=0; j<(DWORD)nDstImgHeight; j++)
{
// 计算该象素在源DIB中的坐标
i0 = (LONG) j;
j0 = (LONG) i;
pDstData = (char *)lpDstImgData + (nDstImgDataSize - nDstLineBytes - j*nDstLineBytes) + i*(lpBi->biBitCount/8);
if ( (j0 >= 0) && (j0 <= nSrcImgHeight)
&& (i0 >= 0) && (i0 <= nSrcImgWidth))
{
pSrcData = (char *)lpBmpData + (nDstImgDataSize-nSrcLineBytes-j0*nSrcLineBytes) + i0*(lpBi->biBitCount/8);
memcpy(pDstData, pSrcData, lpBi->biBitCount/8);
}
else
{
// 对于源图中没有的象素,直接赋值为255
memset(pDstData, 255, lpBi->biBitCount/8);
}
}
}
memcpy(lpBmpData, lpDstImgData, nDstImgDataSize);
LocalUnlock(lpDstImgData);
LocalFree(lpDstImgData);
lpDstImgData = NULL;
return 0;
}
double sinx = sin (3.1415926536*90/180.0);
double cosx = cos (3.1415926536*90/180.0);
DWORD neww=hmHeight*sinx+hmWidth*cosx+1.0;
DWORD newh=hmHeight*cosx+hmWidth*sinx+1.0;
poi[0].x=hmHeight*sinx;
poi[1].x=min(neww-1,hmHeight*sinx+hmWidth*cosx);
poi[1].y=hmWidth*sinx;
poi[2].y=hmHeight*cosx;
其中hmHeight是图片的高 hmWidth为图片的宽
我的显示函数是:
Render(*pDC,rc.left,rc.top,rc.Width()+tempX,rc.Height()+tempY,0,hmHeight,hmWidth,-hmHeight,NULL)
我想显示一幅.jpg格式的图片 应如何将旋转后的坐标加入我的显示函数达到旋转的效果呢?