Fixed hard coded Encoder, if sometime the encoder order changes this would have broken the code. Also removed a stream wrapper.

git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@2130 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
RKrom 2012-10-09 10:01:37 +00:00
parent b600d72156
commit 5714b59a14
2 changed files with 16 additions and 9 deletions

View file

@ -256,12 +256,10 @@ namespace GreenshotPlugin.Core {
int iImageSize = BitConverter.ToInt32(srcBuf, SizeICONDIR + SizeICONDIRENTRY * iIndex + 8);
int iImageOffset = BitConverter.ToInt32(srcBuf, SizeICONDIR + SizeICONDIRENTRY * iIndex + 12);
using (MemoryStream destStream = new MemoryStream()) {
using (BinaryWriter writer = new BinaryWriter(destStream)) {
writer.Write(srcBuf, iImageOffset, iImageSize);
destStream.Write(srcBuf, iImageOffset, iImageSize);
destStream.Seek(0, System.IO.SeekOrigin.Begin);
bmpPngExtracted = new Bitmap(destStream); // This is PNG! :)
}
}
break;
}
}

View file

@ -157,10 +157,19 @@ namespace GreenshotPlugin.Core {
}
if (imageFormat == ImageFormat.Jpeg) {
bool foundEncoder = false;
foreach (ImageCodecInfo imageCodec in ImageCodecInfo.GetImageEncoders()) {
if (imageCodec.FormatID == imageFormat.Guid) {
EncoderParameters parameters = new EncoderParameters(1);
parameters.Param[0] = new System.Drawing.Imaging.EncoderParameter(Encoder.Quality, outputSettings.JPGQuality);
ImageCodecInfo[] ies = ImageCodecInfo.GetImageEncoders();
imageToSave.Save(targetStream, ies[1], parameters);
parameters.Param[0] = new EncoderParameter(Encoder.Quality, outputSettings.JPGQuality);
imageToSave.Save(targetStream, imageCodec, parameters);
foundEncoder = true;
break;
}
}
if (!foundEncoder) {
throw new ApplicationException("No JPG encoder found, this should not happen.");
}
} else if (imageFormat != ImageFormat.Png && Image.IsAlphaPixelFormat(imageToSave.PixelFormat)) {
// No transparency in target format
using (Bitmap tmpBitmap = ImageHelper.Clone(imageToSave, PixelFormat.Format24bppRgb)) {