Results 1 to 4 of 4

Thread: Using a DC instead of Picture1.Picture

  1. #1

    Thread Starter
    Ex-Super Mod'rater Electroman's Avatar
    Join Date
    Sep 2000
    Location
    Newcastle, England
    Posts
    4,349

    Using a DC instead of Picture1.Picture

    I've used the code below to fill "bmp" with the details about the picture in "Picture1".
    VB Code:
    1. Private Type BITMAP
    2.     bmType As Long
    3.     bmWidth As Long
    4.     bmHeight As Long
    5.     bmWidthBytes As Long
    6.     bmPlanes As Integer
    7.     bmBitsPixel As Integer
    8.     bmBits As Long
    9. End Type
    10. Private bmp As BITMAP
    11.  
    12. GetObjectA Picture1.Picture, Len(bmp), bmp
    The problem is i'm no longer wanting to use a PicBox and have stored a picture in a DC I created instead. Does anyone know if there is a way to get these details from just the DC, The only part of "bmp" that I really need is "bmp.bmBits".

    Thanx to anyone that can help.
    Last edited by Electroman; Nov 2nd, 2002 at 03:01 PM.
    When your thread has been resolved please edit the original post in the thread ()
    and amend "-[RESOLVED]-" to the end of the title and change the icon to , Thank you.

    When posting Code use the [VBCode]Code Here[/VBCode] tags to be able to use the code highlighting.

  2. #2
    Addicted Member
    Join Date
    Oct 2002
    Location
    california
    Posts
    245
    I am just learning VB and bitmaps but the way I do what you're trying to do is:

    VB Code:
    1. Dim bmBits As Byte
    2.  
    3. f = FreeFile
    4. Open strFile For Binary As #f
    5.     Get #f, 29, bmBits
    6. Close #f

  3. #3

    Thread Starter
    Ex-Super Mod'rater Electroman's Avatar
    Join Date
    Sep 2000
    Location
    Newcastle, England
    Posts
    4,349
    I've sort of solved the problem but it seems as if there should be a better way to do this. Anyway this is how i'v managed it:
    VB Code:
    1. Private Type OffScreenDC
    2.     DC As Long
    3.     Object As IPictureDisp
    4. End Type
    5. Private MyPict as OffScreenDC
    I used this to create the DC:
    VB Code:
    1. 'Create compatible DC
    2. MyPict.DC = CreateCompatibleDC(frmMain.hdc)
    3.  
    4. 'Load bitmap
    5. Set MyPict.Object = LoadPicture(iFilename)
    6. SelectObject MyPict.DC, MyPict.Object
    7. nFirst = True
    Then I used the "MyPict.Object" instead of the Picture1.Picture:
    VB Code:
    1. GetObjectAPI MyPict.Object, Len(bmp), bmp
    Only thing is now I need to keep the IPictureDisp type when before I was getting rid of it once i had loaded the picture, so my question now is does anyone know if I can regain the IPictureDisp type for a DC when I need it because I might not always use a file to fill a DC.

    Thanx sequoyan, I'll look into that as well, but the thing is i'm trying to work with a loaded Bitmap and bmp.bmBits points to where in the memory the data is(I think).
    Last edited by Electroman; Nov 2nd, 2002 at 03:02 PM.
    When your thread has been resolved please edit the original post in the thread ()
    and amend "-[RESOLVED]-" to the end of the title and change the icon to , Thank you.

    When posting Code use the [VBCode]Code Here[/VBCode] tags to be able to use the code highlighting.

  4. #4
    Addicted Member
    Join Date
    Oct 2002
    Location
    california
    Posts
    245
    Sure, anytime. I'm just starting to learn DCs so what you're trying to do is a little beyond me.

    But if it helps at all, and if you didn't already know it, byte 29 is the bit depth.

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