or ordinary two-dimensional graphics processing (vector, bitmap rotation)

Source: Internet
Author: User
Tags asin sin cos

Simple 2D image processing under C # This is nothing to say. I do not do the image processing of the serious work. In order to work a day to write the data platform business code, in fact, most of these things are not used. Out of the gate so long the high school of those sin cos vector is why do not use. Do the image processing found that Wow is used to the original math so interesting and even use some college math knowledge. In the world of mathematics, computer programming languages are just tools. You also have the same algorithm in C + + java. First of all, I want to talk about nothing technical content. Actually, these things are in most image libraries. Here is just a concise mention of his principles can do what, if the library does not own it if in the kind of slash-and-burn embedded device platform code is the test of your time to the. But under the Windows platform under the mature big platform this kind of test your opportunity is unlikely. Mature large platform software development of a variety of externally available to call things a lump of a lump is writing business code also has no technical content. I write the basic things to the beginning of the BB, although there is no skill, do not shoot bricks. Good point.

Vector computation and its application

1 //the declaration of a vector:2 //vectors and points are represented by coordinates, but their meanings are fundamentally different.3 //vectors and points can be forced to convert each other in C #4 //(WPF uses vector WPF with many libraries that have been duplicated in the original WinForm mode, and WPF is making wheels5Vector v1 = (vector)NewSystem.Windows.Point (1,0);6Vector v2 = (vector)NewSystem.Windows.Point (0,1);7 8System.Windows.Point P1 = (System.Windows.Point)NewVector (1,0);9 Ten  One //the operation of the vector: A //The basic way is x+x y+y don't say more - //In fact, the addition of two vectors has no definite geometrical meaning, and the addition of dots and vectors represents one point moving to another. - //High School has learned two vectors add up is a new vector the //Vector overloads the + operator so that the vectors can be calculated between points and vectors, just like in high school math . - //the value of the vector v3 is not the same as the high school; -Vector V3 = v1 +v2; -MessageBox.Show (string. Format ("X={0},y={1}", v3. X, v3. Y)); + //minus a vector equals a vector in the opposite direction the output value is v4 (0.5,0.5) -Vector v4 = v3-NewVector (0.5,0.5); +MessageBox.Show (string. Format ("X={0},y={1}", v4. X, v4. Y)); A  at  - //what you can do with vectors: - //there's a chapter in high school math, remember? Use vector arithmetic to detect whether two straight lines are parallel or not perpendicular.  - //three-dimensional space normal calculation you can use this principle - //I think in the game, engineering calculations, these places are going to use your imagination.

The diagram used in the WPF self-study manual is then the vector, which is only available in WPF, and of course you can do it yourself with point.

Then there is the rotation of the bitmap image:

This understanding is slightly more complex, or first

This kind of thing I speak pure words can not necessarily achieve the effect.

The concrete theory takes full advantage of the trigonometric functions R is the radius of the coordinates (0,0) to the specific point.

First look at R*sin (Alpha + theta) here (Alpha + theta) is the angle of that big angle.

Sin (alpha + theta) is the opposite Edge/R, and if multiplied by R then does not exactly equal the length of the edge, that is, the Y value of the point.

Here sin (alpha + theta) needs to take advantage of trigonometric function and angular formula sin (a+b) = Sinacosb+cosasinb.

Of course, you don't have to, don't hit me.

It is also necessary to use the ASIN function in the same trigonometric functions as the inverse of the sine to seek the angle. Anyway, just get a few parameters in the diagram to set the formula.

Through this kind of various means can be the image of all the rotated points to achieve the purpose of rotating pictures.

In fact, the figure has been given out, and then each point in turn to calculate it.

1 voidrotate ()2 {3     //Rotate4 5     /*6 * Matrix Information7 * cos& sin&8 *-sin& cos&9      */TenSystem.Drawing.Bitmap bmp = (Bitmap) System.Drawing.Image.FromFile ("tulips.jpg"); One  ASystem.Drawing.Bitmap BMP2 =NewBitmap ((int) (BMP. Width), (int) (BMP. Height)); -  -      for(inti =0; I < BMP. Height; i++)//Row the     { -          for(intj =0; J < BMP. Width; J + +)//Col -         { -             //get raw RGB +System.Drawing.Color Sourcergb =bmp. GetPixel (J, i); -             //using matrix operations to new coordinates +             DoubleR = Math.sqrt (Math.pow (j, 2f) +Math.pow (i, 2f)); A             DoubleAlpha = Math.asin (I/R); at             DoubleXita = Math.PI/6; -  -             intX1 = (int) ((R * MATH.COS (Alpha) * Math.Cos (Xita))- -(R * Math.sin (Alpha)) *(Math.sin (Xita))); -  -             intY1 = (int) ((R * Math.sin (Alpha) * Math.Cos (Xita)) + in(R * Math.Cos (Alpha)) *(Math.sin (Xita))); -  to             if((X1 >=0&& X1 < BMP2. Width) && (y1 >=0&& Y1 <BMP2. Height)) + BMP2. SetPixel (x1, y1, Sourcergb); -         } the     } *  $Bmp2. Save ("22.jpg", imageformat.bmp);Panax Notoginseng}

Here the Xita is the angle double xita = MATH.PI/6; On behalf of 30 degrees we look at the results:

Displacement and stretching those I think the principle is too simple I won't talk about it.
I wish you all a pleasant weekend.

or ordinary two-dimensional graphics processing (vector, bitmap rotation)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.