Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k 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 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...