本文介绍了如何共享WPF和asp.net的图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有3个项目一个与解决方案

i have a vs solution with 3 projects

MyCore:类库与DAL,BLL,辅助功能等......

MyCore: class library with DAL,BLL,helper functions etc...

MyWebsite: asp.net网站,该网站引用MyCore

MyWebsite: asp.net website which references MyCore

所有MyApplication :WPF应用程序还引用MyCore

MyApplication: wpf app that also references MyCore

此设置可以让我重新使用的网站和应用程序的所有相同的功能。

this setup allows me to reuse all the same functionality in the website and in the app.

唯一的问题是图像。现在所有图标我在网站上单独保留(和它们的网址进行访问),并在桌面应用程序(如资源访问)

the only problem is images. right now all icons i keeps separately in the website (and are accessed by their url) and also in the desktop app (accessed as resource)

有什么办法,我可以的图标以某种方式保存在MyCore,并在这两个项目中使用它们?

is there any way i can somehow store the icons in MyCore and use them in both projects?

什么想法?

感谢大家对我付出的时间和耐心

thank you all very much for your time and patience

推荐答案

这是方便,海峡前进的办法是把所有的图片在分隔类(或者在MyCore你的情况)作为的ressource(打开访问修饰符公共!)。

An easy and strait forward way is to put all your images in a seperated Class (or in your case in MyCore) as a Ressource (Turn access modifier to public!).

在这一点上,你可以使用一个HttpHandler作为ImageHandler,其中流您的ressource文件的图像,正常的图像到您的网页,例如。

At this point you can use an HTTPHandler as ImageHandler, which streams the images of your ressource file as "normal" images to your webpage, e.g.

public class ImageHandler : IHttpHandler
{
  public void ProcessRequest(HttpContext context)
  {
    context.Response.ContentType = "image/jpg";
    context.Response.Clear();

    Bitmap image = ClassLibrary1.Resource1._1346135638012;
    image.Save(context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);

  }

  public bool IsReusable
  {
    get
    {
        return false;
    }
   }
 }

您可以使用get参数来识别哪些图像已被流,例如

You could use a get parameter to identify which images has to be streamed, e.g.

<image src="./ImageHandler.ashx?ImageId=123" />

和 - 当然 - 你可以使用ressoures您的应用程序也是如此。

And - of course - you could use the ressoures for your application as well.

这篇关于如何共享WPF和asp.net的图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 01:15