diff --git a/ComicCompress.csproj.user b/ComicCompress.csproj.user index 318fa22..c210ea3 100644 --- a/ComicCompress.csproj.user +++ b/ComicCompress.csproj.user @@ -4,7 +4,7 @@ ProjectDebugger - PROD + DEV_UFF ProjectDebugger diff --git a/Program.cs b/Program.cs index 19d26a9..709c267 100644 --- a/Program.cs +++ b/Program.cs @@ -370,10 +370,11 @@ namespace ComicCompressor { byte[] img = drawer.Draw(labelInfo.ZplElements); outputPath = Path.Join(OutputFolder, Path.ChangeExtension(relativePath, ".prn.png")); + Directory.CreateDirectory(Path.GetDirectoryName(outputPath)); File.WriteAllBytes(outputPath, img); //imageData is bytes of png image string base64String = Convert.ToBase64String(img); - + base64String = "data:image/png;base64," + base64String; File.WriteAllText(outputPath + ".base64", base64String); } } @@ -732,6 +733,8 @@ namespace ComicCompressor #endregion #region COMPRESS_IMAGE + + public void CompressImage(string imagefile, string outputFolder, int max_name_len = -1, Boolean isPar = false, string print_line_header = "") { string name_print = imagefile; @@ -765,25 +768,62 @@ namespace ComicCompressor if (DoPrn) { + var image = Image.FromStream(BitmapStream); + + using (EncoderParameters encParams = new EncoderParameters(1)) + { + using (EncoderParameter encoderParameter = new EncoderParameter(Encoder.Quality, 33L)) + { + encParams.Param[0] = encoderParameter; + var encoderJpeg = ImageCodecInfo.GetImageEncoders() + .First(c => c.FormatID == ImageFormat.Jpeg.Guid); + + var stream = new MemoryStream(); + // image.Save(stream, ImageFormat.Jpeg); + image.Save(stream, encoderJpeg, encParams); + + byte[] imageBytes = stream.ToArray(); + string base64String = Convert.ToBase64String(imageBytes); + base64String = "data:image/jpeg;base64," + base64String; + + string outjpeg = outputFolder.Replace("webp", "jpeg"); + + File.WriteAllText(outjpeg + ".base64", base64String); + + FileStream outStreamjpeg = new FileStream(outjpeg, FileMode.Create); + stream.Position = 0; + stream.CopyTo(outStreamjpeg); + outStreamjpeg.Flush(); + outStreamjpeg.Close(); + } + } + + + + + +#if true using (MemoryStream m = new MemoryStream()) { encoder.Encode(mBitmap, m, 70); byte[] imageBytes = m.ToArray(); string base64String = Convert.ToBase64String(imageBytes); + base64String = "data:image/webp;base64," + base64String; File.WriteAllText(outputFolder + ".base64", base64String); - byte[] imageBytes_o = Convert.FromBase64String(base64String); - using (MemoryStream ms = new MemoryStream(imageBytes_o)) - { - // Create image from memory stream - using (FileStream file = new FileStream(outputFolder + ".base64.webp", FileMode.Create, System.IO.FileAccess.Write)) - { + //byte[] imageBytes_o = Convert.FromBase64String(base64String); + //using (MemoryStream ms = new MemoryStream(imageBytes_o)) + //{ + // // Create image from memory stream + // using (FileStream file = new FileStream(outputFolder + ".base64.webp", FileMode.Create, System.IO.FileAccess.Write)) + // { - ms.WriteTo(file); - } - } + // ms.WriteTo(file); + // } + //} } +#endif } //encoder.Encode(mBitmap, 70, out result, out length); //UnmanagedMemoryStream ustream = new UnmanagedMemoryStream((byte*)result, length); diff --git a/Properties/launchSettings.json b/Properties/launchSettings.json index 5dfeccb..e0f0608 100644 --- a/Properties/launchSettings.json +++ b/Properties/launchSettings.json @@ -23,6 +23,10 @@ "PROD": { "commandName": "Project", "commandLineArgs": "-i \"K:\\_RPG_\\__THE_AMBER_ROOM_UPDATE\\__ASSETS__\\_IMG_\" -o \"K:\\_RPG_\\__THE_AMBER_ROOM_UPDATE\\__ASSETS__\\_IMG_WEBP_\" -r -s -j -a" + }, + "DEV_UFF": { + "commandName": "Project", + "commandLineArgs": "-i \"E:\\SynologyDrive\\SynologyDrive\\A\\_PRINT_TEMPLATES_\\DEV_IN\" -o \"E:\\SynologyDrive\\SynologyDrive\\A\\_PRINT_TEMPLATES_\\DEV_OUT\" -r -s -j -a -n" } } } \ No newline at end of file