public static void ReplaceColor(this Bitmap img, SegaSaturnColor src, SegaSaturnColor dest) { using (BmpPixelSnoop tmp = new BmpPixelSnoop(img)) { int srcColor = src.ToArgb(); for (int y = 0; y < tmp.Height; ++y) { for (int x = 0; x < tmp.Width; ++x) { if (tmp.GetPixel(x, y).ToArgb() == srcColor) { tmp.SetPixel(x, y, dest); } } } } }
public static Bitmap LoadBitmapFromFile(string path, SegaSaturnColor transparentColor = null) { if (Path.GetExtension(path).ToLowerInvariant() == ".bin") { using (Stream stream = File.Open(path, FileMode.Open)) { using (BinaryReader streamReader = new BinaryReader(stream)) { Bitmap bin = new Bitmap(streamReader.ReadUInt16(), streamReader.ReadUInt16(), PixelFormat.Format32bppArgb); using (BmpPixelSnoop tmp = new BmpPixelSnoop(bin)) { for (int y = 0; y < tmp.Height; ++y) { for (int x = 0; x < tmp.Width; ++x) { tmp.SetPixel(x, y, new SegaSaturnColor(streamReader.ReadUInt16())); } } } return(bin); } } } if (Path.GetExtension(path).ToLowerInvariant() == ".tga") { Bitmap tga = TargaImage.LoadTargaImage(path); if (transparentColor != null) { tga.ReplaceColor(transparentColor, Color.Transparent); } return(tga); } Bitmap bitmap = (Bitmap)Bitmap.FromFile(path); if (transparentColor != null) { bitmap.ReplaceColor(transparentColor, Color.Transparent); } return(bitmap); }