private void SaveFui(string filepath) { List <byte> fuiBytes = new List <byte>(); List <byte> imageSection = new List <byte>(); int currentOffset = 0; fuiBytes.AddRange(fuiMainBytes); for (int i = 0; i < fuiImageInfo.Count; i++) { FuiImageInfo imageInfo = fuiImageInfo[i]; using (MemoryStream imageStream = new MemoryStream(originalImagesData[i], false)) { Image imageSave = Image.FromStream(imageStream); byte[] imageBytes = originalImagesData[i]; imageInfo.Width = imageSave.Width; imageInfo.Height = imageSave.Height; imageInfo.ImageOffset = currentOffset; imageInfo.ImageSize = imageBytes.Length; fuiBytes.AddRange(imageInfo.ToByteArray()); imageSection.AddRange(imageBytes); currentOffset += imageBytes.Length; imageSave.Dispose(); } } fuiBytes.AddRange(imageSection); File.WriteAllBytes(filepath, FuiUtils.ProcessHeader(fuiBytes.ToArray())); OnSavedFui(filepath); }
private void OnClickFileSaveAllImages(object sender, EventArgs e) { Dictionary <ImageFormat, string> extensions = new Dictionary <ImageFormat, string>() { { ImageFormat.Png, ".png" }, { ImageFormat.Jpeg, ".jpg" } }; CommonOpenFileDialog fileDialog = new CommonOpenFileDialog(Resources.DialogSaveAllImages) { IsFolderPicker = true, RestoreDirectory = true }; if (fileDialog.ShowDialog() == CommonFileDialogResult.Ok) { string directorySelected = fileDialog.FileName; string filepathBase = Path.Combine( directorySelected, Path.GetFileNameWithoutExtension(currentOpenFui) + "_{0}{1}"); for (int i = 0; i < originalImageFormats.Count; i++) { ImageFormat imageFormat = originalImageFormats[i]; FuiImageInfo imageInfo = fuiImageInfo[i]; int attribute = imageInfo.Attribute; string filepath; if (extensions.ContainsKey(imageFormat)) { string extension = extensions[imageFormat]; filepath = string.Format(filepathBase, i, extension); } else { filepath = string.Format(filepathBase, i, ".unknown"); } File.WriteAllBytes(filepath, originalImagesData[i]); } } }
public static FuiImageInfo[] GetImageInfo(byte[] filedata, int imageIndex) { Stack <FuiImageInfo> imageInfoStack = new Stack <FuiImageInfo>(); int currentOffset = imageIndex - FuiImageInfo.NativeSize; while (true) { FuiImageInfo imageInfo = new FuiImageInfo(); imageInfo.Read(filedata, currentOffset); imageInfoStack.Push(imageInfo); if (imageInfo.ImageOffset == 0) { break; } currentOffset -= FuiImageInfo.NativeSize; } return(imageInfoStack.ToArray()); }
private void OnClickImagesSave(object sender, EventArgs e) { Dictionary <ImageFormat, string> extensions = new Dictionary <ImageFormat, string>() { { ImageFormat.Png, ".png" }, { ImageFormat.Jpeg, ".jpg" } }; CommonFileDialogCheckBox correctColorCb = new CommonFileDialogCheckBox("correctColorCb", Resources.DialogCorrectColor, false); CommonOpenFileDialog fileDialog = new CommonOpenFileDialog(Resources.DialogSaveSelectedImages) { Controls = { correctColorCb }, IsFolderPicker = true, RestoreDirectory = true }; if (fileDialog.ShowDialog() == CommonFileDialogResult.Ok) { string directorySelected = fileDialog.FileName; string filepathBase = Path.Combine( directorySelected, Path.GetFileNameWithoutExtension(currentOpenFui) + "_{0}{1}"); int[] selectedIndices = imageListView.SelectedIndices.Cast <int>().ToArray(); for (int i = 0; i < selectedIndices.Length; i++) { int selected = selectedIndices[i]; ImageFormat imageFormat = originalImageFormats[selected]; FuiImageInfo imageInfo = fuiImageInfo[selected]; byte[] filedata = originalImagesData[selected]; string filepath; if (extensions.ContainsKey(imageFormat)) { string extension = extensions[imageFormat]; filepath = string.Format(filepathBase, i, extension); } else { filepath = string.Format(filepathBase, i, ".unknown"); } if (!correctColorCb.IsChecked) { File.WriteAllBytes(filepath, filedata); } else { using (MemoryStream stream = new MemoryStream(filedata, false)) { Image imageSave = Image.FromStream(stream); ImageUtils.ReverseColorRB((Bitmap)imageSave); imageSave.Save(filepath, imageFormat); imageSave.Dispose(); } } } } }