Ejemplo n.º 1
0
 public static void SaveToFile(Texture texture, string fileName, SysDraw.PixelFormat format = SysDraw.PixelFormat.Format32bppArgb)
 {
     using (var bitmap = SaveToBitmap(texture, format))
     {
         bitmap.Save(fileName);
     }
 }
Ejemplo n.º 2
0
        public static PixelInternalFormat SelectInternalPixelFormat(SysDraw.PixelFormat pixelFormat)
        {
            switch (pixelFormat)
            {
            case SysDraw.PixelFormat.Format8bppIndexed: return(PixelInternalFormat.Luminance);

            case SysDraw.PixelFormat.Format24bppRgb: return(PixelInternalFormat.Rgb);

            case SysDraw.PixelFormat.Format32bppArgb: return(PixelInternalFormat.Rgba);

            default: throw new FileLoadException("Wrong pixel format " + pixelFormat.ToString());
            }
        }
Ejemplo n.º 3
0
        public static PixelFormat SelectPixelFormat(SysDraw.PixelFormat pixelFormat)
        {
            switch (pixelFormat)
            {
            case SysDraw.PixelFormat.Format8bppIndexed: return(PixelFormat.Red);

            case SysDraw.PixelFormat.Format24bppRgb: return(PixelFormat.Bgr);

            case SysDraw.PixelFormat.Format32bppArgb: return(PixelFormat.Bgra);

            default: throw new FileLoadException("Wrong pixel format " + pixelFormat.ToString());
            }
        }
Ejemplo n.º 4
0
 public static Bitmap SaveToBitmap(Texture texture, SysDraw.PixelFormat format = SysDraw.PixelFormat.Format32bppArgb)
 {
     try
     {
         var bmp = new Bitmap(texture.Width, texture.Height);
         texture.Activate();
         var data = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), SysDraw.ImageLockMode.WriteOnly, format);
         GL.GetTexImage(TextureTarget.Texture2D, 0, SelectPixelFormat(format), PixelType.UnsignedByte, data.Scan0);
         bmp.UnlockBits(data);
         texture.Deactivate();
         bmp.RotateFlip(RotateFlipType.RotateNoneFlipY);
         return(bmp);
     }
     catch
     {
         texture.Deactivate();
         return(null);
     }
 }