GDI + mine area

xiaoxiao2021-03-05  50

GDI mine area

2005-4-22

In the thousands of contenders, Microsoft finally launched the next generation of next-generation graphics program interface GDI , and became the DOTNET graphics, which can also be an old age. When several batches of the Warriors who gave Microsoft, everyone began to find GDI , it was a chicken rib, and it was inert, and unfortunately.

Thunder area: slow speed

There are many people who should have noticed, not general slow. It is useless to find Microsoft and MVP. There are two reasons for the root cause, one is GDI currently do not use hardware acceleration. It is accurately that the GDI-based part is accelerated by GDI, and other parts are pure CPU calculations; It is a problem with the algorithm, such as a typical drawing diagram, the plotted speed and source bit map size, notice that the size of the actual plotted part is related to the total size of the source. That is to say to draw 128x128 bitmap and draw a 128X128 part of the 1024x1024 bitmap. These two methods are only 128x128, but the speed has a good day, this problem is discussed in many forums, everyone can't understand can't accept , I have to use GDI. Don't think that this is not using MSDN and those MVP optimization suggestions, you can try it yourself.

Ray: failure package

The best place for DOTNET is to provide an excellent design, unified API, but the GDI package part is something in the system.drawing name space, but it has failed. The core advantage of DOTNET is garbage collection, and the pure memory data object is not needed. It does not need to be worried about its living period, not only simplifying memory management, but also makes the bad API interface that must be allocated for the return value of the function to become the past, which can be Provide functions that are intuitive and easy to use without performance loss. According to the spirit of garbage collection model, it should be encouraged to encourage objects of Dispose. But the class in the Sytem.Drawing names is almost all of the needs of Dispose, even MATRIX and STRINGFORMAT do Dispose. Correct the reason, that is, these classes do not provide DOTNET implementation, but the pointers of the packaged GDI objects, which saves them to development, but gives us endless trouble, and is in compatibility, the later version is also It is difficult to remove that IDisposable interface from those classes.

The worse is that Microsoft's sample code does not drop with Dispose, which looks very clear and simple, but it is necessary to have a group of MVPs to persuade must be Dispose. I know its internal implementation, each programmer will consider it should be Dispose as soon as possible, not other garbage collection, because the garbage collector does not know how much memory accounting, how many system resources are occupied . Programmers who write DOTNET controls often encounter IDE slower or even reporting resources, there is too many GDI objects without release. And MSDN can not teach people Dispose, even the Bitmap object is not!

I know that I should Dispose, then DISPOSE.

Pen Blackpen = New Pen (Color.Black, 3);

E.Graphics.drawline (Blackpen, X1, Y1, X2, Y2);

Blackpen.dispose ();

This line, no! Drawline may be leveled, so Blackpen is still not released, so

Pen Blackpen = NULL;

Try {

Blackpen = new Pen (Color.Black, 3);

E.Graphics.drawline (Blackpen, X1, Y1, X2, Y2);

Finally {

Blackpen.dispose ();

}

Fortunately, Uisng is available in C #, which can be simplified

USING (Blackpen = New Pen (Color.Black, 3)) {

E.Graphics.drawline (Blackpen, X1, Y1, X2, Y2);

}

But a GDI object is ok, 10 What should I do, but in the drawing program more than these, do you have (...) using (...) ... ?? This code can also be read?

So everyone can only break the tank and crack down, and the little thing will do this.

Thunder area 3: and not interactive efficiency

Due to speed problems, everyone can only help with GDI, think that GDI provides a lot of functions with GDI interaction, just like you have to know that you have such a day. It is not right, because most of it is copying a generated GDI object, and the GDI is completed and copied. It's really a tear.

Ray 4: Also provide new accelerated graphics, what else do?

As Joel said, Microsoft now keeps a variety of new APIs, and will give up the old alternatives and give up the old, and the programmer is a nightmare. The old problem does not resolve, and use new replacement, then bring a bunch of new problems, then replace it out. If it is not necessary, don't be too big in GDI .

in conclusion

Of course, there is no perfect thing in the world, although there are many defects, GDI features are still very attractive, and it is still very useful if it is not high. Here is a few major mine areas of GDI , I hope everyone should not sacrifice in the thunder.

转载请注明原文地址:https://www.9cbs.com/read-32865.html

New Post(0)