long DrawImage( HDC bd, B_Rect *src, B_Rect *dst, PImg pImg)
{
}其中B_Rect的定义如下
typedef struct {
long x;
long y;
long w;//width
long h;//height
} B_Rect;PImg 的定义如下:typedef  struct ImgStruct {
int w;//width
int h;//height
int bpps;//位深
void * data;//句柄
}Img, *PImg;

解决方案 »

  1.   

    下面代码应该可以用,可以多加一些注释和检查:long DrawImage(HDC bd, B_Rect *src, B_Rect *dst, PImg pImg)
    {
        HDC     hdcDest = bd;
        HDC     hdcMem;
        HBITMAP hBitmap;
      
        int     nWidth  = pImg->w;
        int     nHeight = pImg->h;
        int     nBits   = pImg->bpps;
        BYTE*   pBits   = (BYTE*)pImg->data;        // 检查参数
        if(hdcSrc == NULL || src  == NULL || 
           dst    == NULL || pImg == NULL)
        {
            return -1L;
        }    hdcMem  = CreateCompatibleDC(hSrcDC);
        hBitmap = CreateBitmap(nWidth, nHeight, 1, nBits, pBits);    SelectObject(hdcMem, hBitmap);
        StretchBlt(hdcDest, dst->x, dst->y, dst->w, dst->h,
                   hdcMem,  0,      0,      src->w, src->h);    DelectDC(hdcMem);    return 1L;    
    }