예제 #1
0
 private static byte[] Encode(Bitmap icon, int quality)
 {
     using (JpegEncoder jpegEncoder = new JpegEncoder())
     {
         BitmapData bitmapdata = icon.LockBits(new Rectangle(0, 0, icon.Width, icon.Height), ImageLockMode.ReadOnly, icon.PixelFormat);
         byte[]     numArray   = new byte[icon.Height * bitmapdata.Stride];
         Marshal.Copy(bitmapdata.Scan0, numArray, 0, numArray.Length);
         icon.UnlockBits(bitmapdata);
         IconConverter.CorrectRgbChannel(numArray, icon.PixelFormat);
         IconConverter.ThrowExceptionIfJpegResultFail(jpegEncoder.SetPixelData(numArray, icon.PixelFormat, IconConverter.ToSize(icon.PhysicalDimension), 1));
         jpegEncoder.SetQuality(quality);
         jpegEncoder.SetSamplingRatio(SamplingRatio.Ratio_444);
         byte[] outBuffer;
         IconConverter.ThrowExceptionIfJpegResultFail(jpegEncoder.Encode(out outBuffer, new Exif()
         {
             Software = "Nintendo AuthoringTool"
         }));
         return(outBuffer);
     }
 }