Results 1 to 7 of 7

Thread: Resizing and rotating gifs

  1. #1

    Thread Starter
    Fanatic Member r0ach's Avatar
    Join Date
    Dec 1999
    Location
    South Africa
    Posts
    722

    Unhappy

    Hi,

    I want to resize a gif image to fit into a picture box, and turn it upside down. How can i do this?

    r0ach™
    Don't forget to rate the post

  2. #2
    Lively Member
    Join Date
    Sep 1999
    Location
    Liverpool, UK
    Posts
    64
    from vbsquare...

    Code:
    '// Make a New project. Add a module. To the form Add two picture boxes And a Command button.
    
    '// Code:
    '// Add this code To the module:
    
    Declare Function SetPixel Lib "gdi32" Alias "SetPixelV" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal crColor As Long) As Long
    Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
    
    '// Add this code To the form's General Declarations procedure:
    
    Public Sub rotateimage()
    	Dim x As Long
    	Dim y As Long
    
    	Picture2.Height = Picture1.Width
    	Picture2.Width = Picture1.Height
    
    	For x = 0 To Picture1.Width
    		For y = 0 To Picture1.Height
    			Call SetPixel(Picture2.hdc, y, x, GetPixel(Picture1.hdc, x, y))
    		Next
    			If x Mod 50 = 0 Then
    			DoEvents
    
    			Picture2.Refresh
    
    			End If
    
    	Next
    
    	DoEvents
    
    	Picture2.Refresh
    
    End Sub
    
    '// Add this code To the Command button:
    
    Private Sub Command1_Click()
    	Call RotateImage
    End Sub

  3. #3
    Addicted Member Shrog's Avatar
    Join Date
    Aug 1999
    Location
    Darkest Africa
    Posts
    186

    Cool PaintPicture

    There is another way - use the PaintPicture method.

    Most controls with a graphic device context (hdc) has the PaintPicture method. That ioncludes Forms and PictureBoxes.

    You simply pass it the picture and the coordinates and it renders the picture at that position on the control or form.
    Code:
      'Place the picture in the top left corner of the picturebox
      Call picTest.PaintPicture(MyPicture, 0, 0)
    But it has some hidden powers: By specifying the width and height, you can stretch or shrink the picture to fit the box.
    Code:
      'fill the box with the picture
      Call picTest.PaintPicture(MyPicture, 0, 0, picTest.Width, picTest.Height)
    By setting the x/y coordinates to the bottom right corner of the picture box, and the width and height as negative numbers, it flips the picture AND stretches it.

    If you want to flip it only horizontally, make the width negative. For vertical, make the Height negative.

    Code:
      'stretched and upside down
      With picTest
        Call .PaintPicture(MyPicture, 0, .ScaleHeight, .ScaleWidth, -.ScaleHeight)
      End With
    Hope this helps.
    Shrog



  4. #4

    Thread Starter
    Fanatic Member r0ach's Avatar
    Join Date
    Dec 1999
    Location
    South Africa
    Posts
    722
    Thanx.

    Shrog's method worked better for my purpose, because the setpixel thing was just too slow. I needed BitBlt speed.

    Thanx guys!

    r0ach™
    Don't forget to rate the post

  5. #5

    Thread Starter
    Fanatic Member r0ach's Avatar
    Join Date
    Dec 1999
    Location
    South Africa
    Posts
    722
    OK. Another thing.
    The transparent parts of the original gif, is now magenta in the copied pic. Any way around that?

    r0ach™
    Don't forget to rate the post

  6. #6
    Addicted Member Shrog's Avatar
    Join Date
    Aug 1999
    Location
    Darkest Africa
    Posts
    186

    Unhappy oh-oh..

    Alas, no. The moment you "re-draw" the picture, it is not a gif any more, and you lose the transparency.

    There are ways around this, but they are not simple and they are not fast. VB does not actually cater for transparency very well. Sorry.

    Shrog

  7. #7

    Thread Starter
    Fanatic Member r0ach's Avatar
    Join Date
    Dec 1999
    Location
    South Africa
    Posts
    722

    solution!

    Never Mind...
    I made a mask, and my Dest Pic's BGColor black.
    Then I copied Src to Dest using vbSrcInvert (oh. Src's BGColor = White) and the copy mask to Dest using vbSrcAnd.

    Works perfectly

    r0ach™
    Don't forget to rate the post

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