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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T12:55:22+00:00 2026-06-11T12:55:22+00:00

When I am writing a Bitmap to a file and read from the file,

  • 0

When I am writing a Bitmap to a file and read from the file, I am getting the transparency correctly.

using (Bitmap bmp = new Bitmap(2, 2))
{
    Color col = Color.FromArgb(1, 2, 3, 4);
    bmp.SetPixel(0, 0, col);
    bmp.Save("J.bmp");
}

using (Bitmap bmp = new Bitmap("J.bmp"))
{
    Color col = bmp.GetPixel(0, 0);
    // Value of col.A = 1. This is right.
}

But if I write the Bitmap to a MemoryStream and read from that MemoryStream, the transparency has been removed. All alpha values become 255.

MemoryStream ms = new MemoryStream();
using (Bitmap bmp = new Bitmap(2, 2))
{
    Color col = Color.FromArgb(1, 2, 3, 4);
    bmp.SetPixel(0, 0, col);
    bmp.Save(ms, ImageFormat.Bmp);
}

using (Bitmap bmp = new Bitmap(ms))
{
    Color col = bmp.GetPixel(0, 0);
    // Value of col.A = 255. Why? I am expecting 1 here.
}

I wish to save the Bitmap to a MemoryStream and read it back with transparency. How can I resolve this issue?

  • 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-11T12:55:23+00:00Added an answer on June 11, 2026 at 12:55 pm

    The problem is this line: bmp.Save(ms, ImageFormat.Bmp). ImageFormat.Bmp does not support alpha values, you can change it to ImageFormat.Png for the same effect.

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

Sidebar

Related Questions

I am writing a bitmap file using python. My code to create the bitmap
I thought I am writing 10 file extensions and their related Icons as Bitmap
I am new to Python, writing something with pygame and it is very bitmap
Writing htaccess that allows me to remove index.php from the URL can confuse search
Writing a python program, and I came up with this error while using the
Writing an asynchronous Ping using Raw Sockets in F#, to enable parallel requests using
I see more than a few questions asking how to read metadata from an
I am writing a map editing program for a 2D game using XNA. To
Let me start off with I'm mostly new to writing Java, so I would
How can a WriteableBitmap from Silverlight be Saved onto the File System, I am

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.