Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8133675
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T09:41:29+00:00 2026-06-06T09:41:29+00:00

I am using following code to get source for image in wpf (image is

  • 0

I am using following code to get source for image in wpf (image is of type System.Windows.Controls.Image). I want to store this image to disk with it original extension, is it possible?

System.drawing.image provides save method is there something like that for System.windows.controls.image?

Image image=new Image();
BitmapImage bitmap = new BitmapImage();
bitmap.BeginInit();
bitmap.UriSource = new Uri(openFileDlg.FileName);
bitmap.EndInit();               
image.Source = bitmap;                
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T09:41:33+00:00Added an answer on June 6, 2026 at 9:41 am

    Take a look at RenderTargetBitmap and BitmapEncoder classes.

    The following utility class allows you to save your Image as raster graphics image, according to the chosen format:

    public static class VisualToImg
    {
    
        static VisualToImg()
        {
            DPI = 96;
            PixelFormat = PixelFormats.Default;
        }
    
        public enum eImageFormat
        { Bitmap, Png, Gif, Jpeg, Tiff, Wmp }
    
        static public bool SaveAs(FrameworkElement element, String filePath,
            eImageFormat imageFormat)
        {
            switch (imageFormat)
            {
                case eImageFormat.Bitmap:
                    return SaveUsingEncoder(element, filePath, new BmpBitmapEncoder());
                case eImageFormat.Gif:
                    return SaveUsingEncoder(element, filePath, new GifBitmapEncoder());
                case eImageFormat.Jpeg:
                    return SaveUsingEncoder(element, filePath, new JpegBitmapEncoder());
                case eImageFormat.Png:
                    return SaveUsingEncoder(element, filePath, new PngBitmapEncoder());
                case eImageFormat.Tiff:
                    return SaveUsingEncoder(element, filePath, new TiffBitmapEncoder());
                case eImageFormat.Wmp:
                    return SaveUsingEncoder(element, filePath, new WmpBitmapEncoder());
            }
    
            return false;
        }
    
        static public double DPI
        { get; set; }
    
        static public PixelFormat PixelFormat
        { get; set; }
    
        static private bool SaveUsingEncoder(FrameworkElement visual, string filePath,
            BitmapEncoder encoder)
        {
            try
            {
                RenderTargetBitmap bmp = new RenderTargetBitmap((int)visual.ActualWidth,
                    (int)visual.ActualHeight, DPI, DPI, PixelFormat);
    
                bmp.Render(visual);
                encoder.Frames.Add(BitmapFrame.Create(bmp));
    
                using (var stream = File.Create(filePath))
                { encoder.Save(stream); }
    
                return true;
            }
            catch (Exception)
            { return false; }
        }
    
    }
    

    And you can use it to save your Image, or any other FrameworkElement:

    VisualToImg.SaveAs(image, "image1.png", VisualToImg.eImageFormat.Png);
    VisualToImg.SaveAs(image, "image2.bmp", VisualToImg.eImageFormat.Bitmap);
    VisualToImg.SaveAs(image, "image3.jpeg", VisualToImg.eImageFormat.Jpeg);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using following code to get bitmap from url. This function is used
I want to get the difference between two images I use this source code:
I am using following code to get current latitude and longitude. But none of
I am using the following code to get the Google Plus posts, public class
I'm using the following code to get a list of all installed apps on
I'm using the following code to get an array with all sub directories from
I am using the following code to get make an IMAP connection. I am
I am using the following code to get an XML data from a website
We are using the following code to get the groups of an active directory
I'm using the following code to get response from a requested page using php

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.