system.drawing.imaging

Alternatives to System.Drawing for use with ASP.NET?

After several days of tracking down bizarre GDI+ errors, I've stumbled across this little gem on MSDN: Classes within the System.Drawing namespace are not supported for use within a Windows or ASP.NET service. Attempting to use these classes from within one of these application types may produce unexpected problems, such as diminishe...

Changing System.Drawing.Bitmap.Palette

I have a TIFF file in memory, which I obtained by a variant of the following code: Image myImage = Image.FromFile("somefile.tiff"); Currently, myImage.Palette only returns two colors, black and white. I would like to expand this to include the entire color spectrum. However, myImage.Palette does not have a function to add additional ...

Assuming ASP.NET and form upload, any way to ensure file is an image?

Is there any way to tell if the file is an image either through MIME type or some other way of inspection? The images are going into a gallery and I'll be resizing them as necessary and want to ensure, to the best I can, that the file I'm about to process with GDI is, in fact, an image. ...

Converting a GUID to System.Drawing.Imaging.ImageFormat

I store information about images in a database - also their ImageFormat (jpeg, png etc). Console.WriteLine(System.Drawing.Imaging.ImageFormat.Jpeg.Guid); Outputs: b96b3cae-0728-11d3-9d7b-0000f81ef32e I want to store this in the database as a GUID - and read from the database and get the associated ImageFormat. How do I cast the GU...

Any good source of explanatory documentation on ColorMatrix?

I'd like to try using ColorMatrix, but am only able to find examples that convert an image to grayscale. And even then, they tend to be presented as a chunk of 'magic numbers' code with no explanation. Does anyone know of a 'tutorial' on how to use ColorMatrix? For example I'd be interested in converting a grayscale image to a color ima...

Determine if Alpha Channel is Used in an Image

As I'm bringing in images into my program, I want to determine if: they have an alpha-channel if that alpha-channel is used #1 is simple enough with using Image.IsAlphaPixelFormat. For #2 though, other than looping through every single pixel, is there a simple way I can determine if at least one of the pixels has an alpha channel tha...

passing the right BytesArray into the MemoryStream for Image

Hi, there a way to determine that I am passing the right byte array to the MemoryStream if I want to create an Image out of byte array. MemoryStream mStream = new MemoryStream(); mStream.Write(byteArray, 0, byteArray.Lenth); Image imgObj = Image.FromStream(mStream); How can I, if possible Correct the byteArray that it is a valid byteA...

Using a System.Drawing.Image as the centered part of a larger image?

I have a System.Drawing.Image that I would like to use as the centered portion for a new, larger image. I’m given the dimensions of the (always) larger image and the idea is to make that image all white and overlay its center with the first image. Is there a way to do this using GDI+? Some combination of TextureBrush and the Graphic c...

File extension from System.Drawing.Image

I'm writing a method that needs to save a System.Drawing.Image to a file. Without knowing the original file the Image was created from, is there anyway to determine what file extension it should have? The best solution I've come up with is to use a Switch/Case statement with the value of Image.RawFormat. Does it even matter that I save...

How to draw text onto a jpg and resave it using system.drawing in c#

Anyone have good example of how to write text onto a jpg image and resave it using System.Drawing in .NET? ...

How to draw centered text onto a jpg using system.drawing in c#

I am using the following code to draw text onto a jpg image but it requires x/y coordinate percision on where to place the text. var bmp = new Bitmap("C:\\testing\\Given.jpg"); var gra = Graphics.FromImage(bmp); var text = "The Berman's"; var font = new Font("Segoe Script", 24); var brush = Brushes.Orange; var point = new PointF(130, 2...

How to serve up image from type System.Drawing.Bitmap (<img> tag?)

I am sending a bitmap to a View in ASP.NET MVC. I have a property in my ViewModel: public Bitmap TemplateImage { get; set; } In my View, I want to be able to render that Bitmap image but I can't figure out how to do it. ...

What quality level does Image.Save() use for jpeg files?

I just got a real surprise when I loaded a jpg file and turned around and saved it with a quality of 100 and the size was almost 4x the original. To further investigate I open and saved without explicitly setting the quality and the file size was exactly the same. I figured this was because nothing changed so it's just writing the exac...