Results 1 to 7 of 7

Thread: Pictures

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jun 2002
    Location
    Far.. far away! (Netherlands)
    Posts
    169

    Pictures

    Hi everyone, yet another question from me
    I'm messing around bit with graphics and stuff, I got this:

    Code:
    Dim TmpPictureBox as Picturebox
    Is there any way that I can use this picturebox for drawing? When i try to it gives all kind of nice errors
    I want to do some drawing inside a function on such a picturebox and then return that picturebox's picture property. I hope I made myself clear and that anyone knows how to fix this.

    -Shell-
    Last edited by Shell; Oct 29th, 2002 at 04:02 PM.

  2. #2

    Thread Starter
    Addicted Member
    Join Date
    Jun 2002
    Location
    Far.. far away! (Netherlands)
    Posts
    169
    Ok, i'll change the question.

    I'm making a graphics file format (nothing serious, just playing around). I want to make a function where you input a filename and the function then returns a picture. Like this:

    Code:
    Public Funtion OpenGraphicFile(sFileName as String) as picture
    
    'Do drawing and loading stuff
    
    End Function
    How can I make a picture with the right sizes (stored in the file) wich I can return with this function? I want to use the function like this:

    Code:
    Picture1.picture = OpenGraphicFile("c:\test.grp")
    I know i'll have to use the createbitmap api and some other, but i have no clue on how to use those! Anyone please help me

    Thanks in advance,

    -Shell-

  3. #3
    Addicted Member Frankie902's Avatar
    Join Date
    Feb 2001
    Location
    Lindenwold, NJ, USA
    Posts
    217
    you could make a graphic format if you know some your binary open commands. And if you plan the structure of your format.

    ill look into what your trying to do with the picture.
    Using:
    Visual Studio .Net Enterprise
    Visual Basic 6.0 Enterprise

  4. #4
    Addicted Member
    Join Date
    Aug 2002
    Location
    Baltimore, MD
    Posts
    230
    The PictureBox only supports certain formats so your function would have to return something that the control supports. Since that's the case, why go to all the trouble of developing your own file format. Also, for your first question, try this:

    Dim TmpPictureBox as StdPicture

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Jun 2002
    Location
    Far.. far away! (Netherlands)
    Posts
    169
    Hi,

    What I want to do is:

    Make a bitmap with given size in memory wich I can draw on using setpixelv and wich I can return from a function so it can be put in a picturebox.

    -Shell-

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Jun 2002
    Location
    Far.. far away! (Netherlands)
    Posts
    169
    Ok... i've been doing some trying and searching and i now have this:

    Code:
    Dim MyDC As Long
    Dim hBitmap As Long
    Dim Pic As New StdPicture
    
    Set Pic = LoadPicture("")
    
    'Create a DC
    MyDC = CreateCompatibleDC(GetDC(0))
    
    'Create a bitmap
    hBitmap = CreateCompatibleBitmap(GetDC(0), 32, 32)
    
    'Select the bitmap in the DC
    SelectObject MyDC, hBitmap
    
    BitBlt MyDC, 0, 0, 32, 32, Picture1.hdc, 0, 0, SRCCOPY
    This creates a 32x32 image, now my question is: How can i put this picture into the stdPicture thing? I tried this: pic.handle = MyDC, but that wouldn't work. Anyone knows? Please help me!!

    -Shell-

  7. #7
    Addicted Member
    Join Date
    Oct 2002
    Location
    Somewhere out in space
    Posts
    151
    Here's a function create an stdPicture using the handle of a bitmap using the OleCreatePictureIndirect API

    Code:
    Public Type GUID
        
        Data1 As Long
        Data2 As Integer
        Data3 As Integer
        Data4(7) As Byte
    
    End Type
    
    Public Type PicBmp
        
        Size As Long
        Type As Long
        hBmp As Long
        hPal As Long
        Reserved As Long
    
    End Type
    
    Declare Function OleCreatePictureIndirect Lib "olepro32.dll" (PicDesc As PicBmp, RefIID As GUID, ByVal fPictureOwnsHandle As Long, iPic As IPicture) As Long
    
    Private Function BitmapToStdPicture(hMemBmp As Long) As StdPicture
    
    Dim InterfaceId As GUID
    Dim Pic As PicBmp
    Dim iPic As StdPicture
    
        With InterfaceId
            
            .Data1 = &H20400
            .Data4(0) = &HC0
            .Data4(7) = &H46
        
        End With
        
        With Pic
        
            .Size = Len(Pic)
            .Type = vbPicTypeBitmap
            .hBmp = hMemBmp
            
        End With
        
        OleCreatePictureIndirect Pic, InterfaceId, 1, iPic
        Set LoadMemoryBitmap = iPic
        
    End Function

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