![]() Reducing the image file size as much as possible helps to save bandwidth cost, reduce time to download, and even achieve a higher Google PageSpeed score because “optimize images” is one of the priorities. You can easily find many tools on the Internet to compress image files but most, if not all of them produce different file sizes. The newer WebP is dual role because you can compress images with either lossless or lossy compression but it’s a bit less compatible than JPEG and PNG. PNG is good on smaller and transparent pictures because it’s lossless and you don’t lose quality. If this could be altered, it would a lot better.The GIF image format is commonly used for short animated images while JPEG is for higher quality photos using lossy compression to reduce file sizes. ImageCodecInfo jpgEncoder = GetEncoder(ImageFormat.Png) Bitmap bmp1 = new Bitmap(imageFile) //pathOfImage) ![]() UpdateStatusText = UpdateStatusText.Replace(ImageName, ImageName "," Status) įile.WriteAllText(_StatusLog, UpdateStatusText) įile.AppendAllText(_StatusLog, Environment.NewLine) įor PNG compression i changed the following line. ![]() String UpdateStatusText = File.ReadAllText(_StatusLog) Sec.AddAccessRule(new FileSystemAccessRule(everyone, FileSystemRights.Modify | FileSystemRights.Synchronize, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, PropagationFlags.None, AccessControlType.Allow)) ĭirectory.SetAccessControl(_StatusLog, sec) SecurityIdentifier everyone = new SecurityIdentifier(WellKnownSidType.WorldSid, null) Public static void LoggingOperations(string ImageName, string Status, bool UpdateRequired)ĭirectorySecurity sec = Directory.GetAccessControl(_StatusLog) String RemovingImageFormat = splitingPathOfImage.ToString().Split('.') String splitingPathOfImage = pathOfImage.Split('\\') Public string GettingImageNameForOptimizedImage(string pathOfImage) ImageCodecInfo codecs = ImageCodecInfo.GetImageDecoders() Private ImageCodecInfo GetEncoder(ImageFormat format) System.IO.File.Move(filesInSubDir "\\" "Zip" GettingImageNameForOptimizedImage(imageFile), filesInSubDir "\\" GettingImageNameForOptimizedImage(imageFile)) Ĭonsole.Write("\n" ex.Message " Press enter to continue :") Ĭonsole.Write("\nWould you like to retry ? :") Ĭonsole.WriteLine(" -\n\n") Ĭonsole.Write("Press any key to exit.") #region BACK RENAMING FILE TO ORIGNAL NAME bmp1.Save("D:\\" RemovingImageFormat "100L" ".jpg", jpgEncoder, myEncoderParameters) myEncoderParameters.Param = myEncoderParameter myEncoderParameter = new EncoderParameter(myEncoder, 100L) System.IO.File.Delete(filesInSubDir "\\" GettingImageNameForOptimizedImage(imageFile)) //pathOfImageĬonsole.WriteLine(imageFile.Replace("jpg", "png") " DELETED") //pathOfImage MyEncoderParameters.Param = myEncoderParameter īmp1.Save(filesInSubDir "\\" "Zip" GettingImageNameForOptimizedImage(imageFile), jpgEncoder, myEncoderParameters) //pathOfImageĬonsole.WriteLine(filesInSubDir GettingImageNameForOptimizedImage(imageFile) " CREATED") //pathOfImage In this case, there is only oneĮncoderParameters myEncoderParameters = new EncoderParameters(1) ĮncoderParameter myEncoderParameter = new EncoderParameter(myEncoder, 50L) ![]() An EncoderParameters object has an array of EncoderParameter Create an Encoder object based on the GUID ImageCodecInfo jpgEncoder = GetEncoder(ImageFormat.Jpeg) String allFilesInSubDir = Directory.GetFiles(filesInSubDir) įoreach (var imageFile in allFilesInSubDir)īitmap bmp1 = new Bitmap(imageFile) //pathOfImage) String subDirectory = Directory.GetDirectories(directory) // ATTRIBUTE DIRECTORY OPENįoreach (var filesInSubDir in subDirectory) String allDirectoryInTargetDirectory = Directory.GetDirectories(targetDirectory) Ĭonsole.Write("Total Folders found = " allDirectoryInTargetDirectory.Count()) įoreach (var directory in allDirectoryInTargetDirectory) String targetDirectory = pathOfImage //Console.ReadLine() Console.Write("Target Directory Path :") Private void VaryQualityLevel(string pathOfImage) public const string _StatusLog = "StatusLog.csv" Ĭonsole.Write("\n\nPlease enter image folder path :") Picture compressed about 90% and quality remain the same but when i compress a PNG image with it. I want to compress a PNG image, to reduce its size but the quality should remain the same.
0 Comments
Leave a Reply. |