Click here to Skip to main content
15,891,828 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,

I am trying to figure out the best and fastest way to display image parts which are derived from a large set of data.

Currently I have a picturebox with scrollbars and the application calculates and plots only the image needed within the picturebox dimensions. For additional speed I am using Lockbits and a parallel For loop in the image construction. It works very well as-is, but there is some lag while the program redraws if the user drags the scrollbars.

I have used applications in the past that are more responsive. I guess they must cleverly re-use known image parts and also may have pre-made tiled images ready for the user if they drag the scrollbars.

I'd like to implement something similar if possible but I'm not sure of the best way to go about it.

Could I ask if anyone can kindly offer any suggestions on a good method ?

Many thanks.
Posted
Comments
Sergey Alexandrovich Kryukov 24-Jan-15 15:51pm    
Without detail explanation of how images should be built from data, this post is pointless, not informative.
—SA

1 solution

Here is a hint:

To copy a part of the image onto another image, use System.Drawing.Graphics.DrawImage:
https://msdn.microsoft.com/en-us/library/system.drawing.graphics.drawimage.aspx[^].

Note that the methods which accept the target rectangle will perform re-sampling of the image to be copied, if source and target rectangles sizes are different, which is a considerable performance hit; and the image quality may be compromised. Avoid them. Use, for, example, these methods instead:
https://msdn.microsoft.com/en-us/library/ms142038.aspx[^],
https://msdn.microsoft.com/en-us/library/ms142039.aspx[^].

To get an instance of System.Drawing.Graphics to draw on a bitmap, use https://msdn.microsoft.com/en-us/library/system.drawing.graphics.fromimage(v=vs.110).aspx[^].

You see, no LockBits or anything like that. LockBits is only needed if you have to manipulate at the level of bits, want to convert pixel types, things like that.

That's all.

And don't manipulate with System.Windows.Forms.PictureBox. Even if you want to use this purely redundant control type (which can be convenient in some simple cases), do all calculations with images, use System.Drawing.Bitmap as a target of your calculations, and, when they are done, assign this image to PictureBox.Image.
 
Share this answer
 
Comments
codetowns 26-Jan-15 6:18am    
Many thanks Sergey. I think the hint helps me and your suggestions on copying methods is valuable.
Sergey Alexandrovich Kryukov 26-Jan-15 15:59pm    
Great. You are very welcome.
Good luck, call again.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900