none
Are System.Windows.Media.Imaging Classes Supported in ASP.NET Applications? RRS feed

  • Question

  • Are the classes in System.Windows.Media.Imaging supported for use in ASP.NET applications or do these classes have similar memory/deadlock/unsupported issues as the System.Drawing classes?
    Thursday, June 1, 2017 6:39 PM

All replies

  • Hi Jared S. _,

    Thank you for posting here.

    For your question, please add the "Presentation.dll" in your asp.net project.

    The dll is in c:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0\PresentationCore.dll.


    Here is a simple code in MSDN article for your reference.

    FileStream stream = new FileStream("empty.tif", FileMode.Create);
    TiffBitmapEncoder encoder = new TiffBitmapEncoder();
    TextBlock myTextBlock = new TextBlock();
    myTextBlock.Text = "Codec Author is: " + encoder.CodecInfo.Author.ToString();
    encoder.Frames.Add(BitmapFrame.Create(image));
    MessageBox.Show(myPalette.Colors.Count.ToString());
    encoder.Save(stream);
    

    I hope this would be helpful.

    Best Regards,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, June 2, 2017 7:04 AM
    Moderator
  • Thank you for the reply Wendy.  I am aware of how to add the references to use classes and am able to do so.  My question is, is this supported in ASP.NET or is it unsupported by Microsoft, similar to how System.Drawing is not supported in ASP.NET applications.
    Friday, June 2, 2017 1:38 PM
  • Hi Jared S. _,

    Thank you for feedback.

    For System.Windows.Media.Imaging, it supports ASP.NET project. You could refer to the following code. It works well.

    protected void Page_Load(object sender, EventArgs e)
            {
                BitmapSource bSource = new BitmapImage(new Uri(@"C:\Users\v-wezan\Desktop\1.png"));
           
                // save the barcode image to a file
                PngBitmapEncoder encoder = new PngBitmapEncoder();
                encoder.Frames.Add(BitmapFrame.Create(bSource));
                using (Stream stream = File.OpenWrite(@"C:\Users\v-wezan\Desktop\2.png"))
                    encoder.Save(stream);
    
    
            }

    It works well for me.

    ASP.NET support support System.Drawing. I make a simple example to show.

     protected void Page_Load(object sender, EventArgs e)
            {
                Bitmap bitmap = new Bitmap(800, 600);
                Graphics graphics = Graphics.FromImage(bitmap);
                graphics.Clear(Color.White);
                SolidBrush mySolidbrush = new SolidBrush(Color.Yellow);
                graphics.FillEllipse(mySolidbrush, 70, 20, 100, 50);
                System.IO.MemoryStream ms = new System.IO.MemoryStream();
                bitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Gif);
                Response.ClearContent();
                Response.ContentType = "image/Gif";
                Response.BinaryWrite(ms.ToArray());
            }

    What are you doing for with System.Drawing or System.Windows.Media.Imanging? Could you provide more information about this?

    Best Regards,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, June 5, 2017 9:31 AM
    Moderator