Results 1 to 25 of 25

Thread: [VB6] - image scaling

  1. #1
    PowerPoster joaquim's Avatar
    Join Date
    Apr 07
    Posts
    2,494

    [VB6] - image scaling

    i know catch the image to pixels... but i don't know work with image scaling
    i know use the stretch api functions, but i wanted build nice alghoritmos... can anyone explain to me how can i create my own method?
    VB6 2D Sprite control

    To live is difficult, but we do it.

  2. #2
    PowerPoster joaquim's Avatar
    Join Date
    Apr 07
    Posts
    2,494

    Re: [VB6] - image scaling

    on emulators we have very nice graphics filters for render an image. but i don't know how works. can anyone explain to me?
    VB6 2D Sprite control

    To live is difficult, but we do it.

  3. #3
    Lively Member Mikle's Avatar
    Join Date
    Oct 09
    Location
    Tuapse, Russia
    Posts
    76

    Re: [VB6] - image scaling


  4. #4
    PowerPoster joaquim's Avatar
    Join Date
    Apr 07
    Posts
    2,494

    Re: [VB6] - image scaling

    Quote Originally Posted by Mikle View Post
    sorry. but can you explain how we do filters?
    you know, that i know working with pixels, but i don't understand how do filters
    i wanted work\do nice filters when 1 image is resize it... because the stretchdibs() function don't give us good results
    VB6 2D Sprite control

    To live is difficult, but we do it.

  5. #5
    Lively Member Mikle's Avatar
    Join Date
    Oct 09
    Location
    Tuapse, Russia
    Posts
    76

    Re: [VB6] - image scaling

    This is the usual linear interpolation pixel colors.

  6. #6
    PowerPoster joaquim's Avatar
    Join Date
    Apr 07
    Posts
    2,494

    Re: [VB6] - image scaling

    Quote Originally Posted by Mikle View Post
    This is the usual linear interpolation pixel colors.
    sorry, but i don't know how the linear interpolation pixel colors works
    i know work with pixels, like you know. what i don't know is how the effects works. and more dificulty is the stretch(that it's my objective).
    can you explain to me how can i resize an image(pseudo-code) by a pixel?
    (by pixels, i know do: mirror and rotate an image and change colors and select an object and do a nice shadow... i don't know all)
    VB6 2D Sprite control

    To live is difficult, but we do it.

  7. #7
    Lively Member mikorians's Avatar
    Join Date
    Jun 10
    Location
    In a fog
    Posts
    83

    Re: [VB6] - image scaling

    Once again, Mikle generously offers the whole solution... Perhaps a simpler understanding of the process is what you desire? This pseudo code does NO INTERPOLATION of colors and is very slow.
    xscale=(maxX+1)/maxx
    yscale=(maxY+1)/maxy
    for y=0 to maxY
    for x=0 to maxX
    col=pic1.point(x,y)
    for y1=y*yscale to (y+1)*yscale
    for x1=x*xscale to (x+1)*xscale
    pic2.pset(x1,y1),col
    next x1
    next y1
    next x
    doevents
    next y
    Last edited by mikorians; Sep 24th, 2012 at 02:05 PM.

  8. #8
    PowerPoster joaquim's Avatar
    Join Date
    Apr 07
    Posts
    2,494

    Re: [VB6] - image scaling

    the maxX and maxY are the final size, right?
    then what are xscale and yscale?
    VB6 2D Sprite control

    To live is difficult, but we do it.

  9. #9
    Lively Member mikorians's Avatar
    Join Date
    Jun 10
    Location
    In a fog
    Posts
    83

    Re: [VB6] - image scaling

    note the first two lines say maxX+1 and maxY+1
    maxX and maxY are meant to be the 1st images size.

  10. #10
    Lively Member mikorians's Avatar
    Join Date
    Jun 10
    Location
    In a fog
    Posts
    83

    Re: [VB6] - image scaling

    Also with this SIMPLE method - not using any color interpolation, you may notice a pair of vertical lines and a pair of horizontal lines that have the same color, and we did not 'dither' the colors throughout the 2nd image, so
    what this does is probably leave you with vertical and horizontal stripe artifacts. I myself am not certain as to how to improve this by much without a much more complex mathematical algorithm with pic1.point(x+n,y+m) based color dithering with another pair of loops... or a more intelligent pset post-processing algorithm.
    Last edited by mikorians; Sep 24th, 2012 at 02:21 PM.

  11. #11
    Lively Member mikorians's Avatar
    Join Date
    Jun 10
    Location
    In a fog
    Posts
    83

    Re: [VB6] - image scaling

    But... Aside from these artifacts, you should be able to increase your image size by whatever you wish. This represents kinda what the built in stretchblit or paintpicture method does.

  12. #12
    PowerPoster joaquim's Avatar
    Join Date
    Apr 07
    Posts
    2,494

    Re: [VB6] - image scaling

    sorry... but i can't see a diference between the original image and the result
    (picture1=original image... picture2=result)
    for me seems the same... just a copy
    Code:
    Option Explicit
    
    Private Sub Command1_Click()
    Dim x As Long
    Dim y As Long
    Dim col As Long
    Dim X1 As Long
    Dim y1 As Long
    Dim xscale As Long
    Dim yscale As Long
    
    xscale = (Picture1.Width + 1) / Picture1.Width
     yscale = (Picture1.Height + 1) / Picture1.Height
     For y = 0 To Picture1.Height
     For x = 0 To Picture1.Width
     col = Picture1.Point(x, y)
     For y1 = y * yscale To (y + 1) * yscale
     For X1 = x * xscale To (x + 1) * xscale
     Picture2.PSet (X1, y1), col
     Next X1
     Next y1
     Next x
     DoEvents
     Next y
    End Sub
    VB6 2D Sprite control

    To live is difficult, but we do it.

  13. #13
    Lively Member mikorians's Avatar
    Join Date
    Jun 10
    Location
    In a fog
    Posts
    83

    Re: [VB6] - image scaling

    xscale and yscale should be single not long - decimal values
    You aren't going to notice much of any change with only 1 pixel of size difference

  14. #14
    Lively Member mikorians's Avatar
    Join Date
    Jun 10
    Location
    In a fog
    Posts
    83

    Re: [VB6] - image scaling

    X1 Y1 should also be single I suppose. Aw fudge, I must be half-awake. I made 4 typos on this one post.

  15. #15
    PowerPoster joaquim's Avatar
    Join Date
    Apr 07
    Posts
    2,494

    Re: [VB6] - image scaling

    Quote Originally Posted by mikorians View Post
    X1 Y1 should also be single I suppose. Aw fudge, I must be half-awake. I made 4 typos on this one post.
    ok.. i did it, but it's the same.
    my global objective is build a nice resize way
    VB6 2D Sprite control

    To live is difficult, but we do it.

  16. #16
    Lively Member mikorians's Avatar
    Join Date
    Jun 10
    Location
    In a fog
    Posts
    83

    Re: [VB6] - image scaling

    We're close now, stand by, testing app.. Mustof fudged my old math a bit...

  17. #17
    Lively Member mikorians's Avatar
    Join Date
    Jun 10
    Location
    In a fog
    Posts
    83

    Re: [VB6] - image scaling

    The code did work with slight changes. Examine this.
    Attached Files Attached Files

  18. #18
    Lively Member mikorians's Avatar
    Join Date
    Jun 10
    Location
    In a fog
    Posts
    83

    Re: [VB6] - image scaling

    Odd how the decimal math becomes your enemy at small size increases.

  19. #19
    PowerPoster joaquim's Avatar
    Join Date
    Apr 07
    Posts
    2,494

    Re: [VB6] - image scaling

    can you tell me theory of the code?
    thanks for all
    VB6 2D Sprite control

    To live is difficult, but we do it.

  20. #20
    Lively Member mikorians's Avatar
    Join Date
    Jun 10
    Location
    In a fog
    Posts
    83

    Re: [VB6] - image scaling

    I verified exactly 1 pixel larger output on this app with a paint program.
    Attached Files Attached Files

  21. #21
    Lively Member mikorians's Avatar
    Join Date
    Jun 10
    Location
    In a fog
    Posts
    83

    Re: [VB6] - image scaling

    This application performs a pair of classic Cartesian coordinate loops with simple division arithmetic to scale the values up or down by a tiny value that is proportional to the two different sizes of the images.
    Version 2 is much faster. Hope you enjoy!
    These are pretty sloppy and perform no error or numeric bounding tests, neither do they permit user data entry or save and load any images.
    If you're in school for this, then study your algebra real hard now!

  22. #22
    PowerPoster joaquim's Avatar
    Join Date
    Apr 07
    Posts
    2,494

    Re: [VB6] - image scaling

    it can be more faster, but i see 2 errors:
    1 - i see that left 1 pixel.. but i correct it;
    2 - the image isn't resized.
    Code:
    Option Explicit
    Private Sub Command1_Click()
    'Make certain the pictureboxes have scalemode set to pixels
    'and autoredraw set to true
    Dim X As Long
    Dim Y As Long
    Dim Col As Long
    Dim X1 As Single
    Dim Y1 As Single
    Dim MaxX As Long
    Dim MaxY As Long
    Dim Xscale As Single
    Dim Yscale As Single
    MaxX = Picture1.ScaleWidth - 4
    MaxY = Picture1.ScaleHeight - 4
    Xscale = MaxX / (MaxX - 1) '55 pixels wider
    Yscale = MaxY / (MaxY - 1) '55 pixels higher
    For Y = 0 To MaxY + 1
    For X = 0 To MaxX + 1
    Col = Picture1.Point(X * Xscale, Y * Yscale)
    Picture2.PSet (X, Y), Col
    Next X
    DoEvents
    Next Y
    'Picture2 is EXACTLY 1 pixel larger
    End Sub
    thanks for all
    VB6 2D Sprite control

    To live is difficult, but we do it.

  23. #23
    Lively Member mikorians's Avatar
    Join Date
    Jun 10
    Location
    In a fog
    Posts
    83

    Re: [VB6] - image scaling

    My comments should have been '1 pixel wider and '1 pixel higher, respectively
    As the file was verbatim worked. I don't know if the +1 is necessary in the two loops, but with the -1 on the scale, it should make it 2 pixels larger.
    Whatever works for you, but don't exceed the size of your source picture's dimensions (picture1). I put a -4 because the 3d frame around the picturebox control messes us all up.
    It's nitpicky with 1 pixel, but watch it if you go to larger size changes, you'll see what I mean.
    I'm done now.
    Good luck!

  24. #24
    PowerPoster joaquim's Avatar
    Join Date
    Apr 07
    Posts
    2,494

    Re: [VB6] - image scaling

    thanks for all my friend
    VB6 2D Sprite control

    To live is difficult, but we do it.

  25. #25
    Lively Member mikorians's Avatar
    Join Date
    Jun 10
    Location
    In a fog
    Posts
    83

    Red face Re: [VB6] - image scaling [RESOLVED]

    You're welcome. We have a lot of time to burn around here. Happy to help!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •