のアップロード中にので、私はPNGに画像を変換してZIP圧縮に建てを使用することをお勧め画質の緩いせずに画像を圧縮する必要があります。
public static void SaveToPNG(Bitmap SourceImage, string DestinationPath)
{
SourceImage.Save(DestinationPath, ImageFormat.Png);
CompressFile(DestinationPath, true);
}
private static string CompressFile(string SourceFile, bool DeleteSourceFile)
{
string TargetZipFileName = Path.ChangeExtension(SourceFile, ".zip");
using (ZipArchive archive = ZipFile.Open(TargetZipFileName, ZipArchiveMode.Create))
{
archive.CreateEntryFromFile(SourceFile, Path.GetFileName(SourceFile),CompressionLevel.Optimal);
}
if(DeleteSourceFile == true)
{
File.Delete(SourceFile);
}
return TargetZipFileName;
}
たり、あなたは少しunnoticable損失を気にしない場合、その後、あなたは、高品質でJPGに変換することができ、その後、それをZIP。 100%の品質では、ユーザーは違いが気付かれず、品質が低いほどイメージは小さくなりますが、「品質の低下なし」の条件を破ります。
private static ImageCodecInfo __JPEGCodecInfo = null;
private static ImageCodecInfo _JPEGCodecInfo
{
get
{
if (__JPEGCodecInfo == null)
{
__JPEGCodecInfo = ImageCodecInfo.GetImageEncoders().ToList().Find(delegate (ImageCodecInfo codec) { return codec.FormatID == ImageFormat.Jpeg.Guid; });
}
return __JPEGCodecInfo;
}
}
public static void SaveToJPEG(Bitmap SourceImage, string DestinationPath, long Quality)
{
EncoderParameters parameters = new EncoderParameters(1);
parameters.Param[0] = new EncoderParameter(Encoder.Quality, Quality);
SourceImage.Save(DestinationPath, _JPEGCodecInfo, parameters);
CompressFile(DestinationPath, true);
}
private static string CompressFile(string SourceFile, bool DeleteSourceFile)
{
string TargetZipFileName = Path.ChangeExtension(SourceFile, ".zip");
using (ZipArchive archive = ZipFile.Open(TargetZipFileName, ZipArchiveMode.Create))
{
archive.CreateEntryFromFile(SourceFile, Path.GetFileName(SourceFile),CompressionLevel.Optimal);
}
if(DeleteSourceFile == true)
{
File.Delete(SourceFile);
}
return TargetZipFileName;
}
出典
2015-12-31 02:27:43
Don
どのような画像ですか?それらがjpegの場合、それらはすでに圧縮されています。 – Candide
あなたは画像をアップロードしています。いくつかのJQueryプラグインを介してクライアント側の画像を圧縮することができれば、より良いでしょう...クライアント側の圧縮についてはこれを参照してください(http://stackoverflow.com/questions/4579193/uploadify-and-image-compression) –
ほとんどの画像フォーマットはすでに圧縮されています。それらをさらに圧縮し*品質を維持することはLaw&Order犯罪研究室でのみ可能です。 –