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

  • Home
  • SEARCH
  • 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 9168257
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:35:12+00:00 2026-06-17T15:35:12+00:00

I am new to C#. I want to convert FormatConvertedBitmap to Stream as said

  • 0

I am new to C#.

I want to convert FormatConvertedBitmap to Stream as said earlier.
I couldn’t find any method for that. I thought to save or write the FormatConvertedBitmap to a file so that reading it as a Stream, but even couldn’t find a way to write it to a file.

can some one help me in either :

  1. Converting FormatConvertedBitmap to an Stream
    Or
  2. Writing FormatConvertedBitmap to a file and then reading it as Stream.

public Stream Image

    {
        get
    {//some condition
                if (_image != null)
                {
                    _image.Seek(0, SeekOrigin.Begin);

                    BitmapImage bmp = new BitmapImage();
                    MemoryStream stream = (MemoryStream)_image;
                    bmp.BeginInit();
                    bmp.StreamSource = stream;
                    bmp.CacheOption = System.Windows.Media.Imaging.BitmapCacheOption.OnLoad;
                    bmp.EndInit();
                    var grayBitmapSource = new FormatConvertedBitmap();
                    grayBitmapSource.BeginInit();
                    grayBitmapSource.Source = bmp;
                    grayBitmapSource.DestinationFormat = PixelFormats.Gray32Float;
                    grayBitmapSource.EndInit();
                    Stream st=new MemoryStream();
                    //File.WriteAllBytes(Path.GetTempPath(),grayBitmapSource);
                    return grayBitmapSource;
                }

In the above code I am getting the Image as Stream from the server then on some condition I am converting it to grayScale image . but now we sould return an Stream and finaly we have FormatConvertedBitmap.

#####EDIT

public Stream Image
        {
            get
            {
                //some condition

                            if (_image != null)
                            {
                                _image.Seek(0, SeekOrigin.Begin);
                                BitmapImage bmp = new BitmapImage();
                                MemoryStream stream = (MemoryStream)_image;
                                bmp.BeginInit();
                                bmp.StreamSource = stream;
                                bmp.CacheOption = System.Windows.Media.Imaging.BitmapCacheOption.OnLoad;
                                bmp.EndInit();
                                var grayBitmapSource = new FormatConvertedBitmap();
                                grayBitmapSource.BeginInit();
                                grayBitmapSource.Source = bmp;
                                grayBitmapSource.DestinationFormat = PixelFormats.Gray32Float;
                                grayBitmapSource.EndInit();
                                int bytePerPixel = grayBitmapSource.Format.BitsPerPixel / 8;
                                int width = grayBitmapSource.PixelWidth;
                                int height = grayBitmapSource.PixelHeight;
                                int stride = width * bytePerPixel;
                                byte[] resultLine = new byte[height * stride];
                                grayBitmapSource.CopyPixels(resultLine, stride, 0);
                                MemoryStream ms = new MemoryStream(resultLine);
                                return ms;
  • 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-17T15:35:13+00:00Added an answer on June 17, 2026 at 3:35 pm

    You can use the method CopyPixels to write the contents of your FormatConvertedBitmap to a byte array.

    You can then use that byte array to either Initialize a MemoryStream or store them to a file with BmpBitmapEncoder or other BitmapEncoder.

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

Sidebar

Related Questions

I have a string with new line characters. I want to convert that string
I want to use LINQ to convert this IEnumerable<int>[] value1ByType = new IEnumerable<int>[3]; value1ByType[0]=
I want add new Feed item on entity persist and update. I write this
I am new to Android. I want to convert a XML file to HTML
I am new to android deveolpment. I want to convert the String Mon, 11
I want to convert an array of hashes that I create like this: while(...)
I have a sentence say This is my new program I want to convert
I want to convert this code into PHP, it's a function that hides layers
I want to convert string to other type. The problem is that I know
Quite new to EF, basically i want to convert this SQL query: SELECT PSKU.ProductSKUID,

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.