Is it OK to use WPF assemblies in a web app?

Posted by Chris on Stack Overflow See other posts from Stack Overflow or by Chris
Published on 2010-03-11T05:19:22Z Indexed on 2010/03/11 5:23 UTC
Read the original article Hit count: 277

Filed under:
|
|

I have an ASP.NET MVC 2 app targeting .NET 4 that needs to be able to resize images on the fly and write them to the response.

I have code that does this and it works. I am using System.Drawing.dll.

However, I want to enhance my code so that not only am I resizing the image, but I am dropping it from 24bpp down to 4bit grayscale. I could not, for the life of me, find code on how to do this with System.Drawing.dll.

But I did find a bunch of WPF stuff. This is my working/sample code (runs in LinqPad).

// Load the original 24 bit image
var bitmapImage = new BitmapImage();
bitmapImage.BeginInit();
bitmapImage.UriSource = new Uri(@"C:\Temp\Resized\18_appa2_015.png", UriKind.Absolute);
//bitmapImage.DecodePixelWidth = 600;
bitmapImage.EndInit();

// Create the destination image
var formatConvertedBitmap = new FormatConvertedBitmap();
formatConvertedBitmap.BeginInit();
formatConvertedBitmap.Source = bitmapImage;
formatConvertedBitmap.DestinationFormat = PixelFormats.Gray4;
formatConvertedBitmap.EndInit();

// Encode and dump the image to disk
var encoder = new PngBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(formatConvertedBitmap));
using (var fileStream = File.Create(@"C:\Temp\Resized\18_appa2_015_s2.png"))
{
    encoder.Save(fileStream);
}

It uses System.Xaml.dll, WindowsBase.dll, PresentationCore.dll, and PresentationFramework.dll. The namespaces used are: System.Windows.Controls, System.Windows.Media, and System.Windows.Media.Imaging.

Is there any problem using these namespaces in my web application? It doesn't seem right.

If anyone knows how to drop the bit depth without all this WPF stuff (which I barely understand, BTW) I would be thrilled to see that too.

© Stack Overflow or respective owner

Related posts about asp.net-mvc

Related posts about wpf