예제 #1
0
        public static void ImageSave_PPM(ColorRGB8[,] image, string imgPath)
        {
            int          imgh = image.GetLength(0), imgw = image.GetLength(1);
            FileStream   fs      = new FileStream(imgPath, FileMode.Create);
            BinaryWriter bw      = new BinaryWriter(fs);
            string       imghead = $"P6\n{imgw} {imgh}\n255\n";

            byte[] headcont = Encoding.ASCII.GetBytes(imghead);
            bw.Write(headcont);
            bw.Flush();
            for (int i = 0; i < imgh; ++i)
            {
                for (int j = 0; j < imgw; j++)
                {
                    ColorRGB8 c = image[i, j];
                    bw.Write(c.R);
                    bw.Write(c.G);
                    bw.Write(c.B);
                }
                bw.Flush();
            }

            bw.Flush();
            bw.Close();
            fs.Close();
        }
예제 #2
0
        public static ColorRGB8[,] ConvertToRGB8Image(XYZSpectrum[,] img)
        {
            int imgh = img.GetLength(0), imgw = img.GetLength(1);

            ColorRGB8[,] re = new ColorRGB8[imgh, imgw];
            for (int j = 0; j < imgh; j++)
            {
                for (int i = 0; i < imgw; i++)
                {
                    re[j, i] = GetColor8Gamma22(img[j, i].ToRGB());
                }
            }
            return(re);
        }
예제 #3
0
        public static ColorRGB8[,] ConvertToRGB8Image(Float[,] img)
        {
            int imgh = img.GetLength(0), imgw = img.GetLength(1);

            ColorRGB8[,] re = new ColorRGB8[imgh, imgw];
            for (int j = 0; j < imgh; j++)
            {
                for (int i = 0; i < imgw; i++)
                {
                    byte g = (byte)(Tools.Clamp(img[j, i] * 255, 0.0f, 10.0f));
                    re[j, i] = new ColorRGB8(g);
                }
            }
            return(re);
        }
예제 #4
0
        public static void ImageSave_PNG(ColorRGB8[,] image, string imgPath)
        {
            int imgh = image.GetLength(0), imgw = image.GetLength(1);
            //Image<SixLabors.ImageSharp.PixelFormats.Rgb24> img = new Image<SixLabors.ImageSharp.PixelFormats.Rgb24>(imgw, imgh);
            Bitmap img = new Bitmap(imgw, imgh);

            for (int i = 0; i < imgh; ++i)
            {
                for (int j = 0; j < imgw; j++)
                {
                    ColorRGB8 c = image[i, j];
                    img.SetPixel(j, i, Color.FromArgb(c.R, c.G, c.B));
                }
            }
            img.Save(imgPath, System.Drawing.Imaging.ImageFormat.Png);
        }
예제 #5
0
        public static ColorRGB8[,] ConvertToRGB8Image(int[,] data, int maxvalue)
        {
            int imgh = data.GetLength(0), imgw = data.GetLength(1);

            ColorRGB8[,] re = new ColorRGB8[imgh, imgw];
            float mvalue = 1.0f / maxvalue;

            for (int j = 0; j < imgh; j++)
            {
                for (int i = 0; i < imgw; i++)
                {
                    byte b = (byte)(Tools.Clamp(data[j, i] * mvalue, 0.0f, 1.0f) * 255);
                    re[j, i] = new ColorRGB8(b);
                }
            }
            return(re);
        }