williamsandonz
williamsandonz

Reputation: 16420

C# .NET Dynamic Image Library?

Hi there I am looking to create a image dynamically from an array[500][500] (500x500pixel) Each array item has the pixel color data,

Does anyone know which .NET library/interface would be best for this? Could point me in right direction? I need to create/save the file.

Also, The image is a composite of the data from many images, I am wondering if it is possible to use various formats, or if I need to first convert the small images into one format,

Also which image format is best to use (the most compatible?) JPG/PNG24? (for web)

Thanks for your input!

Upvotes: 1

Views: 1000

Answers (3)

Rohan West
Rohan West

Reputation: 9298

You could use the System.Drawing.Bitmap class.

If you are able to use unsafe code, construct the bitmap using pointers and BitmapData rather than SetPixel

var bitmap = new Bitmap(500, 500);

// Update the pixels with values in you array...

bitmap.Save("myfilename.jpg", ImageFormat.Jpeg);

Upvotes: 1

Can Poyrazoğlu
Can Poyrazoğlu

Reputation: 34780

if you can use unsafe code in your website (in other words, your code runs under full trust), just use the Bitmap class, and use the LockBits method, then you can use pointers just like in C++ to access the pixels (tip: create a Pixel struct to hold RGB values). You will see GetPixel and SetPixel methods, DO NOT EVER use them. The performance is terrible, more than 100 times slower than using pointers. Just go with BitmapData.Scan0.ToPointer() and then iterate with for.

Upvotes: 2

Yahia
Yahia

Reputation: 70369

The format depends on what you need (for example png can support transaprency, jpg does not).

You could start wich System.Drawing.Bitmap .

Upvotes: 0

Related Questions