AlbLib.Imaging.Drawing.LoadBitmap C# (CSharp) Метод

LoadBitmap() публичный статический Метод

Converts bitmap to byte array using external palette.
public static LoadBitmap ( Bitmap bmp, ImagePalette palette ) : byte[]
bmp System.Drawing.Bitmap
palette ImagePalette
Результат byte[]
        public static byte[] LoadBitmap(Bitmap bmp, ImagePalette palette)
        {
            byte[] result = new byte[bmp.Width*bmp.Height];
            BitmapData data = bmp.LockBits(new Rectangle(Point.Empty, bmp.Size), ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);
            for(int y = 0; y < bmp.Height; y++)
            for(int x = 0; x < bmp.Width; x++)
            {
                byte r = Marshal.ReadByte(data.Scan0, y*data.Stride+x*3);
                byte g = Marshal.ReadByte(data.Scan0, y*data.Stride+x*3+1);
                byte b = Marshal.ReadByte(data.Scan0, y*data.Stride+x*3+2);
                result[y*bmp.Width+x] = (byte)palette.GetNearestColorIndex(Color.FromArgb(r,g,b));
            }
            return result;
        }

Usage Example

Пример #1
0
 /// <summary>
 /// Creates new instance.
 /// </summary>
 public static RawImage FromBitmap(Bitmap bmp)
 {
     return(new RawImage(Drawing.LoadBitmap(bmp), bmp.Width, bmp.Height));
 }
All Usage Examples Of AlbLib.Imaging.Drawing::LoadBitmap