Raheel Khan
Raheel Khan

Reputation: 14787

Generating extremely large images in C#

I need to generate some large graphs whose width and height can go up to millions of pixels in size. Please note that I do NOT want to scale down the image. Each point must represent one pixel.

Now using the Bitmap and Graphics objects, this is very much possible if I split the image into smaller squares but it is painfully slow.

I already calculate the pixel RGB values so was wondering if there is a way to create a byte array with these values and manually save them as an uncompressed BMP format file instead of dealing with the Bitmap class and the drawing functions of the Graphics class.

I am comfortable with unsafe code if that helps to speed up the process.

Upvotes: 2

Views: 1378

Answers (2)

Jordan
Jordan

Reputation: 32552

If you're displaying graphs, why don't you use a technology like SVG that can be rendered on the fly with very little processing power, yet can scale to near-infinite sizes thanks to vector expansion?

Upvotes: 3

Alexei Levenkov
Alexei Levenkov

Reputation: 100620

(While there is good question if anything will be able to read such files...)

BMP format is very simple - you can write it directly to disk (I'd recommend avoiding building huge file in memory unless you have other reasons to do so). There is a fixed-size header and then (for 24bpp) sequences of colors aligned on some width. Assuming you can pick width you will not even need to add any padding - just rows of colors for each pixel.

Upvotes: 2

Related Questions