private void DoExport(string exportDir, string rc2file) { //240x400 //Offset 0x21000 byte[] iBoot = new byte[192000]; //240x400 //Offset 0x50000 byte[] iBatt = new byte[192000]; //212x13 //Offset 0x7EE04 byte[] iPbdr = new byte[5512]; //21x11 //Offset 0x8038C byte[] iPbar = new byte[462]; FileInfo fi = new FileInfo(rc2file); using (FileStream fs = fi.Open(FileMode.Open, FileAccess.Read, FileShare.Read)) { //Load up our images. fs.Seek(0x21000, SeekOrigin.Begin); if (fs.Read(iBoot, 0, iBoot.Length) != iBoot.Length) { throw new InvalidDataException("Couldn't read the boot image from the RC2 file!"); } fs.Seek(0x50000, SeekOrigin.Begin); if (fs.Read(iBatt, 0, iBatt.Length) != iBatt.Length) { throw new InvalidDataException("Couldn't read the Battery image from the RC2 File!"); } fs.Seek(0x7EE04, SeekOrigin.Begin); if (fs.Read(iPbdr, 0, iPbdr.Length) != iPbdr.Length) { throw new InvalidDataException("Couldn't read the progress bar border from the RC2 file!"); } //? fs.Seek(0x8038C, SeekOrigin.Begin); if (fs.Read(iPbar, 0, iPbar.Length) != iPbar.Length) { throw new InvalidDataException("Couldn't read the progress bar image from RC2!"); } } //Bitmap tmp = new Bitmap(240, 400); Image boot = FirmwareBMP.FWBitmapToImage(iBoot, 400, 240); Image batt = FirmwareBMP.FWBitmapToImage(iBatt, 400, 240); Image brdr = FirmwareBMP.FWBitmapToImage(iPbdr, 13, 212); Image pbar = FirmwareBMP.FWBitmapToImage(iPbar, 11, 21); //And now... DirectoryInfo di = new DirectoryInfo(exportDir); boot.Save(Path.Combine(di.FullName, BootImageFilename), ImageFormat.Bmp); batt.Save(Path.Combine(di.FullName, BattImageFilename), ImageFormat.Bmp); brdr.Save(Path.Combine(di.FullName, BorderImageFilename), ImageFormat.Bmp); pbar.Save(Path.Combine(di.FullName, BarImageFilename), ImageFormat.Bmp); MessageBox.Show(string.Format("Successfully exported boot images to {0}", di.FullName)); }
private byte[] ImportBitmap(string filename, int width, int height) { Bitmap b = new Bitmap(filename); if (b.Width != width || b.Height != height) { throw new SizeException(string.Format("Bitmap {0}\n" + "Requested Size: {1}, {2}\n" + "Actual Size: {3}, {4}", filename, width, height, b.Width, b.Height)); } return(FirmwareBMP.ImageToFWBitmap(b)); }