Resize
内容
[
隐藏
]Resize(int, int)
调整图像大小。默认NearestNeighbourResample已使用。
public void Resize(int newWidth, int newHeight)
范围 | 类型 | 描述 |
---|---|---|
newWidth | Int32 | 新的宽度。 |
newHeight | Int32 | 新高度。 |
例子
以下示例显示如何调整图元文件(WMF 和 EMF)的大小。
[C#]
string dir = "c:\\aspose.imaging\\issues\\net\\3280\\";
string[] fileNames = new[] { "image3.emf", "image4.wmf" };
foreach (string fileName in fileNames)
{
string inputFilePath = dir + fileName;
string outputFilePath = dir + "Downscale_" + fileName;
using (Aspose.Imaging.FileFormats.Emf.MetaImage image = (Aspose.Imaging.FileFormats.Emf.MetaImage)Aspose.Imaging.Image.Load(inputFilePath))
{
image.Resize(image.Width / 4, image.Height / 4);
image.Save(outputFilePath);
}
}
以下示例显示如何调整 SVG 图像的大小并将其保存为 PNG。
[C#]
string dir = "c:\\aspose.imaging\\net\\issues\\3549";
string[] fileNames = new string[]
{
"Logotype.svg",
"sample_car.svg",
"rg1024_green_grapes.svg",
"MidMarkerFigure.svg",
"embeddedFonts.svg"
};
Aspose.Imaging.PointF[] scales = new Aspose.Imaging.PointF[]
{
new Aspose.Imaging.PointF(0.5f, 0.5f),
new Aspose.Imaging.PointF(1f, 1f),
new Aspose.Imaging.PointF(2f, 2f),
new Aspose.Imaging.PointF(3.5f, 9.2f),
};
foreach (string inputFile in fileNames)
{
foreach (Aspose.Imaging.PointF scale in scales)
{
string outputFile = string.Format("{0}_{1}_{2}.png", inputFile, scale.X.ToString(System.Globalization.CultureInfo.InvariantCulture), scale.Y.ToString(System.Globalization.CultureInfo.InvariantCulture));
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(System.IO.Path.Combine(dir, inputFile)))
{
image.Resize((int)(image.Width * scale.X), (int)(image.Height * scale.Y));
image.Save(System.IO.Path.Combine(dir, outputFile), new Aspose.Imaging.ImageOptions.PngOptions());
}
}
}
也可以看看
- class Image
- 命名空间 Aspose.Imaging
- 部件 Aspose.Imaging
Resize(int, int, ResizeType)
调整图像大小。
public abstract void Resize(int newWidth, int newHeight, ResizeType resizeType)
范围 | 类型 | 描述 |
---|---|---|
newWidth | Int32 | 新的宽度。 |
newHeight | Int32 | 新高度。 |
resizeType | ResizeType | 调整大小类型。 |
例子
使用特定的调整大小类型调整图像大小。
[C#]
using (var image = Image.Load("Photo.jpg"))
{
image.Resize(640, 480, ResizeType.CatmullRom);
image.Save("ResizedPhoto.jpg");
image.Resize(1024, 768, ResizeType.CubicConvolution);
image.Save("ResizedPhoto2.jpg");
var resizeSettings = new ImageResizeSettings
{
Mode = ResizeType.CubicBSpline,
FilterType = ImageFilterType.SmallRectangular
};
image.Resize(800, 800, resizeSettings);
image.Save("ResizedPhoto3.jpg");
}
此示例加载图像并使用各种调整大小的方法调整其大小。
[C#]
string dir = "c:\\temp\\";
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.gif"))
{
// 使用最近邻重采样放大 2 倍。
image.Resize(image.Width* 2, image.Height* 2, Aspose.Imaging.ResizeType.NearestNeighbourResample);
image.Save(dir + "upsample.nearestneighbour.gif");
}
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.gif"))
{
// 使用最近邻重采样缩小 2 倍。
image.Resize(image.Width / 2, image.Height / 2, Aspose.Imaging.ResizeType.NearestNeighbourResample);
image.Save(dir + "downsample.nearestneighbour.gif");
}
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.gif"))
{
// 使用双线性重采样放大 2 倍。
image.Resize(image.Width* 2, image.Height* 2, Aspose.Imaging.ResizeType.BilinearResample);
image.Save(dir + "upsample.bilinear.gif");
}
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.gif"))
{
// 使用双线性重采样缩小 2 倍。
image.Resize(image.Width / 2, image.Height / 2, Aspose.Imaging.ResizeType.BilinearResample);
image.Save(dir + "downsample.bilinear.gif");
}
使用分段掩码加快分段过程
[C#]
// 屏蔽导出选项
Aspose.Imaging.ImageOptions.PngOptions exportOptions = new Aspose.Imaging.ImageOptions.PngOptions();
exportOptions.ColorType = Aspose.Imaging.FileFormats.Png.PngColorType.TruecolorWithAlpha;
exportOptions.Source = new Aspose.Imaging.Sources.StreamSource(new System.IO.MemoryStream());
Aspose.Imaging.Masking.Options.MaskingOptions maskingOptions = new Aspose.Imaging.Masking.Options.MaskingOptions();
// 使用 GraphCut 聚类。
maskingOptions.Method = Masking.Options.SegmentationMethod.GraphCut;
maskingOptions.Decompose = false;
maskingOptions.Args = new Aspose.Imaging.Masking.Options.AutoMaskingArgs();
// 背景颜色将是透明的。
maskingOptions.BackgroundReplacementColor = Aspose.Imaging.Color.Transparent;
maskingOptions.ExportOptions = exportOptions;
string dir = "c:\\temp\\";
using (Aspose.Imaging.RasterImage image = (Aspose.Imaging.RasterImage)Aspose.Imaging.Image.Load(dir + "BigImage.jpg"))
{
Aspose.Imaging.Size imageSize = image.Size;
// 减小图像大小以加快分割过程
image.ResizeHeightProportionally(600, Aspose.Imaging.ResizeType.HighQualityResample);
// 创建 ImageMasking 类的实例。
Aspose.Imaging.Masking.ImageMasking masking = new Aspose.Imaging.Masking.ImageMasking(image);
// 将源图像分成几个簇(段)。
using (Aspose.Imaging.Masking.Result.MaskingResult maskingResult = masking.Decompose(maskingOptions))
{
// 获取前景蒙版
using (Aspose.Imaging.RasterImage foregroundMask = maskingResult[1].GetMask())
{
// 将蒙版的大小增加到原始图像的大小
foregroundMask.Resize(imageSize.Width, imageSize.Height, Aspose.Imaging.ResizeType.NearestNeighbourResample);
// 将掩码应用于原始图像以获得前景段
using (Aspose.Imaging.RasterImage originImage = (Aspose.Imaging.RasterImage)Aspose.Imaging.Image.Load(dir + "BigImage.jpg"))
{
Aspose.Imaging.Masking.ImageMasking.ApplyMask(originImage, foregroundMask, maskingOptions);
originImage.Save(dir + "BigImage_foreground.png", exportOptions);
}
}
}
}
也可以看看
- enum ResizeType
- class Image
- 命名空间 Aspose.Imaging
- 部件 Aspose.Imaging
Resize(int, int, ImageResizeSettings)
调整图像大小。
public abstract void Resize(int newWidth, int newHeight, ImageResizeSettings settings)
范围 | 类型 | 描述 |
---|---|---|
newWidth | Int32 | 新的宽度。 |
newHeight | Int32 | 新高度。 |
settings | ImageResizeSettings | 调整大小设置。 |
例子
使用特定的调整大小类型调整图像大小。
[C#]
using (var image = Image.Load("Photo.jpg"))
{
image.Resize(640, 480, ResizeType.CatmullRom);
image.Save("ResizedPhoto.jpg");
image.Resize(1024, 768, ResizeType.CubicConvolution);
image.Save("ResizedPhoto2.jpg");
var resizeSettings = new ImageResizeSettings
{
Mode = ResizeType.CubicBSpline,
FilterType = ImageFilterType.SmallRectangular
};
image.Resize(800, 800, resizeSettings);
image.Save("ResizedPhoto3.jpg");
}
此示例加载图像并使用各种调整大小设置调整其大小。
[C#]
string dir = "c:\\temp\\";
Aspose.Imaging.ImageResizeSettings resizeSettings = new Aspose.Imaging.ImageResizeSettings();
// 基于加权混合有理函数和 lanczos3 插值的自适应算法。
resizeSettings.Mode = Aspose.Imaging.ResizeType.AdaptiveResample;
// 小矩形过滤器
resizeSettings.FilterType = Aspose.Imaging.ImageFilterType.SmallRectangular;
// 调色板中的颜色数量。
resizeSettings.EntriesCount = 256;
// 不使用颜色量化
resizeSettings.ColorQuantizationMethod = ColorQuantizationMethod.None;
// 欧几里得方法
resizeSettings.ColorCompareMethod = ColorCompareMethod.Euclidian;
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.gif"))
{
// 使用自适应重采样缩小 2 倍。
image.Resize(image.Width / 2, image.Height / 2, resizeSettings);
image.Save(dir + "downsample.adaptive.gif");
}
也可以看看
- class ImageResizeSettings
- class Image
- 命名空间 Aspose.Imaging
- 部件 Aspose.Imaging