Results 1 to 22 of 22

Thread: cGDIPImageLoader, small class for "universal" image loading

Hybrid View

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2015
    Posts
    324

    Re: cGDIPImageLoader, small class for "universal" image loading

    Final revision of DrawImageToDC function. Leaned to only necessary code.

    Note: This change is already incorporated into the final download version in the original post.


    Code:
    Public Function DrawImageToDC(ByVal nHdc As Long, ByVal nImage As Long, Optional ByVal dX As Single, _
                                  Optional ByVal dY As Single, Optional ByVal dW As Single, _
                                  Optional ByVal dH As Single, Optional ByVal sX As Single, _
                                  Optional ByVal sY As Single, Optional ByVal sW As Single, _
                                  Optional ByVal sH As Single)
    
    '- Draws passed image at specified x, y coordinates
    '- and at specified width & height.
    '- Returns zero if successful.
    
        Dim ImGraphics As Long
        Dim lRet       As Long
    
        If (dW = 0) Then dW = m_Width
        If (dH = 0) Then dH = m_Height
        If (sW = 0) Then sW = m_Width
        If (sH = 0) Then sH = m_Height
    
        lRet = GdipCreateFromHDC(nHdc, ImGraphics)
            
            If lRet <> 0 Then Exit Function               '- Can't create graphics object so bail out
            
            lRet = GdipDrawImageRectRectI(ImGraphics, nImage, dX, dY, dW, dH, sX, sY, sW, sH, 2)
    
            If lRet = 0 Then
                '- No error
                DrawImageToDC = 0
            Else
                '- Something went wrong
                GdipDeleteGraphics (ImGraphics)
                GdipDisposeImage nImage
                DrawImageToDC = lRet
            End If
      
    
        '- Clean up
        If ImGraphics Then GdipDeleteGraphics ImGraphics
     
    End Function
    Last edited by SomeYguy; Aug 5th, 2025 at 10:49 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width