StretchBlt failure on Win98 
Author Message
 StretchBlt failure on Win98

The following function copies a picture (bitmap) into a VB.PictureBox. Works
fine on Win2K. Fails (StretchBlt=0) on Win98 when stretching or compressing
operation is requested: why? Thanks for your time.

Sub StretchPicture( _
                        ByVal HDcTarget As Long, _
                        ByRef Pic As stdOle.IPictureDisp, _
                        ByVal PixelsLeft As Long, _
                        ByVal PixelsTop As Long, _
                        ByVal DestWidth As Long, _
                        ByVal DestHeight As Long)

Dim lMemDC As Long
Dim lOldBmp As Long
Dim lDestWidth As Long
Dim lDestHeight As Long
Const TWIPSPERINCH As Long = 1440

    'Create a compatible DC for the bit block transfer
    lMemDC = CreateCompatibleDC(ByVal 0&)

    'If success
    If (lMemDC <> 0) Then

        'Select the bitmap into the DC
        lOldBmp = SelectObject(lMemDC, Pic)

        'If a horizontal strectch/compression is requested
        If (DestWidth <> 0) Then
            '(1440 / GetDeviceCaps(lMemDC, LOGPIXELSX) =
Screen.TwipsPerPixelX)
            lDestWidth = _
                DestWidth * TWIPSPERINCH / GetDeviceCaps(lMemDC, LOGPIXELSX)
        Else
            lDestWidth = Pic.Width
        End If

        'If a vertical strectch/compression is requested
        If (DestHeight <> 0) Then
            '(1440 / GetDeviceCaps(lMemDC, LOGPIXELSY) =
Screen.TwipsPerPixelY)
            lDestHeight = _
                DestHeight * TWIPSPERINCH / GetDeviceCaps(lMemDC,
LOGPIXELSY)
        Else
            lDestHeight = Pic.Height
        End If

        'Use StretchBlt to transfer the bitmap
        Call StretchBlt( _
                    hdc:=HDcTarget, _
                    x:=PixelsLeft, _
                    y:=PixelsTop, _
                    nWidth:=lDestWidth, _
                    nHeight:=lDestHeight, _
                    hSrcDC:=lMemDC, _
                    xSrc:=0, _
                    ySrc:=0, _
                    nSrcWidth:=Pic.Width, _
                    nSrcHeight:=Pic.Height, _
                    dwRop:=SRCCOPY)

        'Reselect the original bitmap
        Call SelectObject(lMemDC, lOldBmp)

        'Delete the compatible DC
        Call DeleteDC(lMemDC)

    End If

End Sub



Mon, 02 May 2005 18:03:08 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. GetMenuItemInfo failure on Win98 SE

2. Making a working StretchBlt?

3. Using StretchBlt with my own UserControl

4. StretchBlt help..

5. bitblt / stretchblt picture distortion

6. StretchBlt and Voodoo3 problem?

7. StretchBlt API

8. StretchBlt() and PictureBox

9. Using StretchBlt to capture screen image to screen saver preview pane

10. BitBlt & StretchBlt

11. StretchBlt Question

12. Need serious Stretchblt help!

 

 
Powered by phpBB® Forum Software