GDI+ Transforms
GDI+ Transforms
GDI+ Transforms
GDI+ Transforms
GDI+ Transforms
GDI+ Transforms GDI+ Transforms GDI+ Transforms GDI+ Transforms GDI+ Transforms GDI+ Transforms GDI+ Transforms GDI+ Transforms
GDI+ Transforms GDI+ Transforms
GDI+ Transforms
Go Back  Xtreme Visual Basic Talk > > > > GDI+ Transforms


Reply
 
Thread Tools Display Modes
  #1  
Old 08-13-2004, 08:03 AM
Iceplug's Avatar
IceplugGDI+ Transforms Iceplug is offline
MetaCenturion

Retired Moderator
* Guru *
 
Join Date: Aug 2001
Location: Iowa, USA
Posts: 16,583
Cool GDI+ Transforms


The Transforms of the GDI are a very powerful way to manipulate your images.
You can have them spin, shrink, and warp in any way you want them to.

There are also the similar Matrix transforms that you can get when you apply a matrix to the Graphics object transform.

Just looking at the the graphics object transforms today, there are four Transform subroutines of the Graphics object that will be of the most interest:

GFX.TranslateTransform(dx, dy)
GFX.ScaleTransform(sx, sy)
GFX.RotateTransform(angle)
GFX.ResetTransform()


The Graphics object that has been created is aimed at something... typically a picturebox or a form, although an image is fine as well.
Now, each of the transforms will move this Graphics object *aim* in several ways, according to the transform.

The aim begins and resets at the upper left corner 0,0.
This is where the aim will be after you have called ResetTransform.
GFX.ResetTransform()
The crosshairs represent where 0,0 is, although you can't see them in the picture.
GFX.DrawImage(cubec, 0, 0)
Let's say that this draws the blue cube (the upper left corner will indicate where the imaginary crosshairs are when you are drawing in VB.NET).

GFX.TranslateTransform(dx, dy)
This one lets you move the point where 0,0 is. Although, it isn't terribly useful by itself (as you can tell where you want to draw the image), it works well with other transforms to make combination effects (discussed later).
The 1st figure below represents a TranslateTransform(40, 32), where the crosshair moves 40 pixels left, and 32 pixels down, and respectively the image will be drawn here afterwards.

Note that if you draw the image before you translatetransform, the image will still be located in the upper left corner (0, 0) of the form or picbox.
Drawing after the translatetransform makes the image appear at 40 32 on the form/picbox.

GFX.ScaleTransform(sx, sy)
This one, more useful than Translate, lets you stretch the aim in the X and Y direction by a specified multiplier. (2f means doubled, 3f means tripled, -1f means flipped over)
A ScaleTransform(2f, 2f) will simply 2x the image, while ScaleTransform(2f, 1f) will make the image 'double-wide', but the same height.
If any parameter is zero, the image will disappear. Using(-1f, 1f) will flip the image horizontally. Using(1f, -1f) will flip it vertically. And Using(-1f, -1f), a double flip, will flip it horizontally and vertically, equivalent to a 180 degree rotate (more on rotation coming soon).
My f's that appear after the number represent singles (floats)... use these so your result is interpreted as a single.
The 2nd figure below represents
GFX.ResetTransform()
GFX.ScaleTransform(0.5f, 1.5f)

Note that if you don't reset the transform and use the same graphics object, the transforms will multiply together, meaning that the picture will be translated and then scaled, as in the 3rd figure.

GFX.RotateTransform(angle)
My favorite. This lets you rotate the aim (clockwise, unless you've flipped it with a ScaleTransform) by an amount in degrees. Notice that it is in degrees... not radians.
The 4th figure below represents
GFX.RotateTransform(45f)
(And Paint won't let me rotate by 45 degrees... hopefully it's obvious though--the picture is rotated clockwise around the crosshair by 45 degrees)

Once you get these, you should be able to make lots of neat effects.
Remember to reset the transform if you don't want the transforms to multiply, and have fun.

Hint: To draw a picture centered on the crosshair:
GFX.DrawImage(bmp, -bmp.Width \ 2, -bmp.Height \ 2)

As usual, if you are using 7.0, the .vb file is all you need.
Attached Images
File Type: gif t2.gif (1.8 KB, 131 views)
File Type: gif t3.gif (1.8 KB, 89 views)
File Type: gif t4.gif (1.9 KB, 78 views)
File Type: gif t5.gif (1.8 KB, 82 views)
Attached Files
File Type: zip MatrixLoaded.zip (8.1 KB, 339 views)
__________________

Iceplug, USN
Quadrill 1 Quadrill 2 (full) Quadrill 3 JumpCross .NET Website is ALIVE! - DL Platform Tour for VB.NET! Posting Guidelines Hint: Specify your location in your user cp profile if you want compassion!
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
GDI+ Transforms
GDI+ Transforms
GDI+ Transforms GDI+ Transforms
GDI+ Transforms
GDI+ Transforms
GDI+ Transforms GDI+ Transforms GDI+ Transforms GDI+ Transforms GDI+ Transforms GDI+ Transforms GDI+ Transforms
GDI+ Transforms
GDI+ Transforms
 
GDI+ Transforms
GDI+ Transforms
 
-->