The original understanding of fillrectangle is incorrect.

Source: Internet
Author: User
Today, a friend asked me that when he used fillrectangle to draw an image to a form, he always misaligned and did not know what was going on. Take me Code Let's take a look at the Code as follows:

Private   Void Drawtitle_right (Graphics g)

{

Image img = Files. getimage ( " /Images/top_right.gif " );

Brush =   New Texturebrush (IMG );

G. fillrectangle (brush, This . Clientsize. Width - IMG. Width, 0 , IMG. Width, IMG. Height );

}

But why is it misplaced? After debugging for half a day, the result is the same as that of his experiment. The use of drawimage will not be a problem. After looking at the dislocation pattern for half a day, we found that:

"Fillrectangle is to fill in a graphics and then display the part specified by rectangle ."

Assume that the image size is the size of graphics. Fillrectangle fills the graphics in mosaic mode, and then draws the rectangle specified by rectangle. (Of course, the actual implementation may not be like this, but the effect is like this. Let me remember that when I was a child, I used my mom and I used my photo in the dark room to wash my 1-inch photos with 5-inch extension paper through a small window ^ & ^ ).


When the rect specified by fillrectangle exactly matches the image in getimage, the display is normal. If they do not match, the system will be misplaced. I have always understood this as follows:

"Fillrectangle is a rectangle with a specified image filled with coordinates at (x, y), width, width, and height ."

There are still discrepancies (this is the sequent Effect of Delphi! -_-!).

summary
after reading replies from friends, I looked back at my own articles.
I do not think it is so clear. Use the code to prove everything: Download the Code

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.