Image offset when texturebrush is used.

Source: Internet
Author: User

Recently, texturebrush in GDI + is used. However, when fillrectangle is used, there is always an offset problem, for example, the following:

The original video clip should be:

The following is my source generation. I will analyze the cause and solution of this problem step by step.

Image logo = image. fromfile ("your picture path ");
Texturebrush BR = new texturebrush (logo );
Graphics G = This. creategraphics ();
G. fillrectangle (BR, 22, 29, 20, 20 );

The cause is 22, 29 in G. fillrectangle (BR, 22, 29, 20, 20. Originally, I think 22 and 29 are used to determine the corresponding position (x, y) of the image to be displayed in the form, but when texturebrush is used (22, 29). The exact position is not specified, and the offset of the split is determined. If you convert it into another number, the offset of the video segment will change. Set G. fillrectangle (BR, 22, 29, 20, 20); change to G. fillrectangle (BR, 0, 0, 20, 20); The Cursor Image is normal, but its position is (0, 0 ), so I guess it is correct.

Solution:

Image logo = image. fromfile ("D: // epon_ EMS // image // green.png ");
Texturebrush BR = new texturebrush (logo );
BR. translatetransform (22, 29 );
Graphics G = liu1.creategraphics ();
G. fillrectangle (BR, 22, 29, 20, 20 );

Add a Br. translatetransform (22, 29); That's OK. translatetransform is used to offset the starting position of the original portrait, so that we offset it first, then, in fillrectangle, it was offset again, so the order was reached our goal.

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.