×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

HBITMAP

HBITMAP

(OP)
Warning! Very limited graphics programming knowledge and using VB6. Now 3 days at the helm with no sleep.  

I am trying to load a texture.  I have been able to do this from a disk file by using LoadImage and specifying the texture's file name,

'***********************
Public HBITMAP as Long

HBITMAP = LoadImage(0, TextureFileName, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE Or LR_CREATEDIBSECTION)

'***********************

I would also like to load a texture from a Device Context, but can't seem to figure out what the procedure is for doing that.  I now guess its probably impossible to simply BitBlt to an HBITMAP, as I have been able to do from one DC to another, or from a DC to a picture box.  Anybody know how to get a DC into a HBITMAP?  Humm... looks like I should have tried creating a DIB and attempt to load with the same statements above, so I'll be trying that until...

BigInchworm-born in the trenches.
http://virtualpipeline.spaces.msn.com

RE: HBITMAP

(OP)
Here's the code I eventually came up with, if anyone's interested.

It loads the picture from picture1 into one memory bitmap, hTmp, blits from hTmp to another memory bitmap jTmp, then blits it back from j to picture1 at 1/2 size.

Make a std exe Form1 with,
Picture Box, Picture1
Command Button, Command1
Load any picture you like into the picture box.

Add this code to the form,

CODE

'DECLARES
Private Declare Function CreateCompatibleDC Lib "gdi32.dll" (ByVal hdc As Long) As Long
Private Declare Function DeleteDC Lib "gdi32.dll" (ByVal hdc As Long) As Long
Private Declare Function SelectObject Lib "gdi32.dll" (ByVal hdc As Long, ByVal hObject As Long) As Long
Private Declare Function DeleteObject Lib "gdi32.dll" (ByVal hObject As Long) As Long
Private Declare Function BitBlt Lib "gdi32.dll" (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long
Private Declare Function CreateCompatibleBitmap Lib "gdi32" (ByVal hdc As Long, ByVal nWidth As Long, ByVal nHeight As Long) As Long
Private Declare Function StretchBlt Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal nSrcWidth As Long, ByVal nSrcHeight As Long, ByVal dwRop As Long) As Long
' END DECLARES

CODE


Private Sub Command1_Click()

    Dim hTmp As Long  'DC 1 in memory
    Dim jTmp As Long  'DC 2 in memory
    
    'Create a DC with the same settings as the picturebox
    hTmp = CreateCompatibleDC(Picture1.hdc)
    jTmp = CreateCompatibleDC(Picture1.hdc)
    
    'If the DC was created...
    If hTmp Then
        'Obtain a bitmap with compatible settings
        hBitmap = CreateCompatibleBitmap(Picture1.hdc, Picture1.Width, Picture1.Height)
        
        If hBitmap Then
            'associate this bitmap with the DC
            SelectObject hTmp, hBitmap
            
            'Copy the picture from Picture1 on to the memory DC
            BitBlt hTmp, 0, 0, Picture1.Width, Picture1.Height, Picture1.hdc, 0, 0, vbSrcCopy
            
            'Now copy it back to the picture
            Me.Picture1 = Nothing
            StretchBlt Picture1.hdc, 0, 0, Picture1.Width, Picture1.Height, hTmp, 0, 0, Picture1.Width, Picture1.Height, vbSrcCopy
            Picture1.Refresh
            
        End If
    End If
    
    'Blit hTmp to jTmp
    jBitmap = CreateCompatibleBitmap(hTmp, Picture1.Width, Picture1.Height)
        
    SelectObject jTmp, jBitmap
    'SelectObject hTmp, hBitmap
    
    BitBlt jTmp, 0, 0, Picture1.Width, Picture1.Height, hTmp, 0, 0, vbSrcCopy

    'send jTmp to picture1
    Me.Picture1 = Nothing
    SelectObject jTmp, jBitmap
    StretchBlt Picture1.hdc, 0, 0, Picture1.Width \ 2, Picture1.Height \ 2, jTmp, 0, 0, Picture1.Width, Picture1.Height, vbSrcCopy
    Picture1.Refresh
    
    'Remove these objects now
    DeleteObject hBitmap
    DeleteObject jBitmap
    DeleteDC hTmp
    DeleteDC jTmp
End Sub

Private Sub Form_Load()
    Me.ScaleMode = vbPixels
    Me.AutoRedraw = True

End Sub

http://virtualpipeline.spaces.msn.com

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members! Already a Member? Login


Resources

Low-Volume Rapid Injection Molding With 3D Printed Molds
Learn methods and guidelines for using stereolithography (SLA) 3D printed molds in the injection molding process to lower costs and lead time. Discover how this hybrid manufacturing process enables on-demand mold fabrication to quickly produce small batches of thermoplastic parts. Download Now
Design for Additive Manufacturing (DfAM)
Examine how the principles of DfAM upend many of the long-standing rules around manufacturability - allowing engineers and designers to place a part’s function at the center of their design considerations. Download Now
Taking Control of Engineering Documents
This ebook covers tips for creating and managing workflows, security best practices and protection of intellectual property, Cloud vs. on-premise software solutions, CAD file management, compliance, and more. Download Now

Close Box

Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close