Results 1 to 7 of 7

Thread: Resizing a PNG to fit a static picturebox exactly[RESOLVED]

  1. #1

    Thread Starter
    Frenzied Member Blobby's Avatar
    Join Date
    Oct 2001
    Location
    England
    Posts
    1,512

    Resizing a PNG to fit a static picturebox exactly[RESOLVED]

    hello boys and girls.

    Can anyone lend a hand with resizing a PNG to fit inside a picture box? Ive got the PNG file loaded and it displays it in my picture box but it doesnt do it to fit. I have a maximum available width and height and would ideally like the png file to fit to the largest dimension whilst keeping the aspect ratio.

    Anyone know anything about how to do it? Thanks

    I can post my code so far if need be its only small but needs the zlib.dll PNG library which i can also attach
    Last edited by Blobby; Jan 25th, 2003 at 10:40 AM.
    There are 3 types of people in this world.........those that can count, and those that can't.

    Blobby

  2. #2
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    Search for "bilinear interpolation" on Google. There should be some C code in your results, just adapt it to fit your needs (ex. to resize a byte array). There is also the StretchDIBits method that you can use.
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  3. #3

    Thread Starter
    Frenzied Member Blobby's Avatar
    Join Date
    Oct 2001
    Location
    England
    Posts
    1,512
    Sastraxi, thanks for those big words

    Ill look them up in the dictonary and check them out Thanks a lot
    There are 3 types of people in this world.........those that can count, and those that can't.

    Blobby

  4. #4
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Bilinear interpolation is a good resizing algorithm (though I think bicubic is even better). The problem of such algorithms is that nearly all code you'll find is either C/C++, Pascal or ASM. Image resizing is calculation and data intensive, so it's exactly the thing VB is NOT suited for.

    StretchDIBits (or StretchBlt) is quite nice, but you need a way to fix the image into the picture box.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  5. #5

    Thread Starter
    Frenzied Member Blobby's Avatar
    Join Date
    Oct 2001
    Location
    England
    Posts
    1,512
    CornedBee, thanks for that....ive just finished the resize/repostion code in Vb as i type this. Ill change the topic to resolved. What did you mean when you said 'fix' the image into the picture box? Ive used stretchblt to redraw and resize the image and it seems to work fine so im puzzled as to why it needs 'fix'ing.
    There are 3 types of people in this world.........those that can count, and those that can't.

    Blobby

  6. #6
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    I don't know much about the inner workings of VB. I was concerned that if you simply StretchBlt an image to the picturebox it might get erased as soon as the picturebox gets redrawn.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  7. #7

    Thread Starter
    Frenzied Member Blobby's Avatar
    Join Date
    Oct 2001
    Location
    England
    Posts
    1,512
    Well, im not sure as its displaying 98% of the images perfect but there a couple of images that refuse to draw and just give me a blank screen. i can scroll up 50 others and the work fine but going back to the troublesome one still refuses to display. The next time i run the prog however the pic displays fine so its not the pic. Im confused....it may be libpng error or zlib...i just dont know!
    There are 3 types of people in this world.........those that can count, and those that can't.

    Blobby

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