Results 1 to 11 of 11

Thread: Flipping An Image

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jul 2002
    Posts
    27

    Flipping An Image

    ok im sure this is really simple, but i have looked through the 1st 15 pages of posts and cant find anyhitng

    i have loaded an image into a picture box, its an inverted dib, so as its loaded as a bmp its upside down, so rather than playing with all the dib commands to load it properly i want to simply flip the image that has been loaded, is that possible?

  2. #2
    Frenzied Member cyborg's Avatar
    Join Date
    May 2000
    Location
    Sweden
    Posts
    1,755
    dunno what a dib is, but to flip the code, do:

    VB Code:
    1. Dim X As Long
    2. Dim Y As Long
    3.  
    4. TempPic.Picture = Pic.Picture
    5.  
    6. For X = 0 To Pic.ScaleWidth
    7.     For Y = 0 To Pic.ScaleHeight
    8.         SetPixel Pic.hDC, X, Y, GetPixel(TempPic.hDC, Pic.ScaleWidth - X, Pic.ScaleHeight - Y)
    9.     Next Y
    10. Next X
    11.  
    12. Pic.Refresh
    Check out the FAQ and do a search before you post.
    My tutorials: Anti-Alias Pixels, Accurate Game Loop, Resource File

  3. #3
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    The reason is that the pixel bits are actually flipped in memory, however it displays correctly when SetDIBits is used (I think). If it still isn't, you should first try the loading options, and if all else fails (I'm assuming a 2D array with datatype of BYTE):
    Code:
    dim x as long
    dim y as long
    dim tmpbyte as byte
    for x = 0 to width * 3 - 1
        for y = 0 to height - 1
            tmpbyte = dib(x, y)
            dib(x, y) = dib(x, height - y) 
            dib(x, height - y) = tmpbyte
        next y
    next x
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  4. #4
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    cyborg: DIB stands for Device Independent Bitmap = (more or less) a bmp file.
    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
    Junior Member
    Join Date
    Jul 2002
    Posts
    27
    how long will these take 2 flip?? its a 6 meg picture (2732x2732 pixels) i know its pretty instant in picture progs lol

    would it be quicker 2 load it useing dib code?

  6. #6
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Picture progs only flip it once (when loading it) and then simply blit the corrected version.
    It's pretty fast to flip, but not so fast that you should do it everytime you draw the img.
    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
    Junior Member
    Join Date
    Jul 2002
    Posts
    27
    when i said in progs i was refering 2 when the user clicks the flip button

    i only need it flipped once (on load) so using a dib code to load would prob b faster, coz by the looks of those codes they do it line by line, its a 2732x2732 pixel image so it will take a wile i think, ill try them tonight when i get back fromwork to see ho fast or slow they are

    thx for the help

  8. #8
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    You can either do it line by line or pixel by pixel. But line by line in effect comes down to pixel by pixel too.
    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.

  9. #9

    Thread Starter
    Junior Member
    Join Date
    Jul 2002
    Posts
    27
    i dont mind what the method is, just as long as its fast lol

  10. #10
    Hyperactive Member
    Join Date
    Jun 1999
    Location
    ma,usa
    Posts
    485
    I use stretchblit to do flips passing in passing in a memorydc and manipulating the dest with. Make it dynamic and you can spin stuff pretty easily.

    ex: stretchblit memdc(0)x,y,width-x,height,memdc(1) _ x2,y2,width2,height2,vbsrccopy

  11. #11

    Thread Starter
    Junior Member
    Join Date
    Jul 2002
    Posts
    27
    cheers for all your help guys, i got it working now

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