Ejemplo n.º 1
0
        public static byte[] ToPixelData <T>(this Image image, TextureFormat fmt)
            where T : unmanaged, IPixel <T>
        {
            var img    = image.CloneAs <T>();
            var stride = fmt.Stride(img.Width);
            var bytes  = new byte[fmt.Size(img.Width, img.Height)];

            for (int i = 0; i < img.Height; i++)
            {
                MemoryMarshal.AsBytes(img.GetPixelRowSpan(i))
                .CopyTo(bytes.AsSpan(stride * i, stride));
            }

            return(bytes);
        }
Ejemplo n.º 2
0
 public static int Size(this TextureFormat fmt, int width, int height)
 {
     return(fmt.Stride(width) * height);
 }