예제 #1
0
 public static Image <Color32> Parse(byte[] bytes)
 {
     try
     {
         var tif = GeoTiff.ImageFromBytes(bytes);
         if (tif is Image <byte> )
         {
             var img   = tif as Image <byte>;
             var image = new Image <Color32>();
             image.Width    = img.Width;
             image.Height   = img.Height;
             image.Channels = img.Channels;
             image.Data     = new Color32[image.Width * image.Height];
             for (int i = 0, c = image.Width * image.Height; i < c; ++i)
             {
                 ref Color32 color = ref image.Data[i];
                 int         index = i * image.Channels;
                 color.r = img.Data[index];
                 color.g = (image.Channels > 1) ? img.Data[index + 1] : img.Data[index];
                 color.b = (image.Channels > 2) ? img.Data[index + 2] : img.Data[index];
                 color.a = (image.Channels > 3) ? img.Data[index + 3] : (byte)255;
             }
             return(image);
         }
         if (tif is Image <short> )
         {
             var img   = tif as Image <short>;
             var image = new Image <Color32>();
             image.Width    = img.Width;
             image.Height   = img.Height;
             image.Channels = img.Channels;
             image.Data     = new Color32[image.Width * image.Height];
             for (int i = 0, c = image.Width * image.Height; i < c; ++i)
             {
                 ref Color32 color = ref image.Data[i];
                 int         index = i * image.Channels;
                 color.r = (byte)(img.Data[index] / 255);
                 color.g = (image.Channels > 1) ? (byte)(img.Data[index + 1] / 255) : (byte)img.Data[index];
                 color.b = (image.Channels > 2) ? (byte)(img.Data[index + 2] / 255) : (byte)img.Data[index];
                 color.a = (image.Channels > 3) ? (byte)(img.Data[index + 3] / 255) : (byte)255;
             }
             return(image);
         }
예제 #2
0
        public override void Execute()
        {
            base.Execute();
            var tif = GeoTiff.ImageFromBytes(FileBytes);

            if (tif is Image <byte> )
            {
                var img = tif as Image <byte>;
                Image.Width    = img.Width;
                Image.Height   = img.Height;
                Image.Channels = img.Channels;
                Image.Data     = new Color32[Image.Width * Image.Height];
                for (int i = 0, c = Image.Width * Image.Height; i < c; ++i)
                {
                    ref Color32 color = ref Image.Data[i];
                    int         index = i * Image.Channels;
                    color.r = img.Data[index];
                    color.g = (Image.Channels > 1) ? img.Data[index + 1] : img.Data[index];
                    color.b = (Image.Channels > 2) ? img.Data[index + 2] : img.Data[index];
                    color.a = (Image.Channels > 3) ? img.Data[index + 3] : (byte)255;
                }
                return;
            }