In. NET Framework, the graphics. drawimage method is generally used to draw images. However, this method has obvious defects in many cases.
The preceding figure shows the two effects of a graph. On the left side is the display effect of Windows thumbnails, and on the right side is the display result of calling the drawimage method. The source image is in TIFF format. The size of the source image is 3185*2276,300*300 dpi, and the size of the image file is kb. We can see that there is a significant difference between the two display effects. This is because drawimage uses the default algorithm to reduce the proportion of images, resulting in serious distortion of the graphic display.
A more serious defect is that the drawimage function is almost completely incapable of Drawing Images of larger formats. In the test, a width of 13290*9600,400*400 dpi is used, a tiff file with a size of MB. When the drawimage function is run, all of my local virtual memory is consumed, and the entire system is in a unresponsive state!
For the above reason, the drawimage method provided by. NET Framework is no longer available when drawing large images. In a program I recently developed, I re-developed a C ++ dynamic link library to complete large-scale image rendering. The display effect and speed were excellent! C ++ draws a function prototype:
1 extern "C" Void highspeeddraw (HDC, int srcleft, int srctop, int srcright, int srcbottom,
2 int dstleft, int dsttop, int dstright, int dstbottom)
3 {
4 CDC * PDC = CDC: fromhandle (HDC );
5 crect srcrect (srcleft, srctop, srcright, srcbottom );
6 crect dstrect (dstleft, dsttop, dstright, dstbottom );
7 pdrawengine-> draw (PDC, dstrect, srcrect );
8}
Packaging in C:
1 [dllimport ("hsdraw. dll")]
2 Private extern static void highspeeddraw (intptr HDC, int srcleft, int srctop, int srcright, int srcbottom,
3 int dstleft, int dsttop, int dstright, int dstbottom)
OK. You can call the paint function as follows:
1try
2 {
3 checked
4 {
5 intptr HDC = E. Graphics. gethdc ();
6 highspeeddraw (HDC, sourcerect. Left, sourcerect. Top, sourcerect. Right, sourcerect. Bottom,
7 targetrect. Left, targetrect. Top, targetrect. Right, targetrect. Bottom );
8 E. Graphics. releasehdc (HDC );
9}
10}
11 catch (exception ex)
12 {
13 graphics. drawstring (ex. tostring (), new font ("Arial", 8), brushes. Red, new pointf (0, 0 ));
14}
The following figure shows the effect of using the C ++ rendering algorithm:
We can see that the new algorithm is very effective. In addition, the original use of drawimage causes the system to fail to respond to the TIFF file. Now it takes less than 1 second to draw images, and the memory consumed by Image Rendering also drops below 20 mb. The effect has been significantly improved.