public bool DrawRgbaImage(int imageIndex) { if (ImagesRgba == null || ImagesRgba.Count <= imageIndex) { return(false); } if (imageIndex < 0 || imageIndex >= ImagesRgba.Count) { return(false); } SpriteImageRgba sprImg = ImagesRgba[imageIndex]; if (sprImg == null || sprImg.Data == null || sprImg.Data.Length == 0 || sprImg.Width < 1 || sprImg.Height < 1) { return(false); } sprImg.Image = new Bitmap(sprImg.Width, sprImg.Height); var fb = new FastBitmap(sprImg.Image); var index = 0; fb.LockImage(); for (var y = 0; y < sprImg.Height; y++) { for (var x = 0; x < sprImg.Width; x++, index += 4) { // A B G R int alpha = sprImg.Data[index]; int blue = sprImg.Data[index + 1]; int green = sprImg.Data[index + 2]; int red = sprImg.Data[index + 3]; var col = Color.FromArgb(alpha, red, green, blue); fb.SetPixel(x, y, col); } } fb.UnlockImage(); return(true); }
protected override bool ReadInternal() { if (base.ReadInternal() == false) { return false; } ImagesPal = new List<SpriteImagePal>(); ImagesRgba = new List<SpriteImageRgba>(); Palette = new PalFormat(); if (FileHeader.Version.Major > 2) { // Unsupported version return false; } int imgPalCount = Reader.ReadUInt16(); int imgRgbaCount = 0; if (FileHeader.Version >= 0x201) { imgRgbaCount = Reader.ReadUInt16(); } // Images - Palette \\ for (var i = 0; i < imgPalCount; i++) { var imgPal = new SpriteImagePal { Width = Reader.ReadUInt16(), Height = Reader.ReadUInt16() }; if (FileHeader.Version >= 0x201) { imgPal.Size = Reader.ReadUInt16(); } else { imgPal.Size = (ushort)(imgPal.Width * imgPal.Height); } imgPal.Data = Reader.ReadBytes(imgPal.Size); ImagesPal.Add(imgPal); } // Images - RGBA \\ for (int i = 0; i < imgRgbaCount; i++) { var imgRgba = new SpriteImageRgba { Width = Reader.ReadUInt16(), Height = Reader.ReadUInt16() }; int size = (imgRgba.Width * imgRgba.Height * 4); imgRgba.Data = Reader.ReadBytes(size); ImagesRgba.Add(imgRgba); } // Palette \\ Reader.BaseStream.Position = (Reader.BaseStream.Length - (4 * PalFormat.ColorCount)); Palette.Read(Reader.BaseStream); Flush(); return true; }
protected override bool ReadInternal() { if (base.ReadInternal() == false) { return(false); } ImagesPal = new List <SpriteImagePal>(); ImagesRgba = new List <SpriteImageRgba>(); Palette = new PalFormat(); if (FileHeader.Version.Major > 2) { // Unsupported version return(false); } int imgPalCount = Reader.ReadUInt16(); int imgRgbaCount = 0; if (FileHeader.Version >= 0x201) { imgRgbaCount = Reader.ReadUInt16(); } // Images - Palette \\ for (var i = 0; i < imgPalCount; i++) { var imgPal = new SpriteImagePal { Width = Reader.ReadUInt16(), Height = Reader.ReadUInt16() }; if (FileHeader.Version >= 0x201) { imgPal.Size = Reader.ReadUInt16(); } else { imgPal.Size = (ushort)(imgPal.Width * imgPal.Height); } imgPal.Data = Reader.ReadBytes(imgPal.Size); ImagesPal.Add(imgPal); } // Images - RGBA \\ for (int i = 0; i < imgRgbaCount; i++) { var imgRgba = new SpriteImageRgba { Width = Reader.ReadUInt16(), Height = Reader.ReadUInt16() }; int size = (imgRgba.Width * imgRgba.Height * 4); imgRgba.Data = Reader.ReadBytes(size); ImagesRgba.Add(imgRgba); } // Palette \\ Reader.BaseStream.Position = (Reader.BaseStream.Length - (4 * PalFormat.ColorCount)); Palette.Read(Reader.BaseStream); Flush(); return(true); }