Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.5k views
in Technique[技术] by (71.8m points)

c# - Washed out colors in PictureBox

When I show a specific image in a PictureBox (or Cyotek's ImageBox in my case, doesn't matter), the color gets a little washed out. Most images displays correctly but some few images gets washed out.

Here's what it looks like:

The original image

Opened in Windows Photo Viewer

Opened in my application

I tried loading the image in 3 different ways, but same result:

Image image = GetImage(OPEN);
imgBox.Image = image;


public Image GetImage(string path)
        {
            Image image = null;
            //image = Image.FromFile(@"D:Visual Studiopicturespokemon.jpg");  // washed out colors
            try
            {
                using (FileStream file_stream = new FileStream(path, FileMode.Open, FileAccess.Read))  // washed out colors
                {
                    MemoryStream memory_stream = new MemoryStream();
                    file_stream.CopyTo(memory_stream);
                    image = Image.FromStream(memory_stream, false, false);
                    file_stream.Dispose();
                }
            }
            catch
            {
                try
                {
                    FIBITMAP picture = FreeImage.LoadEx(path);  // washed out colors
                    Bitmap bitmap = FreeImage.GetBitmap(picture);
                    image = bitmap;
                    FreeImage.Unload(picture);
                }
                catch { }
            }
            return image;
        }

Anyone know why this is? Maybe some specific tag in this image that Windows and PictureBox handles differently?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You should use Image.FromStream() and pass true for the useEmbeddedColorManagement argument to ensure that any metadata for color management is used.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...