|
-
Nov 15th, 2000, 05:31 AM
#1
Thread Starter
Fanatic Member
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
-
Nov 15th, 2000, 06:00 AM
#2
Lively Member
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
-
Nov 15th, 2000, 06:53 AM
#3
Addicted Member
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
-
Nov 15th, 2000, 07:25 AM
#4
Thread Starter
Fanatic Member
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
-
Nov 15th, 2000, 07:45 AM
#5
Thread Starter
Fanatic Member
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
-
Nov 15th, 2000, 07:58 AM
#6
Addicted Member
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
-
Nov 15th, 2000, 08:47 AM
#7
Thread Starter
Fanatic Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|