本文整理汇总了C#中PaintDotNet.Surface.CreateAliasedBitmap方法的典型用法代码示例。如果您正苦于以下问题:C# Surface.CreateAliasedBitmap方法的具体用法?C# Surface.CreateAliasedBitmap怎么用?C# Surface.CreateAliasedBitmap使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PaintDotNet.Surface
的用法示例。
在下文中一共展示了Surface.CreateAliasedBitmap方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Save
public static void Save(Document input, Stream output, Surface scratchSurface, ImageFormat format, ProgressEventHandler callback)
{
// flatten the document
scratchSurface.Clear(ColorBgra.FromBgra(0, 0, 0, 0));
using (RenderArgs ra = new RenderArgs(scratchSurface))
{
input.Render(ra, true);
}
using (Bitmap bitmap = scratchSurface.CreateAliasedBitmap())
{
LoadProperties(bitmap, input);
bitmap.Save(output, format);
}
}
示例2: OnSaveT
protected override void OnSaveT(Document input, Stream output, PropertyBasedSaveConfigToken token, Surface scratchSurface, ProgressEventHandler progressCallback)
{
int quality = token.GetProperty<Int32Property>(PropertyNames.Quality).Value;
ImageCodecInfo icf = GdiPlusFileType.GetImageCodecInfo(ImageFormat.Jpeg);
EncoderParameters parms = new EncoderParameters(1);
EncoderParameter parm = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, quality);
parms.Param[0] = parm;
scratchSurface.Clear(ColorBgra.White);
using (RenderArgs ra = new RenderArgs(scratchSurface))
{
input.Render(ra, false);
}
using (Bitmap bitmap = scratchSurface.CreateAliasedBitmap())
{
GdiPlusFileType.LoadProperties(bitmap, input);
bitmap.Save(output, icf, parms);
}
}
示例3: OnSave
protected override void OnSave(Document input, Stream output, SaveConfigToken token, Surface scratchSurface, ProgressEventHandler callback)
{
JpegSaveConfigToken jsct = (JpegSaveConfigToken)token;
ImageCodecInfo icf = GdiPlusFileType.GetImageCodecInfo(ImageFormat.Jpeg);
EncoderParameters parms = new EncoderParameters(1);
EncoderParameter parm = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, jsct.Quality); // force '95% quality'
parms.Param[0] = parm;
scratchSurface.Clear(ColorBgra.White);
using (RenderArgs ra = new RenderArgs(scratchSurface))
{
input.Render(ra, true);
}
using (Bitmap bitmap = scratchSurface.CreateAliasedBitmap())
{
GdiPlusFileType.LoadProperties(bitmap, input);
bitmap.Save(output, icf, parms);
}
}
示例4: Quantize
/// <summary>
/// Takes a Surface and quantizes it down to an 8-bit bitmap.
/// </summary>
/// <param name="quantizeMe">The Surface to quantize.</param>
/// <param name="ditherAmount">How strong should dithering be applied. 0 for no dithering, 8 for full dithering.</param>
/// <param name="maxColors">The maximum number of colors to use. This may range from 2 to 255.</param>
/// <param name="progressCallback">The progress callback delegate.</param>
/// <returns>An 8-bit Bitmap that is the same size as quantizeMe.</returns>
protected Bitmap Quantize(Surface quantizeMe, int ditherAmount, int maxColors, ProgressEventHandler progressCallback)
{
if (ditherAmount < 0 || ditherAmount > 8)
{
throw new ArgumentOutOfRangeException(
"ditherAmount",
ditherAmount,
"Out of bounds. Must be in the range [0, 8]");
}
if (maxColors < 2 || maxColors > 255)
{
throw new ArgumentOutOfRangeException(
"maxColors",
maxColors,
"Out of bounds. Must be in the range [2, 255]");
}
using (Bitmap bitmap = quantizeMe.CreateAliasedBitmap(quantizeMe.Bounds, true))
{
OctreeQuantizer quantizer = new OctreeQuantizer(maxColors, 8);
quantizer.DitherLevel = ditherAmount;
Bitmap quantized = quantizer.Quantize(bitmap, progressCallback);
return quantized;
}
}
示例5: resize
private static BitmapEx resize(Bitmap bitmap, int width, int height, Rectangle? clipRectangle)
{
using (var src = Surface.CopyFromBitmap(bitmap))
{
var dest = new Surface(width, height);
BitmapEx res = new BitmapEx();
res.surface = dest;
dest.FitSurface(ResamplingAlgorithm.SuperSampling, src);
if (clipRectangle == null)
res.Bitmap = dest.CreateAliasedBitmap();
else
res.Bitmap = dest.CreateAliasedBitmap(clipRectangle.Value);
return res;
}
}
示例6: FinalSave
internal override unsafe void FinalSave(
Document input,
Stream output,
Surface scratchSurface,
int ditherLevel,
SavableBitDepths bitDepth,
PropertyBasedSaveConfigToken token,
ProgressEventHandler progressCallback)
{
if (bitDepth == SavableBitDepths.Rgba32)
{
ImageCodecInfo icf = GdiPlusFileType.GetImageCodecInfo(ImageFormat.Png);
EncoderParameters parms = new EncoderParameters(1);
EncoderParameter parm = new EncoderParameter(System.Drawing.Imaging.Encoder.ColorDepth, 32);
parms.Param[0] = parm;
using (Bitmap bitmap = scratchSurface.CreateAliasedBitmap())
{
GdiPlusFileType.LoadProperties(bitmap, input);
bitmap.Save(output, icf, parms);
}
}
else if (bitDepth == SavableBitDepths.Rgb24)
{
// In order to save memory, we 'squish' the 32-bit bitmap down to 24-bit in-place
// instead of allocating a new bitmap and copying it over.
SquishSurfaceTo24Bpp(scratchSurface);
ImageCodecInfo icf = GdiPlusFileType.GetImageCodecInfo(ImageFormat.Png);
EncoderParameters parms = new EncoderParameters(1);
EncoderParameter parm = new EncoderParameter(System.Drawing.Imaging.Encoder.ColorDepth, 24);
parms.Param[0] = parm;
using (Bitmap bitmap = CreateAliased24BppBitmap(scratchSurface))
{
GdiPlusFileType.LoadProperties(bitmap, input);
bitmap.Save(output, icf, parms);
}
}
else if (bitDepth == SavableBitDepths.Rgb8)
{
using (Bitmap quantized = Quantize(scratchSurface, ditherLevel, 256, false, progressCallback))
{
ImageCodecInfo icf = GdiPlusFileType.GetImageCodecInfo(ImageFormat.Png);
EncoderParameters parms = new EncoderParameters(1);
EncoderParameter parm = new EncoderParameter(System.Drawing.Imaging.Encoder.ColorDepth, 8);
parms.Param[0] = parm;
GdiPlusFileType.LoadProperties(quantized, input);
quantized.Save(output, icf, parms);
}
}
else if (bitDepth == SavableBitDepths.Rgba8)
{
using (Bitmap quantized = Quantize(scratchSurface, ditherLevel, 256, true, progressCallback))
{
ImageCodecInfo icf = GdiPlusFileType.GetImageCodecInfo(ImageFormat.Png);
EncoderParameters parms = new EncoderParameters(1);
EncoderParameter parm = new EncoderParameter(System.Drawing.Imaging.Encoder.ColorDepth, 8);
parms.Param[0] = parm;
GdiPlusFileType.LoadProperties(quantized, input);
quantized.Save(output, icf, parms);
}
}
else
{
throw new InvalidEnumArgumentException("bitDepth", (int)bitDepth, typeof(SavableBitDepths));
}
}
示例7: Quantize
/// <summary>
/// Takes a Surface and quantizes it down to an 8-bit bitmap.
/// </summary>
/// <param name="quantizeMe">The Surface to quantize.</param>
/// <param name="ditherAmount">How strong should dithering be applied. 0 for no dithering, 8 for full dithering. 7 is generally a good default to use.</param>
/// <param name="maxColors">The maximum number of colors to use. This may range from 2 to 256.</param>
/// <param name="enableTransparency">If true, then one color slot will be reserved for transparency. Any color with an alpha value less than 255 will be transparent in the output.</param>
/// <param name="progressCallback">The progress callback delegate.</param>
/// <returns>An 8-bit Bitmap that is the same size as quantizeMe.</returns>
protected Bitmap Quantize(Surface quantizeMe, int ditherAmount, int maxColors, bool enableTransparency, ProgressEventHandler progressCallback)
{
if (ditherAmount < 0 || ditherAmount > 8)
{
throw new ArgumentOutOfRangeException(
"ditherAmount",
ditherAmount,
"Out of bounds. Must be in the range [0, 8]");
}
if (maxColors < 2 || maxColors > 256)
{
throw new ArgumentOutOfRangeException(
"maxColors",
maxColors,
"Out of bounds. Must be in the range [2, 256]");
}
// TODO: detect if transparency is needed? or take another argument
using (Bitmap bitmap = quantizeMe.CreateAliasedBitmap(quantizeMe.Bounds, true))
{
OctreeQuantizer quantizer = new OctreeQuantizer(maxColors, enableTransparency);
quantizer.DitherLevel = ditherAmount;
Bitmap quantized = quantizer.Quantize(bitmap, progressCallback);
return quantized;
}
}