Yisroel M. Olewski
Yisroel M. Olewski

Reputation: 1626

how to share images between wpf and asp.net?

i have a vs solution with 3 projects

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

MyWebsite: asp.net website which references 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)

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

any ideas?

thank you all very much for your time and patience

Upvotes: 0

Views: 1502

Answers (1)

Kai
Kai

Reputation: 2013

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!).

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

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

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

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

Upvotes: 1

Related Questions