Results 1 to 15 of 15

Thread: Image resize with out distortion

  1. #1

    Thread Starter
    Member
    Join Date
    Aug 2001
    Posts
    46

    Image resize with out distortion

    Hi there,

    When i am resizing a picture on the picture box control the picture is getting distorted or pixelated.n How do i resize the image without distortion.

    thanks
    Kanaka Prasad

  2. #2
    PowerPoster
    Join Date
    Aug 2000
    Location
    India
    Posts
    2,288
    use this API call before resizing the picture:
    VB Code:
    1. Private Const HALFTONE = 4
    2. Private Declare Function SetStretchBltMode Lib "gdi32" (ByVal hdc As Long, ByVal nStretchMode As Long)
    3.  
    4. 'use
    5.  
    6. SetStretchBltMode picHdc, HALFTONE

  3. #3

    Thread Starter
    Member
    Join Date
    Aug 2001
    Posts
    46
    halftone is not supported in 95/98
    Kanaka Prasad

  4. #4
    PowerPoster
    Join Date
    Aug 2000
    Location
    India
    Posts
    2,288
    Try this
    Private Const COLORONCOLOR = 3

  5. #5
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    You can also try a bicubic/bilinear resize algorithm.
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  6. #6
    Addicted Member cutamacious's Avatar
    Join Date
    May 2001
    Location
    INDIA >> Andhra Pradesh >> Hyderabad
    Posts
    185
    Sastraxi

    Could you help me regarding the Bicubic/Bilinear resizing algorithm and how do i implement it in VB. Or may you could suggest some sites where i can get the information.

    Fact is i need to include the image resizing in one of my modules. But the resultant image i got is being pixelated. I'm using the paintpicture method of the picture box.

    I'm also in a lookout for resing the images using the code. I've tried also using the stretchblt API call but hte result seems to be the same.


    Thanx in advance
    Cute Member

  7. #7
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    I recommend getting the book Visual Basic Graphics programming. There are two functions you use, one for enlarging and one for shrinking, and you'll have to adapt it to your own code. Try searching google if you don't have this book for Resize Algorithm.
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  8. #8
    Addicted Member cutamacious's Avatar
    Join Date
    May 2001
    Location
    INDIA >> Andhra Pradesh >> Hyderabad
    Posts
    185

    Unhappy

    Sastraxi



    I've tried searching google for the resize algorithm, but there's no real code given in it. only lots and lots of text. I would like to go through any sample code which does the resizing and i can enhance it to fit my requirements.

    Could u help me on this issue?
    Cute Member

  9. #9
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    I have the code in my book but really don't have the time to write it out... sorry.
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  10. #10
    Behemoth
    Guest
    Strictly speaking, it is impossible to resize an image without distorting it, the trick is to distort it as little as possible, but its never going to be perfect.

    Firstly, if you're resizing by a large amount, particularly if you're expanding an image it will look pixellated and crappy. Even a decent bicubic algorithm (say for example Photoshop's) won't be able to fix it if you're trying to make it really big.

    Secondly, try to resize to a common factor or multiple of the images original size. shrinking an image to 50% will look better than shrinking it to 66.6% for example.

    The whole subject is quite a complicated science. A google search could tell you more.

  11. #11
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    Learning the mechanics behind it will help you best manipulate it; don't jump straight in to code.
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  12. #12
    Addicted Member Janus's Avatar
    Join Date
    Aug 2001
    Location
    California
    Posts
    221
    Fury2GE has Bi-Linear resampling, but the down-scaling is buggy. If you don't mind using a library, mine does it quite fast (in realtime, literally, for sizes below 640x480.)
    http://fury2.happyapathy.com/fury2ge.exe
    "1 4m 4 1337 #4xz0r!'
    Janus

  13. #13
    Addicted Member cutamacious's Avatar
    Join Date
    May 2001
    Location
    INDIA >> Andhra Pradesh >> Hyderabad
    Posts
    185

    Angry

    I've tried using StretchBlt for resizing the image in the picture box and the painting it into another picture box. but the destination picture box does not show any picture and the return value of StretchBlt is non-zero. I've aslo called the set stretchbltmode with the destination pic. box hdc as the first argument and COLORONCOLOR as the second. but still the problem is persisting kindly help on this.

    Cute Member

  14. #14
    Addicted Member Janus's Avatar
    Join Date
    Aug 2001
    Location
    California
    Posts
    221
    A non-zero return code means an error, you should look up the return code in the MSDN documentation for StretchBlt.
    "1 4m 4 1337 #4xz0r!'
    Janus

  15. #15
    Addicted Member cutamacious's Avatar
    Join Date
    May 2001
    Location
    INDIA >> Andhra Pradesh >> Hyderabad
    Posts
    185
    In MSDN it is listed as

    If function succeds the return value is non-zero
    if function fails the return value is zero


    Cute Member

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