How to mimic rendering of Picasa images with reduced quality to speed up drawing

I have an owner-driven control where performance is a problem during quick reviews such as dragging and dropping objects, resizing and drawing the selector square. I noticed that several other applications, including Picasa , will temporarily draw a low-quality image during quick redraw scenarios, and then update the image with a better version when the user interface "settles".

How can I (can I?) Create a lower quality image for drawing when there are many quick redraws? Are there other strategies like this that I can use to increase performance (or fake increased performance).

Additional Information:

This application is similar to the design of forms, which heavily uses the drawing of the owner. It works well, but it gets scared when more than three or four images need to be drawn in rectangles in the client area. (End users are allowed to create various types of elements from which images occupy the largest losses in drawing.)

I use the DrawImageUnscaled GDI + method to draw images that should be much more efficient than DrawImage, but performance profiling shows that DrawImageUnscaled is still a bottleneck. I think my only way out is to come up with smart ways to attract less.

PS The previous question related to this question earned me the Tumbleweed badge, so I use a different approach: How to increase performance compared to DrawImage (Unscaled) GDI?

+7
performance c # gdi +
source share
1 answer

Wait - you missed a piece of low-hanging fruit here. They probably don’t redraw the image at all during the resize operations. They can resize an existing image in video memory using StretchBlt, which can be optimized by the video driver / hardware to be very fast, faster than you could ever “redraw image with reduced quality”.

Strategy:
- object objects have a member variable for the last position / size (rect)
-repaint image object attracts full-fledged quality -repaint image updates last position
when dragging, do the following:
* StrechBlt from last position / size to current position / size
* Update last position / size
* If more than a few seconds. drawing and / or> .2s from the moment you last moved the mouse, call redrawing (and not just invalid - you want NOW) to get a new full-quality image. Also, if you find overlapping with other objects (also get StrechBlt'd)

The example code that I use in an application that does something similar (the zoom effect, which has a window size that can contain 100 objects), looks just like an ipad daemon):

Declare Function StretchBlt Lib "gdi32.dll" _ (ByVal hdcDest As IntPtr, _ ByVal nXOriginDest As Integer, _ ByVal nYOriginDest As Integer, _ ByVal nWidthDest As Integer, _ ByVal nHeightDest As Integer, _ ByVal hdcSrc As IntPtr, _ ByVal nXOriginSrc As Integer, _ ByVal nYOriginSrc As Integer, _ ByVal nWidthSrc As Integer, _ ByVal nHeightSrc As Integer, _ ByVal dwRop As Int32) As Boolean Using g As Graphics = f.pb.CreateGraphics ' parm of True says draw plain view - no text = looks bad Zooming. f.DrawAll(g, True) For i As Integer = iSteps To 1 Step -1 Dim HDC1 As IntPtr = g.GetHdc Try ' Size of bite will not be right, but by re-adjusting ' with each iteration, it will make it to full-screen. ' Looks as good as having it right to start with, only much easier. TopBite = objTop \ i BottomBite = h - ((h - objBottom) \ i) ' Stretch/move the stuff. StretchBlt(HDC1, 0, 0, w - LeftBite, h, _ HDC1, LeftBite, TopBite, w - LeftBite, BottomBite - TopBite, 13369376) ' Calculate where MyEntry would be after each stretch. Then the Bite ' size calcs above will ensure its closer next time. SimulateStretch(objTop, objBottom, TopBite, BottomBite, h) Finally g.ReleaseHdc(HDC1) End Try ' Clear exposed/invalid area to the right. g.FillRectangle(br, w - LeftBite, 0, LeftBite, h) ' Sleep will make Swells close in duration between small/big window. ' (Can I actually sleep this short of a time?) System.Threading.Thread.Sleep(5) Next End Using 

Of course, if someone changes this itti-bitted image and then creates a backup, it will be super-low quality and pixelated, so you can use a smarter algorithm to sometimes run the real onpaint during mousedrag if you don't resize it.

note that the nuts and bolts of this will depend on the particular implementation. You need to give more detailed information about your application so that I can understand it correctly (what does it look like?) I accept a large usercontrol square with a lot of controls that all change the same way. IF you start them small and resize them so that they begin to overlap, you will have to periodically perform a full redraw more often during mouse resizing operations.

+3
source share

All Articles