Buggy code:
OS . DeleteObject ( memDib ) ; } OS . SelectObject ( srcHdc , oldSrcBitmap ) ; OS . DeleteDC ( srcHdc ) ; return ; } Rectangle rect = getClipping ( ) ; rect = rect . intersection ( new Rectangle ( destX , destY , destWidth , destHeight ) ) ; if ( rect . isEmpty ( ) ) return ; int sx1 = srcX + ( ( ( ( rect . x ) - destX ) * srcWidth ) // destWidth ) ; int sx2 = srcX + ( ( ( ( ( rect . x ) + ( rect . width ) ) - destX ) * srcWidth ) // destWidth ) ; int sy1 = srcY + ( ( ( ( rect . y ) - destY ) * srcHeight ) // destHeight ) ; int sy2 = srcY + ( ( ( ( ( rect . y ) + ( rect . height ) ) - destY ) * srcHeight ) // destHeight ) ; destX = rect . x ; destY = rect . y ; destWidth = rect . width ; destHeight = rect . height ; srcX = sx1 ; srcY = sy1 ; srcWidth = Math . max ( 1 , ( sx2 - sx1 ) ) ; srcHeight = Math . max ( 1 , ( sy2 - sy1 ) ) ; int srcHdc = OS . CreateCompatibleDC ( handle ) ; int oldSrcBitmap = OS . SelectObject ( srcHdc , srcImage . handle ) ; int memHdc = OS . CreateCompatibleDC ( handle ) ; int memDib = Image . createDIB ( Math . max ( srcWidth , destWidth ) , Math . max ( srcHeight , destHeight ) , 32 ) ; if ( memDib == 0 ) SWT . error ( ERROR_NO_HANDLES ) ; int oldMemBitmap = OS . SelectObject ( memHdc , memDib ) ; BITMAP dibBM = new BITMAP ( ) ; OS . GetObject ( memDib , sizeof , dibBM ) ; int sizeInBytes = ( dibBM . bmWidthBytes ) * ( dibBM . bmHeight ) ; OS . BitBlt ( memHdc , 0 , 0 , destWidth , destHeight , handle , destX , destY , SRCCOPY ) ; byte [ ] destData = new byte [ sizeInBytes ] ; OS . MoveMemory ( destData , dibBM . bmBits , sizeInBytes ) ; OS . BitBlt ( memHdc , 0 , 0 , srcWidth , srcHeight , srcHdc , srcX , srcY , SRCCOPY ) ; byte [ ] srcData = new byte [ sizeInBytes ] ; OS . MoveMemory ( srcData , dibBM . bmBits , sizeInBytes ) ; int alpha = srcImage . alpha ; final boolean hasAlphaChannel = ( srcImage . alpha ) == ( - 1 ) ; if ( hasAlphaChannel ) { final int apinc = imgWidth - srcWidth ; final int spinc = ( dibBM . bmWidthBytes ) - ( srcWidth * 4 ) ; int ap = ( srcY * imgWidth ) + srcX ; int sp = 3 ; byte [ ] alphaData = srcImage . alphaData ; for ( int y = 0 ; y < srcHeight ; ++ y ) { for ( int x = 0 ; x < srcWidth ; ++ x ) { srcData [ sp ] = alphaData [ ( ap ++ ) ] ; sp += 4 ; } ap += apinc ; sp += spinc ; } } OS . MoveMemory ( dibBM . bmBits , srcData , sizeInBytes ) ; <START_BUG> if ( ( isPrinter || ( ( OS . IsWinCE ) && ( ( destWidth > srcWidth ) || ( destHeight > srcHeight ) ) ) ) || ( ( ! ( OS . IsWinNT ) ) && ( ! ( OS . IsWinCE ) ) ) ) { <END_BUG> int tempHdc = OS . CreateCompatibleDC ( handle ) ; int tempDib = Image . createDIB ( destWidth , destHeight , 32 ) ; if ( tempDib == 0 ) SWT . error ( ERROR_NO_HANDLES ) ; int oldTempBitmap = OS . SelectObject ( tempHdc , tempDib ) ; if ( ( ! simple ) && ( ( srcWidth != destWidth ) || ( srcHeight != destHeight ) ) ) { if ( ! ( OS . IsWinCE ) ) OS . SetStretchBltMode ( memHdc , COLORONCOLOR ) ; OS . StretchBlt ( tempHdc , 0 , 0 , destWidth , destHeight , memHdc , 0 , 0 , srcWidth , srcHeight , SRCCOPY ) ; } else { OS . BitBlt ( tempHdc , 0 , 0 , destWidth , destHeight , memHdc , 0 , 0 , SRCCOPY ) ; } OS . BitBlt ( memHdc , 0 , 0 , destWidth , destHeight , tempHdc , 0 , 0 , SRCCOPY ) ; OS . SelectObject ( tempHdc , oldTempBitmap ) ; OS . DeleteObject ( tempDib ) ; OS . DeleteDC ( tempHdc ) ; } else { if ( ( ! simple ) && ( ( srcWidth != destWidth ) || ( srcHeight != destHeight ) ) ) { if ( ! ( OS . IsWinCE ) ) OS . SetStretchBltMode ( memHdc , COLORONCOLOR ) ; OS . StretchBlt ( memHdc , 0 , 0 , destWidth , destHeight , memHdc , 0 , 0 , srcWidth , srcHeight , SRCCOPY ) ; } else { OS . BitBlt ( memHdc , 0 , 0 , destWidth , destHeight , memHdc , 0 , 0 , SRCCOPY ) ; } } OS . MoveMemory ( srcData , dibBM . bmBits , sizeInBytes ) ; final int dpinc = ( dibBM . bmWidthBytes ) - ( destWidth * 4 ) ; int dp = 0 ; for ( int y = 0 ; y < destHeight ; ++ y ) { for ( int x = 0 ; x < destWidth ;

Fix:
if ( ( ( ( OS . IsWinCE ) && ( ( destWidth > srcWidth ) || ( destHeight > srcHeight ) ) ) || ( ( ! ( OS . IsWinNT ) ) && ( ! ( OS . IsWinCE ) ) ) ) || isPrinter ) {