internal override void OnFinalSave(Document input, Stream output, Surface scratchSurface, int ditherLevel, InternalFileType.SavableBitDepths bitDepth, PropertyBasedSaveConfigToken token, ProgressEventHandler progressCallback) { if (bitDepth == InternalFileType.SavableBitDepths.Rgb24) { base.SquishSurfaceTo24Bpp(scratchSurface); ImageCodecInfo imageCodecInfo = GdiPlusFileType.GetImageCodecInfo(ImageFormat.Bmp); EncoderParameters encoderParams = new EncoderParameters(1); EncoderParameter parameter = new EncoderParameter(Encoder.ColorDepth, 0x18); encoderParams.Param[0] = parameter; using (Bitmap bitmap = base.CreateAliased24BppBitmap(scratchSurface)) { GdiPlusFileType.LoadProperties(bitmap, input); bitmap.Save(output, imageCodecInfo, encoderParams); return; } } if (bitDepth == InternalFileType.SavableBitDepths.Rgb8) { using (Bitmap bitmap2 = base.Quantize(scratchSurface, ditherLevel, 0x100, false, progressCallback)) { ImageCodecInfo encoder = GdiPlusFileType.GetImageCodecInfo(ImageFormat.Bmp); EncoderParameters parameters2 = new EncoderParameters(1); EncoderParameter parameter2 = new EncoderParameter(Encoder.ColorDepth, 8); parameters2.Param[0] = parameter2; GdiPlusFileType.LoadProperties(bitmap2, input); bitmap2.Save(output, encoder, parameters2); return; } } throw ExceptionUtil.InvalidEnumArgumentException <InternalFileType.SavableBitDepths>(bitDepth, "bitDepth"); }
static PdnFileTypes() { string[] extensions = new string[] { ".tif", ".tiff" }; Tiff = new GdiPlusFileType("TIFF", ImageFormat.Tiff, false, extensions); Png = new PngFileType(); Pdn = new PdnFileType(); Tga = new TgaFileType(); Dds = new DdsFileType(); fileTypes = new FileType[] { Pdn, Bmp, Gif, Jpeg, Png, Tiff, Tga, Dds }; }
internal override void OnFinalSave(Document input, Stream output, Surface scratchSurface, int ditherLevel, InternalFileType.SavableBitDepths bitDepth, PropertyBasedSaveConfigToken token, ProgressEventHandler progressCallback) { int num; Bitmap bitmap; Func <PropertyItem, bool> func; ImageCodecInfo imageCodecInfo = GdiPlusFileType.GetImageCodecInfo(ImageFormat.Png); EncoderParameters encoderParams = new EncoderParameters(1); if (bitDepth == InternalFileType.SavableBitDepths.Rgba32) { num = 0x20; bitmap = scratchSurface.CreateAliasedBitmap(); } else if (bitDepth == InternalFileType.SavableBitDepths.Rgb24) { base.SquishSurfaceTo24Bpp(scratchSurface); num = 0x18; bitmap = base.CreateAliased24BppBitmap(scratchSurface); } else if (bitDepth == InternalFileType.SavableBitDepths.Rgb8) { num = 8; bitmap = base.Quantize(scratchSurface, ditherLevel, 0x100, false, progressCallback); } else { if (bitDepth != InternalFileType.SavableBitDepths.Rgba8) { throw ExceptionUtil.InvalidEnumArgumentException <InternalFileType.SavableBitDepths>(bitDepth, "bitDepth"); } num = 8; bitmap = base.Quantize(scratchSurface, ditherLevel, 0x100, true, progressCallback); } EncoderParameter parameter = new EncoderParameter(Encoder.ColorDepth, (long)num); encoderParams.Param[0] = parameter; if (num == 0x20) { func = pi => true; } else { int iccProfileDataID = 0x8773; func = pi => pi.Id != iccProfileDataID; } GdiPlusFileType.LoadProperties(bitmap, input, func); bitmap.Save(output, imageCodecInfo, encoderParams); bitmap.Dispose(); bitmap = null; }
protected override void OnSaveT(Document input, Stream output, PropertyBasedSaveConfigToken token, Surface scratchSurface, ProgressEventHandler progressCallback) { int num = token.GetProperty <Int32Property>(PropertyNames.Quality).Value; ImageCodecInfo imageCodecInfo = GdiPlusFileType.GetImageCodecInfo(ImageFormat.Jpeg); EncoderParameters encoderParams = new EncoderParameters(1); EncoderParameter parameter = new EncoderParameter(Encoder.Quality, (long)num); encoderParams.Param[0] = parameter; scratchSurface.Clear(ColorBgra.White); using (RenderArgs args = new RenderArgs(scratchSurface)) { input.Render(args, false); } using (Bitmap bitmap = scratchSurface.CreateAliasedBitmap()) { GdiPlusFileType.LoadProperties(bitmap, input); bitmap.Save(output, imageCodecInfo, encoderParams); } }