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 1065063
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T19:45:15+00:00 2026-05-16T19:45:15+00:00

Working in WPF and C#, I have a TransformedBitmap object that I either: Need

  • 0

Working in WPF and C#, I have a TransformedBitmap object that I either:

  1. Need to save to disk as a bitmap type of file (ideally, I’ll allow users to choose whether it’s saved as a BMP, JPG, TIF, etc, though, I’m not to that stage yet…)
  2. Need to convert to a BitmapImage object as I know how to get a byte[] from a BitmapImage object.

Unfortunately, at this point I’m really struggling to get either one of those two things done.

Can anyone offer any help or point out any methods I might be missing?

  • 1 1 Answer
  • 1 View
  • 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-05-16T19:45:16+00:00Added an answer on May 16, 2026 at 7:45 pm

    All of your encoders are using BitmapFrame class for creating frames that will be added to Frames collection property of encoder. BitmapFrame.Create method has variety of overloads and one of them accepts parameter of BitmapSource type. So as we know that TransformedBitmap inherits from BitmapSource we can pass it as a parameter to BitmapFrame.Create method. Here are the methods which works as you have described:

    public bool WriteTransformedBitmapToFile<T>(BitmapSource bitmapSource, string fileName) where T : BitmapEncoder, new()
            {
                if (string.IsNullOrEmpty(fileName) || bitmapSource == null)
                    return false;
    
                //creating frame and putting it to Frames collection of selected encoder
                var frame = BitmapFrame.Create(bitmapSource);
                var encoder = new T();
                encoder.Frames.Add(frame);
                try
                {
                    using (var fs = new FileStream(fileName, FileMode.Create))
                    {
                        encoder.Save(fs);
                    }
                }
                catch (Exception e)
                {
                    return false;
                }
                return true;
            }
    
            private BitmapImage GetBitmapImage<T>(BitmapSource bitmapSource) where T : BitmapEncoder, new()
            {
                var frame = BitmapFrame.Create(bitmapSource);
                var encoder = new T();
                encoder.Frames.Add(frame);
                var bitmapImage = new BitmapImage();
                bool isCreated;
                try
                {
                    using (var ms = new MemoryStream())
                    {
                        encoder.Save(ms);
                        ms.Position = 0;
    
                        bitmapImage.BeginInit();
                        bitmapImage.StreamSource = ms;
                        bitmapImage.CacheOption = BitmapCacheOption.OnLoad;
                        bitmapImage.EndInit();
                        isCreated = true;
                    }
                }
                catch
                {
                    isCreated = false;
                }
                return isCreated ? bitmapImage : null;
            }
    

    They accept any BitmapSource as the first parameter and any BitmapEncoder as a generic type parameter.

    Hope this helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been working on a C# 4.0 WPF project and need to figure
I'm working with WPF and often have the need to get the namespace and
I'm trying to do (in WPF): Have an .exe file that displays the system
I have a WPF C# project that I am working on and I have
We have a working WPF app that we are looking into running in the
I have a working WPF dialog that uses DataGrid. The DataGrid is set to
I am working on the WPF application and i have created an exe file.
i'm working on Linq To Sql,WPF and i have a database now i need
I am working on a WPF project and I have a years combobox that
While working in WPF i have the need for a Dynamic Grid. By this

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.