Results 1 to 32 of 32

Thread: Simple morphing [RESOLVED]

  1. #1

    Thread Starter
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Simple morphing [RESOLVED]

    Does anybody have any suggestion how to create a routine to create simple morphing between 2 images using the GDI APIs? I'm guessing that some XORing between the images would do it but I just can't figure out a good way of doing it. What I want is for the user to select two pictures and the program would create a number of images "between" those so they together could form a simple morphing animation.

    Any suggestions are more then welcome.
    Last edited by Joacim Andersson; May 14th, 2003 at 09:23 AM.

  2. #2
    Frenzied Member cyborg's Avatar
    Join Date
    May 2000
    Location
    Sweden
    Posts
    1,755
    have you tried MorphMan? maybe that program will give you some ideas...
    it lets the user click on a point on the first pic and set where it should be on the other pic and the finished animation fades between the two pics while moving that certain point....looks really good
    Check out the FAQ and do a search before you post.
    My tutorials: Anti-Alias Pixels, Accurate Game Loop, Resource File

  3. #3

    Thread Starter
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    Originally posted by cyborg
    have you tried MorphMan? maybe that program will give you some ideas...
    it lets the user click on a point on the first pic and set where it should be on the other pic and the finished animation fades between the two pics while moving that certain point....looks really good
    Thanks but if it doesn't come with an API I can use in my app it's useless for me.

  4. #4

    Thread Starter
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    It doesn't have to be any good morphing, a simple fade effect would do....

  5. #5
    Fanatic Member Mushroom Realm's Avatar
    Join Date
    Mar 2002
    Location
    Murrieta, California
    Posts
    650
    Pradeep wrote one that works well. It's at http://www.vbforums.com/showthread.p...hreadid=244183

  6. #6

    Thread Starter
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    Thanks Mushroom, it works as expected however it's dead slow since it's just using Get/SetPixels, especially on larger images. I was hoping for some quicker code... There must be a faster way to XOR the DIBs or GDIs together, or not ??? But thank you so much anyway.

  7. #7
    Frenzied Member Zaei's Avatar
    Join Date
    Jul 2002
    Location
    My own little world...
    Posts
    1,710
    The only FAST way to do realtime fading is with assembly or DirectX.

    Z.

  8. #8

    Thread Starter
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    Originally posted by Zaei
    The only FAST way to do realtime fading is with assembly or DirectX.

    Z.
    Well, it all depends on how you would define "realtime" in this context. What I want to do is to create images that will be stored on disk, I could later use these images to create an animation, GIF or AVI or whatever. Using assembly to work with GDI objects is not what I'm after. My application will NOT require directx either. Cyborg mentioned MorphMan which doesn't use DirectX and I know for a fact that it isn't written in an assembly language either, I'm pretty sure it uses good ol' Windows GDI functions, either through API or MFC classes.

  9. #9
    Frenzied Member Zaei's Avatar
    Join Date
    Jul 2002
    Location
    My own little world...
    Posts
    1,710
    I define realtime to be generating the images on the fly fast enough that the image appears to be moving (even if it is choppy). However, since you are actually going to be generating and storing the frames, this isnt a problem... The Get/SetPixel method should do fine. If you wanted, you could also try using the Get/SetDIBits functions.

    Z.

  10. #10

    Thread Starter
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    Originally posted by Zaei
    I define realtime to be generating the images on the fly fast enough that the image appears to be moving (even if it is choppy). However, since you are actually going to be generating and storing the frames, this isnt a problem... The Get/SetPixel method should do fine. If you wanted, you could also try using the Get/SetDIBits functions.

    Z.
    Well, the problem is that Get/SetPixel isn't fast enough... It takes forever to loop through an image and then doing it again and again for each image to create. I've done some experimenting with the Get/SetDIBits functions but couldn't get it to work for this. Do you have any example code?

  11. #11
    Fanatic Member pradeepkrao's Avatar
    Join Date
    Sep 2001
    Location
    New Jersey
    Posts
    534

    Hi

    Thanks Mushroom, it works as expected however it's dead slow since it's just using Get/SetPixels, especially on larger images. I was hoping for some quicker code... There must be a faster way to XOR the DIBs or GDIs together, or not ??? But thank you so much anyway.
    I dint have a better thought to do it..

    But yes.. what you could do is after drawing at the first store the picture in a dc do it till your frame count...

    This would be one time activity.. Then you can just load those dc'c on by one using BitBlt..
    Learn by others experience as you cannot live long to experience them all.
    www.freewebs.com/pradeepkrao

    LOOK AT MY GAMES AT MY WEB SITE.

  12. #12
    Frenzied Member Zaei's Avatar
    Join Date
    Jul 2002
    Location
    My own little world...
    Posts
    1,710
    I dont have any code for you, but there should be some floating about.

    Z.

  13. #13
    Frenzied Member
    Join Date
    Jul 2002
    Posts
    1,370
    You can use AlphaBlend to fade and combine two pictures.
    I'm not sure that is what you want, but is a way of mrphing images.

    Code:
    'This project requires two picture boxes
    'Both picture boxes should contain a picture
    Const AC_SRC_OVER = &H00
    Private Type BLENDFUNCTION
      BlendOp As Byte
      BlendFlags As Byte
      SourceConstantAlpha As Byte
      AlphaFormat As Byte
    End Type
    Private Declare Function AlphaBlend Lib "msimg32.dll" (ByVal hdc As Long, ByVal lInt As Long, ByVal lInt As Long, ByVal lInt As Long, ByVal lInt As Long, ByVal hdc As Long, ByVal lInt As Long, ByVal lInt As Long, ByVal lInt As Long, ByVal lInt As Long, ByVal BLENDFUNCT As Long) As Long
    Private Declare Sub RtlMoveMemory Lib "kernel32.dll" (Destination As Any, Source As Any, ByVal Length As Long)
    Private Sub Form_Load()
        'KPD-Team 2000
        'URL: http://www.allapi.net/
        'E-Mail: [email protected]
        Dim BF As BLENDFUNCTION, lBF As Long
        'Set the graphics mode to persistent
        Picture1.AutoRedraw = True
        Picture2.AutoRedraw = True
        'API uses pixels
        Picture1.ScaleMode = vbPixels
        Picture2.ScaleMode = vbPixels
        'set the parameters
        With BF
            .BlendOp = AC_SRC_OVER
            .BlendFlags = 0
            .SourceConstantAlpha = 128
            .AlphaFormat = 0
        End With
        'copy the BLENDFUNCTION-structure to a Long
        RtlMoveMemory lBF, BF, 4
        'AlphaBlend the picture from Picture1 over the picture of Picture2
        AlphaBlend Picture2.hdc, 0, 0, Picture2.ScaleWidth, Picture2.ScaleHeight, Picture1.hdc, 0, 0, Picture1.ScaleWidth, Picture1.ScaleHeight, lBF
    End Sub

  14. #14

    Thread Starter
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    Thanks a million Jim. I did get alphablend to work, the only problem with that call is that it's not available in Win95 or NT4, but I guess I could live with that. I can always check the OS version and use AlphaBlend if it's available and if not use the slow Get/SetPixel approach if it's not (that should teach people to upgrade their OSes )

    Cheers,

  15. #15
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    Tried GetDIBBits yet?

  16. #16

    Thread Starter
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    Originally posted by Fox
    Tried GetDIBBits yet?
    Many times However I've no idea how to use it to produce a morphing effect, do you?

  17. #17
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    Well basically you just have 2 data DIBData arrays instead of one and then blend from one to the other. It's quite easy as long as both pictures have the same size.

  18. #18

    Thread Starter
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    Nice to hear that it's easy.... in that case I must be stupid because I can't get it to work, do you have any example code perhaps?

  19. #19
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    No but I can make one..

  20. #20
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    Here you are
    Attached Files Attached Files

  21. #21

    Thread Starter
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    Thanks a lot Fox, however it misses every forth pixel on each row so the target ends up with black vertical lines. Have a look at the attached image.
    Attached Images Attached Images  

  22. #22
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    Do you work in 24bit graphics mode? Well try adding the A component of the color (Blend function):

    VB Code:
    1. 'Get color values
    2.         With Temp
    3.             .R = (iPic1.Data(A).R * Blend1) + (iPic2.Data(A).R * Blend2)
    4.             .G = (iPic1.Data(A).G * Blend1) + (iPic2.Data(A).G * Blend2)
    5.             .B = (iPic1.Data(A).B * Blend1) + (iPic2.Data(A).B * Blend2)
    6.             [b].A = (iPic1.Data(A).A * Blend1) + (iPic2.Data(A).A * Blend2)[/b]
    7.         End With

  23. #23

    Thread Starter
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    Originally posted by Fox
    VB Code:
    1. 'Get color values
    2.         With Temp
    3.             .R = (iPic1.Data(A).R * Blend1) + (iPic2.Data(A).R * Blend2)
    4.             .G = (iPic1.Data(A).G * Blend1) + (iPic2.Data(A).G * Blend2)
    5.             .B = (iPic1.Data(A).B * Blend1) + (iPic2.Data(A).B * Blend2)
    6.             [b].A = (iPic1.Data(A).A * Blend1) + (iPic2.Data(A).A * Blend2)<b>Do you work in 24bit graphics mode? Well try adding the A component of the color (Blend function):
    7.  
    8. </b>
    9.         End With
    [/B]
    Oh yes, that did it Thanks a million Fox, this is greatly appreciated!

  24. #24
    Fanatic Member pradeepkrao's Avatar
    Join Date
    Sep 2001
    Location
    New Jersey
    Posts
    534

    Hi

    Fox thats Great..



    Do make a Tuto in DirectX7 for 2d Game..
    Learn by others experience as you cannot live long to experience them all.
    www.freewebs.com/pradeepkrao

    LOOK AT MY GAMES AT MY WEB SITE.

  25. #25
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    When the pathfinding tutorial is out I'll teach you all how to switch the "renderer" of the tile engine. In fact I mean switching from BitBlt to a DXGraphics engine. But give me some time to prepare everything

  26. #26
    Fanatic Member pradeepkrao's Avatar
    Join Date
    Sep 2001
    Location
    New Jersey
    Posts
    534

    Hi

    Sorry... but have a look at this..

    I was checking out few API's and I found this...

    VB Code:
    1. Const AC_SRC_OVER = &H0
    2. Private Type BLENDFUNCTION
    3.   BlendOp As Byte
    4.   BlendFlags As Byte
    5.   SourceConstantAlpha As Byte
    6.   AlphaFormat As Byte
    7. End Type
    8. Private Declare Function AlphaBlend Lib "msimg32.dll" (ByVal hdc As Long, ByVal lInt As Long, ByVal lInt As Long, ByVal lInt As Long, ByVal lInt As Long, ByVal hdc As Long, ByVal lInt As Long, ByVal lInt As Long, ByVal lInt As Long, ByVal lInt As Long, ByVal BLENDFUNCT As Long) As Long
    9. Private Declare Sub RtlMoveMemory Lib "kernel32.dll" (Destination As Any, Source As Any, ByVal Length As Long)
    10.  
    11. Private Sub Timer1_Timer()
    12. Dim BF As BLENDFUNCTION, lBF As Long
    13.    
    14.     Picture1.AutoRedraw = True
    15.     Picture2.AutoRedraw = True
    16.     Picture1.ScaleMode = vbPixels
    17.     Picture2.ScaleMode = vbPixels
    18.    
    19.     BF.BlendOp = AC_SRC_OVER
    20.     BF.BlendFlags = 0
    21.     BF.SourceConstantAlpha = 20
    22.     BF.AlphaFormat = 0
    23.    
    24.     RtlMoveMemory lBF, BF, 4
    25.    
    26.     AlphaBlend Picture2.hdc, 0, 0, Picture2.ScaleWidth, Picture2.ScaleHeight, Picture1.hdc, 0, 0, Picture1.ScaleWidth, Picture1.ScaleHeight, lBF
    27.     Picture2.Refresh
    28.    
    29. End Sub

    This works fine....too
    Learn by others experience as you cannot live long to experience them all.
    www.freewebs.com/pradeepkrao

    LOOK AT MY GAMES AT MY WEB SITE.

  27. #27
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    jim mcnamara already posted that snippet -.-

  28. #28
    Fanatic Member pradeepkrao's Avatar
    Join Date
    Sep 2001
    Location
    New Jersey
    Posts
    534

    Hi

    Sorry.. I dint see his post.....

    But he has not shown how to morph... (make fade effect)
    Learn by others experience as you cannot live long to experience them all.
    www.freewebs.com/pradeepkrao

    LOOK AT MY GAMES AT MY WEB SITE.

  29. #29
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    The problem was that this call doesn't work for older Windows.

  30. #30
    Fanatic Member pradeepkrao's Avatar
    Join Date
    Sep 2001
    Location
    New Jersey
    Posts
    534

    Hi

    Yeah Fox..

    By the way when are you making Directx7 article....
    Learn by others experience as you cannot live long to experience them all.
    www.freewebs.com/pradeepkrao

    LOOK AT MY GAMES AT MY WEB SITE.

  31. #31
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    As mentioned in another thread: Right after the path finding tutorial I'll show you how to switch the renderer of the sample engine form BitBlt to DX8. I'm currently working on the path finding tutorial but this may take me the week-end to finish.
    Last edited by Fox; May 16th, 2003 at 07:55 AM.

  32. #32

    Thread Starter
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    I hope nobody minds if I close this thread..... I'm very gratefull to those who has helped me but the discussion of different tutorials should probably be discussed in another thread

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