Results 1 to 10 of 10

Thread: How do i load a picture into a picturebox

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2000
    Posts
    299

    Question

    Without using the Loadpicture method? How about BitBlt? i have heard that might do it. Any other methods? i guess i could use SetPixel (pretty lame way i think, drawing each pixel??)
    Anyone have any ideas?

  2. #2
    Frenzied Member
    Join Date
    Mar 2000
    Posts
    1,089
    if you're going from a file
    Code:
    Set Picture1.Picture = LoadPicture("MyPicture.bmp")
    From another Picturebox[/code]Set Picture1.Picture = Picture2.Image[/code]


  3. #3
    Guest
    BitBlt and SetPixel are both methods of drawing Pictures, not loading them from a file.

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2000
    Posts
    299

    Unhappy So only Loadpicture works?

    Bummer. Sounds like i'm stuck with it, and i guess theres nothing i can do to stop the pixellation that occurs.
    Oh well.
    BW

  5. #5
    Frenzied Member
    Join Date
    Mar 2000
    Posts
    1,089
    Oh, Sorry, I misread your post. It Can be done anotherway, I think you gave to use the CreateFileMapping and CreateBitmap APIs but I'm not entirely sure how. I think if you get hold of a book on Windows programming in C, that would explain it. (Don't buy one they're expensive, just go to a bookshop and read one) If you can't read C then that makes it harder, all the good stuff on API programming is written in C so I'd recomend learning to read it. It's much easier to read than it is to write.

  6. #6
    Hyperactive Member
    Join Date
    Jun 2000
    Location
    Auckland, NZ
    Posts
    411

    I will reply soon

    I will have a post shortly for you.

    It might be too much code to post here so I may have to email you?

    In any case, I will snip some code from my own project. I have messed with loading/saving jpegs to/from disk as well as to/from Access DB fields... so I might have some code that you can tailor...

    Cheers
    Paul Lewis


  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2000
    Posts
    299

    Cool as!!

    I can get a copy of Dan Applemans guide to the API for VB, so i'll get that to have a look. Cheers

    PaulLewis: You can email me, i guess my email address is in there somewhere, just take out the -nospamforme- in the address. If you can't get it from my info, let me know and i'll post it.
    I'll wait for your post
    BW

  8. #8
    Guest
    Regarding Bitmap API's:

    While the CreateBitmap API can be used to create Colour Bitmaps, for performace reasons, you should use CreateBitmap to create Monochrome Bitmaps and CreateCompatibleBitmap to create Colour Bitmaps. when a colour bitmap returned from CreateBitmap is selected into the device context, Windows must ensure that the Bitmap matches the format of the device context it is being selected to. Since CreateCompatibleBitmap takes a device context, it returns a bitmap that has the same format as the specified device context. Because of this, subsequent calls to SelectObject are faster than with a colour being returned from CreateBitmap.

  9. #9
    Hyperactive Member
    Join Date
    Jun 2000
    Location
    Auckland, NZ
    Posts
    411

    Solution or not?

    OK, There are two other files needed to work with this, both are from the site: http://www.vbaccelerator.com.

    Check out the following links. You will need the class module cDIBSection and the module mIntelJPEGLibrary to make my simple test work. Get the files from http://vbaccelerator.com/codelib/gfx/vbjpeg.htm

    I never had a 16M colour jpeg so I am sure my code will let you load / save jpeg to BMP, but you may still suffer from the colour depth problem.


    But, while verifying that link for you , i noticed an article on the site called "Colour Depth Control
    ... whether you want to save to a different colour depth. This sample shows how to colour reduce a DIBSection object using two different techniques and save that to a bitmap file at the correct colour depth ..." the link is: http://vbaccelerator.com/codelib/gfx/octree.htm

    This looks like exactly what you want... So take a look.

    It's a solution, not a quick and easy one, and by the end you will probably know more about the DIB API that you wanted to but at least you will be able to proceed.

    Indidentally, I hate big wallpaper pics cos they take so long to load/refresh. Also, they are stored along with any of your desktop icons/folders and your registry settings in your profile when running on a network (Well NT anyhow) so the bigger the pic, the longer it takes to download your stuff from the server when you logon.

    Be that as it may, I have a small pic of my baby son in the centre of my screen... hehe


    Oh, the code...

    Code:
    Option Explicit
    Private Sub Command1_Click()
      RunLoadJPGDemo Text1.Text
    End Sub
    
    Private Sub RunLoadJPGDemo(ByVal filename As String)
      Dim picDIB As New cDIBSection
      
      ' thanks to intel and vbaccelerator site for this nice code
      LoadJPG picDIB, filename
    
      ' just resize the picture box to meet the size of the DIB
      Picture1.width = ScaleX(picDIB.width, 3, 1)
      Picture1.height = ScaleY(picDIB.height, 3, 1)
      
      ' now paint the picture
      picDIB.PaintPicture Picture1.hdc
      
      ' and finally set the picturebox's picture property to the visible image
      Set Picture1.Picture = Picture1.Image
      
      ' save the picture (as BMP)
      SavePicture Picture1.Picture, "c:\winnt\pic2.bmp"
    End Sub

    Cheers

    Paul Lewis

  10. #10

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2000
    Posts
    299

    ok...

    I have had a look at that octree project, and while it looks great, it doesn't actually solve my problem, cos it still loads using loadpicture. I have just downloaded the jpg zip and will have a look and see how that goes.
    BW

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