是否确定使用WPF程序集的web应用程序? [英] Is it OK to use WPF assemblies in a web app?

查看:135
本文介绍了是否确定使用WPF程序集的web应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ASP.NET MVC 2应用定位.NET 4中,需要能够动态调整图像,并将其写入响应。

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.

我有code,这是否和它的作品。我使用System.Drawing.dll程序。

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

不过,我想提高我的code,这样我不仅调整图像大小,但我从24 bpp的掉落下来到4位灰度。我不能,因为我的生活,找到关于如何与System.Drawing.dll程序做到这一点code。

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.

但我确实发现了一堆东西WPF。这是我的工作/样品code(在LinqPad运行)。

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);
}

它采用System.Xaml.dll,WindowsBase.dll中,presentationCore.dll和presentationFramework.dll。所使用的命名空间:System.Windows.Controls的,System.Windows.Media和System.Windows.Media.Imaging

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.

有没有用我的web应用这些命名空间的任何问题?它看起来不正确。

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

如果有谁知道如何删除该位深度没有这一切的WPF的东西(我不太了解,BTW)我会很高兴地看到这一点。

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.

推荐答案

没有问题。您可以轻松地使用WPF的图像处理从ASP.NET Web站点内。我使用WPF一个网站内的幕后前几次,它的伟大工程。

No problem. You can easily use WPF for image manipulation from within an ASP.NET web site. I've used WPF behind the scenes within a web site several times before, and it works great.

在一个问题我也碰到是WPF的许多地方坚持调用线程是STA线程。如果你的网站使用MTA线程而不是你会得到一个错误,告诉您需要的WPF STA线程。为了解决这个问题,可以使用STAThreadPool I类张贴在<一个href=\"http://stackoverflow.com/questions/2363397/can-the-wpf-api-be-safely-used-in-a-wcf-service/2367409#2367409\">this回答。

The one issue I did run into is that many parts of WPF insist the calling threads be STA threads. If your web site uses MTA threads instead you will get an error telling you that WPF needs STA threads. To fix this, use the STAThreadPool class I posted in this answer.

这篇关于是否确定使用WPF程序集的web应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆