Click to See Complete Forum and Search --> : Performance when processing with image !


tam.hh
December 21st, 2006, 08:11 PM
I have a program about processing image (use MDI architecture)
The function is very simple : Choose image from a File Dialog, draw it in view, select it, move it, change attribute for it ( transparent, brightness).
But it run slowly, maybe because when there are any change in view, it will be redrawn. To avoid flash, when redraw, i draw in newDC, then stretch it to originalDC.
Help me with this proplem, may you have some idea to increase performance when processing with image. Thank you !

Metaspace
December 22nd, 2006, 03:39 AM
First I suggest you use GDI+ for bitmap operations, if you do not do so already (depends on your platform an programming language really, but you did not specify them...do so next time!)

Generally, use a Bitmap object for your original image (which you load into it), and a second the size your view currently has; recreate the second bitmap with appropriate size everytime the view resizes, and stretch the first bitmap into the second. In your view's OnDraw handler (or likewise), draw the second bitmap into the DC.

When transparency or other image attributes change, directly modify the second bitmap, then force invocation of your OnDraw handler.

BTW, an efficient way to change transparency using GDI+:

float fBlend = (100 - (float) iTransparency) / 100;
ColorMatrix BitmapMatrix = {
1.0f, 0.0f, 0.0f, 0.0f, 0.0f
, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f
, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f
, 0.0f, 0.0f, 0.0f, fBlend, 0.0f
, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f
};
ImageAttributes ImgAttr;
ImgAttr.SetColorMatrix (&BitmapMatrix, ColorMatrixFlagsDefault, ColorAdjustTypeBitmap);
m_pMemGraphicsRaster->DrawImage ( pBitmap
, rectDestination
, (float) 0
, (float) 0
, (float) pBitmap->GetWidth ()
, (float) pBitmap->GetHeight ()
, UnitPixel
, &ImgAttr
);

(m_pMemGraphicsRaster is a 'Graphics' object created based on the second bitmap - see 'Graphics' class constructors)

Hope to have helped you.

tam.hh
December 23rd, 2006, 03:39 AM
Thank you !
But i have used this way. The question i want is "How can i take more performance when processing with image". If use this way, the speed is slow.
How can i make image have smaller pixel, smaller quality.... to get more speed... Or what else solution...