Пример #1
0
        public static void SaveImageToFile(LightStrongImage image, string path, int gamma = 1, float min = 0.0f, float max = 1.0f)
        {
            FileStream       fs = new FileStream(path, FileMode.OpenOrCreate);
            PngBitmapEncoder pngBitmapEncoder = new PngBitmapEncoder();

            pngBitmapEncoder.Frames.Add(BitmapFrame.Create(GetBitmap(image, min, max, gamma)));
            pngBitmapEncoder.Save(fs);
            fs.Flush();
            fs.Close();
        }
Пример #2
0
        private static WriteableBitmap GetBitmap(LightStrongImage image, float min, float max, int gamma)
        {
            int             imgw = image.Width, imgh = image.Height;
            WriteableBitmap bitmap       = new WriteableBitmap(imgw, imgh, 96, 96, System.Windows.Media.PixelFormats.Bgr24, null);
            int             byteperpixel = bitmap.Format.BitsPerPixel / 8;

            byte[] colordata = new byte[imgw * imgh * byteperpixel];
            int    pos       = 0;

            for (int t = 0; t < imgh; t++)
            {
                for (int l = 0; l < imgw; l++)
                {
                    int rt, rl;
                    if (image.HorMirror)
                    {
                        rl = imgw - 1 - l;
                    }
                    else
                    {
                        rl = l;
                    }
                    if (image.VerMirror)
                    {
                        rt = imgh - 1 - t;
                    }
                    else
                    {
                        rt = t;
                    }
                    RGBColor8 color = default;
                    if (gamma == 1)
                    {
                        color = TransToColorGamma1(image.Content[rt, rl], min, max);
                    }
                    else if (gamma == 2)
                    {
                        color = TransToColorGamma2(image.Content[rt, rl], min, max);
                    }
                    else
                    {
                        color = TransToColor(image.Content[rt, rl], min, max, gamma);
                    }
                    colordata[pos] = color.B; pos++;
                    colordata[pos] = color.G; pos++;
                    colordata[pos] = color.R; pos++;
                }
            }
            Int32Rect rect = new Int32Rect(0, 0, image.Width, image.Height);

            bitmap.WritePixels(rect, colordata, image.Width * byteperpixel, 0);
            return(bitmap);
        }