Hello everybody,
I am C#/.NET newbie.
I have been tasked to write a graphics application using C#.
The application needs to visualize an image that is narrow and very
long. Typically images have width=1024 pixel and height= 40000 pixel.
Of course is impossible to completely visualize such an image on the
screen, so the standard solution (in this type of applications) is to
visualize only a part of the image (all the columns, but only some
rows) on a control.
Two buttons will be available "scroll up" and "scroll down" and
employing a timer the image will scrolls up or down automatically.
At the moment I implement this keeping a rectangle object that is
shifting up or down every timer tick. The timer tick is 125 ms, and the
vertical shift is about 50 pixels, so a big part of the image is just
moved on the screen up or down, while only a small part of the image is
actually new data. At the moment when I need to paint I do something
like the following (I re-draw all the image every time):
dc.InterpolationMode = InterpolationMode.NearestNeighbor;
Point ulCorner = new Point(10, 100);
Point urCorner = new Point(this.Width-10, 100);
Point llCorner = new Point(10, this.Height);
Point[] destPara = {ulCorner, urCorner, llCorner};
dc.DrawImage( myImage, destPara, box, GraphicsUnit.Pixel);
where box is the shifting rectangle.
The performance are acceptable, but I would like to know if is possible
to do something better. The followings are just two ideas, your
recommendations would be very appreciated (also new ideas are welcome):
1. In the timer tick event handler is possible to capture the image
that is already on the screen and shift it down or up, than add (draw)
only the new part. Would this bring a performance improvement? If yes
how would you do that?
2. At the moment myImage (that is 1024*40000) is completely allocated
in memory using PixelFormat.Format32bppPArgb, even if the image in 8
bit per pixel grayscale. I changed to Format32bppPArgb because using
Format8bppIndexed (I don't understand because 8bppGrayScale doesn't
exists) the performances are really bad. Of course having such image
with 32 bit per pixel completely in memory wastes a lot of space
(around 160 Mb memory allocated). Would be possible inside the onPaint
event to crop only the part of the image I need to draw convert it to
32 bit per pixel on the fly and draw it? If yes how would you do that?
Any new idea would also be greatly appreciated!!!
Thanks a lot
JocK
SharpCoderMP - 28 Oct 2005 16:16 GMT
a'm afraid that doing all the stuff you'd suggested is not a good idea
for c#/.net ... but i may be wrong :) there is quite powerfull freeimage
lib that may help you with perfomance but as far as i know its .net
version is just a wrapper for unmanaged code and also, using it
introduces some difficulties.
> Hello everybody,
>
[quoted text clipped - 46 lines]
> Thanks a lot
> JocK