#if CXIMAGE_SUPPORT_WINDOWS
HBITMAP MakeBitmap(HDC hdc = NULL);
HANDLE CopyToHandle();
bool CreateFromHANDLE(HANDLE hMem); //Windows objects (clipboard)
bool CreateFromHBITMAP(HBITMAP hbmp, HPALETTE hpal=0); //Windows resource
bool CreateFromHICON(HICON hico);
long Draw(HDC hdc, long x=0, long y=0, long cx = -1, long cy = -1, RECT* pClipRect = 0, bool bSmooth = false);
long Draw(HDC hdc, const RECT& rect, RECT* pClipRect=NULL, bool bSmooth = false);
我要的就是long Draw(HDC hdc, const RECT& rect, RECT* pClipRect=NULL, bool bSmooth = false);
的实现代码,从网上下载的Cximg6.0找不到,谁能发给我,谢谢各位!我是新手!

解决方案 »

  1.   

    long CxImage::Draw(HDC hdc, const RECT& rect, RECT* pClipRect, bool bSmooth)
    {
    return Draw(hdc, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, pClipRect,bSmooth);
    }
    long CxImage::Draw(HDC hdc, long x, long y, long cx, long cy, RECT* pClipRect, bool bSmooth)
    {
    if((pDib==0)||(hdc==0)||(cx==0)||(cy==0)||(!info.bEnabled)) return 0; if (cx < 0) cx = head.biWidth;
    if (cy < 0) cy = head.biHeight;
    bool bTransparent = info.nBkgndIndex >= 0;
    bool bAlpha = pAlpha != 0; //required for MM_ANISOTROPIC, MM_HIENGLISH, and similar modes [Greg Peatfield]
    int hdc_Restore = ::SaveDC(hdc);
    if (!hdc_Restore) 
    return 0;#if !defined (_WIN32_WCE)
    RECT mainbox; // (experimental) 
    if (pClipRect){
    GetClipBox(hdc,&mainbox);
    HRGN rgn = CreateRectRgnIndirect(pClipRect);
    ExtSelectClipRgn(hdc,rgn,RGN_AND);
    DeleteObject(rgn);
    }
    #endif //find the smallest area to paint
    RECT clipbox,paintbox;
    GetClipBox(hdc,&clipbox); paintbox.top = min(clipbox.bottom,max(clipbox.top,y));
    paintbox.left = min(clipbox.right,max(clipbox.left,x));
    paintbox.right = max(clipbox.left,min(clipbox.right,x+cx));
    paintbox.bottom = max(clipbox.top,min(clipbox.bottom,y+cy)); long destw = paintbox.right - paintbox.left;
    long desth = paintbox.bottom - paintbox.top; if (!(bTransparent || bAlpha || info.bAlphaPaletteEnabled)){
    if (cx==head.biWidth && cy==head.biHeight){ //NORMAL
    #if !defined (_WIN32_WCE)
    SetStretchBltMode(hdc,COLORONCOLOR);
    #endif
    SetDIBitsToDevice(hdc, x, y, cx, cy, 0, 0, 0, cy,
    info.pImage,(BITMAPINFO*)pDib,DIB_RGB_COLORS);
    } else { //STRETCH
    //pixel informations
    RGBQUAD c={0,0,0,0};
    //Preparing Bitmap Info
    BITMAPINFO bmInfo;
    memset(&bmInfo.bmiHeader,0,sizeof(BITMAPINFOHEADER));
    bmInfo.bmiHeader.biSize=sizeof(BITMAPINFOHEADER);
    bmInfo.bmiHeader.biWidth=destw;
    bmInfo.bmiHeader.biHeight=desth;
    bmInfo.bmiHeader.biPlanes=1;
    bmInfo.bmiHeader.biBitCount=24;
    BYTE *pbase; //points to the final dib
    BYTE *pdst; //current pixel from pbase
    BYTE *ppix; //current pixel from image
    //get the background
    HDC TmpDC=CreateCompatibleDC(hdc);
    HBITMAP TmpBmp=CreateDIBSection(hdc,&bmInfo,DIB_RGB_COLORS,(void**)&pbase,0,0);
    HGDIOBJ TmpObj=SelectObject(TmpDC,TmpBmp); if (pbase){
    long xx,yy;
    long sx,sy;
    float dx,dy;
    BYTE *psrc; long ew = ((((24 * destw) + 31) / 32) * 4);
    long ymax = paintbox.bottom;
    long xmin = paintbox.left;
    float fx=(float)head.biWidth/(float)cx;
    float fy=(float)head.biHeight/(float)cy; for(yy=0;yy<desth;yy++){
    dy = head.biHeight-(ymax-yy-y)*fy;
    sy = max(0L,(long)floor(dy));
    psrc = info.pImage+sy*info.dwEffWidth;
    pdst = pbase+yy*ew;
    for(xx=0;xx<destw;xx++){
    dx = (xx+xmin-x)*fx;
    sx = max(0L,(long)floor(dx));
    #if CXIMAGE_SUPPORT_INTERPOLATION
    if (bSmooth){
    if (fx > 1 && fy > 1) { 
    c = GetAreaColorInterpolated(dx - 0.5f, dy - 0.5f, fx, fy, CxImage::IM_BILINEAR, CxImage::OM_REPEAT); 
    } else { 
    c = GetPixelColorInterpolated(dx - 0.5f, dy - 0.5f, CxImage::IM_BILINEAR, CxImage::OM_REPEAT); 

    } else
    #endif //CXIMAGE_SUPPORT_INTERPOLATION
    {
    if (head.biClrUsed){
    c=GetPaletteColor(GetPixelIndex(sx,sy));
    } else {
    ppix = psrc + sx*3;
    c.rgbBlue = *ppix++;
    c.rgbGreen= *ppix++;
    c.rgbRed  = *ppix;
    }
    }
    *pdst++=c.rgbBlue;
    *pdst++=c.rgbGreen;
    *pdst++=c.rgbRed;
    }
    }
    }
    //paint the image & cleanup
    SetDIBitsToDevice(hdc,paintbox.left,paintbox.top,destw,desth,0,0,0,desth,pbase,&bmInfo,0);
    DeleteObject(SelectObject(TmpDC,TmpObj));
    DeleteDC(TmpDC);
    }
    } else { // draw image with transparent/alpha blending
    //////////////////////////////////////////////////////////////////
    //Alpha blend - Thanks to Florian Egel //pixel informations
    RGBQUAD c={0,0,0,0};
    RGBQUAD ct = GetTransColor();
    long* pc = (long*)&c;
    long* pct= (long*)&ct;
    long cit = GetTransIndex();
    long ci = 0; //Preparing Bitmap Info
    BITMAPINFO bmInfo;
    memset(&bmInfo.bmiHeader,0,sizeof(BITMAPINFOHEADER));
    bmInfo.bmiHeader.biSize=sizeof(BITMAPINFOHEADER);
    bmInfo.bmiHeader.biWidth=destw;
    bmInfo.bmiHeader.biHeight=desth;
    bmInfo.bmiHeader.biPlanes=1;
    bmInfo.bmiHeader.biBitCount=24; BYTE *pbase; //points to the final dib
    BYTE *pdst; //current pixel from pbase
    BYTE *ppix; //current pixel from image //get the background
    HDC TmpDC=CreateCompatibleDC(hdc);
    HBITMAP TmpBmp=CreateDIBSection(hdc,&bmInfo,DIB_RGB_COLORS,(void**)&pbase,0,0);
    HGDIOBJ TmpObj=SelectObject(TmpDC,TmpBmp);
    BitBlt(TmpDC,0,0,destw,desth,hdc,paintbox.left,paintbox.top,SRCCOPY); if (pbase){
    long xx,yy,alphaoffset,ix,iy;
    BYTE a,a1,*psrc;
    long ew = ((((24 * destw) + 31) / 32) * 4);
    long ymax = paintbox.bottom;
    long xmin = paintbox.left; if (cx!=head.biWidth || cy!=head.biHeight){
    //STRETCH
    float fx=(float)head.biWidth/(float)cx;
    float fy=(float)head.biHeight/(float)cy;
    float dx,dy;
    long sx,sy;

    for(yy=0;yy<desth;yy++){
    dy = head.biHeight-(ymax-yy-y)*fy;
    sy = max(0L,(long)floor(dy)); alphaoffset = sy*head.biWidth;
    pdst = pbase + yy*ew;
    psrc = info.pImage + sy*info.dwEffWidth; for(xx=0;xx<destw;xx++){
    dx = (xx+xmin-x)*fx;
    sx = max(0L,(long)floor(dx)); if (bAlpha) a=pAlpha[alphaoffset+sx]; else a=255;
    a =(BYTE)((a*(1+info.nAlphaMax))>>8); if (head.biClrUsed){
    ci = GetPixelIndex(sx,sy);
    #if CXIMAGE_SUPPORT_INTERPOLATION
    if (bSmooth){
    if (fx > 1 && fy > 1) { 
    c = GetAreaColorInterpolated(dx - 0.5f, dy - 0.5f, fx, fy, CxImage::IM_BILINEAR, CxImage::OM_REPEAT); 
    } else { 
    c = GetPixelColorInterpolated(dx - 0.5f, dy - 0.5f, CxImage::IM_BILINEAR, CxImage::OM_REPEAT); 

    } else
    #endif //CXIMAGE_SUPPORT_INTERPOLATION
    {
    c = GetPaletteColor(GetPixelIndex(sx,sy));
    }
    if (info.bAlphaPaletteEnabled){
    a = (BYTE)((a*(1+c.rgbReserved))>>8);
    }
    } else {
    #if CXIMAGE_SUPPORT_INTERPOLATION
    if (bSmooth){
    if (fx > 1 && fy > 1) { 
    c = GetAreaColorInterpolated(dx - 0.5f, dy - 0.5f, fx, fy, CxImage::IM_BILINEAR, CxImage::OM_REPEAT); 
    } else { 
    c = GetPixelColorInterpolated(dx - 0.5f, dy - 0.5f, CxImage::IM_BILINEAR, CxImage::OM_REPEAT); 

    } else
    #endif //CXIMAGE_SUPPORT_INTERPOLATION
    {
    ppix = psrc + sx*3;
    c.rgbBlue = *ppix++;
    c.rgbGreen= *ppix++;
    c.rgbRed  = *ppix;
    }
    }
    //if (*pc!=*pct || !bTransparent){
    //if ((head.biClrUsed && ci!=cit) || ((!head.biClrUsed||bSmooth) && *pc!=*pct) || !bTransparent){
    if ((head.biClrUsed && ci!=cit) || (!head.biClrUsed && *pc!=*pct) || !bTransparent){
    // DJT, assume many pixels are fully transparent or opaque and thus avoid multiplication
    if (a == 0) { // Transparent, retain dest 
    pdst+=3; 
    } else if (a == 255) { // opaque, ignore dest 
    *pdst++= c.rgbBlue; 
    *pdst++= c.rgbGreen; 
    *pdst++= c.rgbRed; 
    } else { // semi transparent 
    a1=(BYTE)~a;
    *pdst++=(BYTE)((*pdst * a1 + a * c.rgbBlue)>>8); 
    *pdst++=(BYTE)((*pdst * a1 + a * c.rgbGreen)>>8); 
    *pdst++=(BYTE)((*pdst * a1 + a * c.rgbRed)>>8); 

    } else {
    pdst+=3;
    }
    }
    }
    } else {
    //NORMAL
    iy=head.biHeight-ymax+y;
    for(yy=0;yy<desth;yy++,iy++){
    alphaoffset=iy*head.biWidth;
    ix=xmin-x;
    pdst=pbase+yy*ew;
    ppix=info.pImage+iy*info.dwEffWidth+ix*3;
    for(xx=0;xx<destw;xx++,ix++){ if (bAlpha) a=pAlpha[alphaoffset+ix]; else a=255;
    a = (BYTE)((a*(1+info.nAlphaMax))>>8); if (head.biClrUsed){
    ci = GetPixelIndex(ix,iy);
    c = GetPaletteColor((BYTE)ci);
    if (info.bAlphaPaletteEnabled){
    a = (BYTE)((a*(1+c.rgbReserved))>>8);
    }
    } else {
    c.rgbBlue = *ppix++;
    c.rgbGreen= *ppix++;
    c.rgbRed  = *ppix++;
    } //if (*pc!=*pct || !bTransparent){
    if ((head.biClrUsed && ci!=cit) || (!head.biClrUsed && *pc!=*pct) || !bTransparent){
    // DJT, assume many pixels are fully transparent or opaque and thus avoid multiplication
    if (a == 0) { // Transparent, retain dest 
    pdst+=3; 
    } else if (a == 255) { // opaque, ignore dest 
    *pdst++= c.rgbBlue; 
    *pdst++= c.rgbGreen; 
    *pdst++= c.rgbRed; 
    } else { // semi transparent 
    a1=(BYTE)~a;
    *pdst++=(BYTE)((*pdst * a1 + a * c.rgbBlue)>>8); 
    *pdst++=(BYTE)((*pdst * a1 + a * c.rgbGreen)>>8); 
    *pdst++=(BYTE)((*pdst * a1 + a * c.rgbRed)>>8); 

    } else {
    pdst+=3;
    }
    }
    }
    }
    }
    //paint the image & cleanup
    SetDIBitsToDevice(hdc,paintbox.left,paintbox.top,destw,desth,0,0,0,desth,pbase,&bmInfo,0);
    DeleteObject(SelectObject(TmpDC,TmpObj));
    DeleteDC(TmpDC);
    }#if !defined (_WIN32_WCE)
    if (pClipRect){  // (experimental)
    HRGN rgn = CreateRectRgnIndirect(&mainbox);
    ExtSelectClipRgn(hdc,rgn,RGN_OR);
    DeleteObject(rgn);
    }
    #endif ::RestoreDC(hdc,hdc_Restore);
    return 1;
    }
      

  2.   

    CXimage源码与demo下载
    http://www.codeproject.com/KB/graphics/cximage.aspx