Question "skew" image

Thonord

Member
Joined
Oct 25, 2012
Messages
23
Programming Experience
10+
I'm trying to "slant" a bitmap.
Not rotate as in RotateTransform.

Let me explain using an italics font as an example. The font is slanted at an angle, but horisontal elements remain horisontal, no matter how much the vertical elements are angled. (Look at the letter "t" in italics. The crossbar remains horisontal).

Thank to you guys, my bitmap is in a single dimension array, using LockBits and MarshalCopy. (WOW, speed is impressive)

I have found several ways that works
One is converting the contents of each stride into a string, Mid'ing the chars(bytes) into place and "Byte'ing it back to the array. Simple but slow. (Slow as in 1500 ms +)
Another is processing each byte within a stride in a "bubblesort" kind of way. Not sorting them, but shifting the "bytes of interest" the required number of Bytes down the stride. Simple, but even slower? (My code here may be extremely ineficient)

Both are also so .NET Not!

What I'm looking for, in the spirit of transforming into a .Net programmer (and wanting more speed) is something like SkewTransform(angle as integer).

Merry x-mas and a happy new year to all.
Espescially to the gentle wizzards, who share their wisdom so willingly.
 
You can do this with Graphics.DrawImage method, look at the overloads that take a Point array as parameter where you specify three points of a parallelogram.
 
And it was:)

Found this in msdn:


Public Sub DrawImagePara(e As PaintEventArgs)' Create image.Dim newImage As Image = Image.FromFile("SampImag.jpg")' Create parallelogram for drawing image.Dim ulCorner As New Point(100, 100)Dim urCorner As New Point(550, 100)Dim llCorner As New Point(150, 250)Dim destPara As Point() = {ulCorner, urCorner, llCorner}' Draw image to screen.e.Graphics.DrawImage(newImage, destPara)End Sub

Oopss!
Obviously I need to learn formatting here - however I digress.

Works fine, when I, as usual, just use the "body" sample Sub's code, writing my own sub or func, provide my own graphics object etc. etc.

However, attempting autodidactism, (paraphrasing the Beatles: "with a "lot" of helpl from my friends") - I'm sure there is a bunch of really noob elementary stuff I don't know about. (Like e)

So, out of curiosity, how the heck do I run the sample above "streight out of the box"?

It's a Sub. It needs a parameter, a PaintEventArgument.

Whose PaintEventArgs? Whose somewhat mysterious (e.)?

I try throwing various e.'s at it but all I get is "this is a system argument - Dumbass!"

This is not an important question, just part of my learning curve, and I know the right answer: " Read the book you Twirp!", but a hint will be greatly appreciated.
 
That sample is intended to be called from some form/controls Paint event handler. That is also what it says in help page:
The following code example is designed for use with Windows Forms, and it requires PaintEventArgs e, which is a parameter of the Paint event handler.
 
When an event is fired, it carries with it a reference to the originating object (sender), and an EventArgs object (e). E contains specific information about the event that was fired, and is always of a type inheriting from the EventArgs type. In this case the type is PaintEventArgs, and its purpose is to carry the Graphics object used to paint, and the GDI ClipRectangle for the area painted.

Note that neither parameter is mandatory for custom events, you could very well have an event that fires carrying nothing at all, but it is the recommended way of passing the data.
 
Back
Top