BOOL StretchBlt( int x, int y, int nWidth, int nHeight, CDC* pSrcDC, int xSrc, int ySrc, int nSrcWidth, int nSrcHeight, DWORD dwRop );//再看看MSDN,很详细..
BOOL StretchBlt( HDC hdcDest, // handle of destination device context int nXOriginDest, // x-coordinate of upper-left corner of dest. rect. int nYOriginDest, // y-coordinate of upper-left corner of dest. rect. int nWidthDest, // width of destination rectangle int nHeightDest, // height of destination rectangle HDC hdcSrc, // handle of source device context int nXOriginSrc, // x-coordinate of upper-left corner of source rectangle int nYOriginSrc, // y-coordinate of upper-left corner of source rectangle int nWidthSrc, // width of source rectangle int nHeightSrc, // height of source rectangle DWORD dwRop // raster operation code ); ParametershdcDestIdentifies the destination device context. nXOriginDestSpecifies the x-coordinate, in logical units, of the upper-left corner of the destination rectangle. nYOriginDestSpecifies the y-coordinate, in logical units, of the upper-left corner of the destination rectangle. nWidthDestSpecifies the width, in logical units, of the destination rectangle. nHeightDestSpecifies the height, in logical units, of the destination rectangle. hdcSrcIdentifies the source device context. nXOriginSrcSpecifies the x-coordinate, in logical units, of the upper-left corner of the source rectangle. nYOriginSrcSpecifies the y-coordinate, in logical units, of the upper-left corner of the source rectangle. nWidthSrcSpecifies the width, in logical units, of the source rectangle. nHeightSrcSpecifies the height, in logical units, of the source rectangle. dwRopSpecifies the raster operation to be performed. Raster operation codes define how Windows combines colors in output operations that involve a brush, a source bitmap, and a destination bitmap.
int nXOriginDest, // x-coordinate of upper-left corner of dest. rect.
int nYOriginDest, // y-coordinate of upper-left corner of dest. rect.
int nWidthDest, // width of destination rectangle
int nHeightDest, // height of destination rectangle
HDC hdcSrc, // handle of source device context
int nXOriginSrc, // x-coordinate of upper-left corner of source rectangle
int nYOriginSrc, // y-coordinate of upper-left corner of source rectangle
int nWidthSrc, // width of source rectangle
int nHeightSrc, // height of source rectangle
DWORD dwRop // raster operation code
);
ParametershdcDestIdentifies the destination device context. nXOriginDestSpecifies the x-coordinate, in logical units, of the upper-left corner of the destination rectangle. nYOriginDestSpecifies the y-coordinate, in logical units, of the upper-left corner of the destination rectangle. nWidthDestSpecifies the width, in logical units, of the destination rectangle. nHeightDestSpecifies the height, in logical units, of the destination rectangle. hdcSrcIdentifies the source device context. nXOriginSrcSpecifies the x-coordinate, in logical units, of the upper-left corner of the source rectangle. nYOriginSrcSpecifies the y-coordinate, in logical units, of the upper-left corner of the source rectangle. nWidthSrcSpecifies the width, in logical units, of the source rectangle. nHeightSrcSpecifies the height, in logical units, of the source rectangle. dwRopSpecifies the raster operation to be performed. Raster operation codes define how Windows combines colors in output operations that involve a brush, a source bitmap, and a destination bitmap.
如果失真比较严重,你可以找几个专业的图形库来试试
{
CBitmap mBitmap; //定义一个位图类
CDC MemDC;
BITMAP bm;
double fX,fY,viewX,viewY; CRect Rect;
int x=0, y=0;
HBITMAP hImage = (HBITMAP)LoadImage(NULL, strPath, IMAGE_BITMAP,
0, 0, LR_LOADFROMFILE|LR_CREATEDIBSECTION|LR_DEFAULTSIZE); mBitmap.Attach(hImage); //装入位图对象 GetClientRect (&Rect); //获取客户区大小
viewY = Rect.Height();
viewX = Rect.Width(); mBitmap.GetObject (sizeof (BITMAP), &bm); //用位图上的信息 填充BITMAP结构的各个域
MemDC.CreateCompatibleDC (pDC); //初始化内存描述对象
CBitmap*pOldBitmap=MemDC.SelectObject (&mBitmap); //定 义一个CBITMAP类,并初始化为选入到设备描述对象的位图 //x= (Rect.Width()-bm.bmWidth) /2; //位图左上角横坐标 //y= (Rect.Height()-bm.bmHeight) /2; //位图左上角纵坐标 /*pDC->BitBlt (x, //目标位图横坐标 y, //目标位图纵坐标 bm.bmWidth, //要转换的块高度 bm.bmHeight, //要转换的块宽度 &MemDC, //图形数据的源设备对象 0, //源位图横坐标 0, //源位图纵坐标 SRCCOPY); //转换类型代码,SRCCOPY 表示数据不经修改直接拷贝
return TRUE;*/
//平铺图形
fX = bm.bmWidth;
fY = bm.bmHeight;
if (fX>fY)
{
if(fX>viewX)
{
fY = fY/fX*viewX;
fX = viewX;
}
x = (int)(Rect.Width()-fX) /2; //位图左上角横坐标
y = (int)(Rect.Height()-fY) /2; //位图左上角纵坐标
}
else
{
if(fY>viewY)
{
fX = fX/fY*viewY;
fY = viewY;
}
x = (int)(Rect.Width()-fX) /2; //位图左上角横坐标
y = (int)(Rect.Height()-fY) /2; //位图左上角纵坐标
}
SetStretchBltMode(pDC->m_hDC , STRETCH_HALFTONE);
pDC->StretchBlt( x, y, (int)fX, (int)fY, &MemDC, 0, 0, bm.bmWidth, bm.bmHeight, SRCCOPY|MERGECOPY );
MemDC.SelectObject ( pOldBitmap ); //将位图对象选入 内存 设备描述对象 return TRUE;
}