public void ImportImageDataAs15Bit(Bitmap bitmap) { if (bitmap == null) { return; } BitsPerPixel = 16; FirstByte = 1; ImageWidth = bitmap.Width; ImageHeight = bitmap.Height; ImageOffset = default; FrameWidth = (byte)bitmap.Width; FrameHeight = (byte)bitmap.Height; ImageHandle = 1; PaletteHandle = 1; Memory = 1; PaletteHandle2 = 1; ImageData = new byte[bitmap.Width * bitmap.Height * 2]; for (int x = 0; x < ImageWidth; x++) { for (int y = 0; y < ImageHeight; y++) { Color pixel = bitmap.GetPixel(x, y); ushort data16 = Palette_15Bit.ConvertColor(pixel); int pos = (x + y * ImageWidth) * 2; byte[] b = BitConverter.GetBytes(data16); ImageData[pos] = b[0]; ImageData[pos + 1] = b[1]; } } }
public Bitmap GetBitmap(Palette_18Bit basePalette, HousePaletteFile housePalette, bool includeFrame, bool makeTransparent, int houseIndex) { if (PaletteType == PaletteType.EMPTY_ENTRY) { // at least draw something so it does not error out. Bitmap empty = new Bitmap(1, 1); empty.MakeTransparent(); return(empty); } Bitmap bmp = new Bitmap(ImageWidth, ImageHeight); if (BitsPerPixel == 8) { IPalette pal = (PaletteHandle == 0) ? (IPalette)basePalette.Clone() : Palette.Clone(); if (houseIndex != -1) { pal = housePalette.Merge(pal, houseIndex); } for (int x = 0; x < ImageWidth; x++) { for (int y = 0; y < ImageHeight; y++) { int pos = x + y * ImageWidth; byte data8 = ImageData[pos]; if (makeTransparent && data8 == 0) { bmp.SetPixel(x, y, Color.Transparent); } else if (makeTransparent && data8 == 1) { bmp.SetPixel(x, y, Color.FromArgb(128, 0, 0, 0)); } else { bmp.SetPixel(x, y, pal.Get(data8)); } } } } else if (BitsPerPixel == 16) { // doesn't care about palettes, as its image data is direct color for (int x = 0; x < ImageWidth; x++) { for (int y = 0; y < ImageHeight; y++) { int pos = (x + y * ImageWidth) * 2; ushort data16 = BitConverter.ToUInt16(ImageData, pos); bmp.SetPixel(x, y, Palette_15Bit.ConvertColor(data16)); } } } else { throw new InvalidDataException("Unexpected bits per pixel! (Value = {0})".F(BitsPerPixel)); } if (makeTransparent) { bmp.MakeTransparent(Palette.Get(0)); } if (includeFrame) { Bitmap bmpFrame = new Bitmap(FrameWidth, FrameHeight); bmpFrame.MakeTransparent(); Graphics g = Graphics.FromImage(bmpFrame); g.DrawImageUnscaled(bmp, new Point((FrameWidth - ImageWidth) / 2, (FrameHeight - ImageHeight) / 2)); return(bmpFrame); } else { return(bmp); } }