Class RasterImage
名称: Aspose.Imaging 收藏: Aspose.Imaging.dll (25.4.0)
代表支持拉斯特图形操作的拉斯特图像。
public abstract class RasterImage : Image, IDisposable, IObjectWithBounds, IRasterImageArgb32PixelLoader, IRasterImageRawDataLoader, IHasXmpData, IHasMetadata
Inheritance
object ← DisposableObject ← DataStreamSupporter ← Image ← RasterImage
Derived
Implements
IDisposable , IObjectWithBounds , IRasterImageArgb32PixelLoader , IRasterImageRawDataLoader , IHasXmpData , IHasMetadata
继承人
Image.CanLoad(string) , Image.CanLoad(string, LoadOptions) , Image.CanLoad(Stream) , Image.CanLoad(Stream, LoadOptions) , Image.Create(ImageOptionsBase, int, int) , Image.Create(Image[]) , Image.Create(MultipageCreateOptions) , Image.Create(string[], bool) , Image.Create(string[]) , Image.Create(Image[], bool) , Image.GetFileFormat(string) , Image.GetFileFormat(Stream) , Image.GetFittingRectangle(Rectangle, int, int) , Image.GetFittingRectangle(Rectangle, int[], int, int) , Image.Load(string, LoadOptions) , Image.Load(string) , Image.Load(Stream, LoadOptions) , Image.Load(Stream) , Image.GetProportionalWidth(int, int, int) , Image.GetProportionalHeight(int, int, int) , Image.RemoveMetadata() , Image.CanSave(ImageOptionsBase) , Image.Resize(int, int) , Image.Resize(int, int, ResizeType) , Image.Resize(int, int, ImageResizeSettings) , Image.GetDefaultOptions(object[]) , Image.GetOriginalOptions() , Image.ResizeWidthProportionally(int) , Image.ResizeHeightProportionally(int) , Image.ResizeWidthProportionally(int, ResizeType) , Image.ResizeHeightProportionally(int, ResizeType) , Image.ResizeWidthProportionally(int, ImageResizeSettings) , Image.ResizeHeightProportionally(int, ImageResizeSettings) , Image.RotateFlip(RotateFlipType) , Image.Rotate(float) , Image.Crop(Rectangle) , Image.Crop(int, int, int, int) , Image.Save() , Image.Save(string) , Image.Save(string, ImageOptionsBase) , Image.Save(string, ImageOptionsBase, Rectangle) , Image.Save(Stream, ImageOptionsBase) , Image.Save(Stream, ImageOptionsBase, Rectangle) , Image.GetSerializedStream(ImageOptionsBase, Rectangle, out int) , Image.SetPalette(IColorPalette, bool) , Image.UpdateContainer(Image) , Image.GetCanNotSaveMessage(ImageOptionsBase) , Image.GetFitRectangle(Rectangle) , Image.GetImage2Export(ImageOptionsBase, Rectangle, IImageExporter) , Image.GetFitRectangle(Rectangle, int[]) , Image.OnPaletteChanged(IColorPalette, IColorPalette) , Image.OnPaletteChanging(IColorPalette, IColorPalette) , Image.ReleaseManagedResources() , Image.BitsPerPixel , Image.Bounds , Image.Container , Image.Height , Image.Palette , Image.UsePalette , Image.Size , Image.Width , Image.InterruptMonitor , Image.BufferSizeHint , Image.AutoAdjustPalette , Image.HasBackgroundColor , Image.FileFormat , Image.BackgroundColor , DataStreamSupporter.timeout , DataStreamSupporter.CacheData() , DataStreamSupporter.Save() , DataStreamSupporter.Save(Stream) , DataStreamSupporter.Save(string) , DataStreamSupporter.Save(string, bool) , DataStreamSupporter.SaveData(Stream) , DataStreamSupporter.ReleaseManagedResources() , DataStreamSupporter.OnDataStreamContainerChanging(StreamContainer) , DataStreamSupporter.DataStreamContainer , DataStreamSupporter.IsCached , DisposableObject.Dispose() , DisposableObject.ReleaseManagedResources() , DisposableObject.ReleaseUnmanagedResources() , DisposableObject.VerifyNotDisposed() , DisposableObject.Disposed , object.GetType() , object.MemberwiseClone() , object.ToString() , object.Equals(object?) , object.Equals(object?, object?) , object.ReferenceEquals(object?, object?) , object.GetHashCode()
Examples
此示例显示如何在类型颜色序列中加载Pixel信息,操纵序列并将其重新设置为图像。 为了执行这些操作,此示例创建一个新的图像文件(GIF格式) uisng MemoryStream 对象。
//Create an instance of MemoryStream
using (System.IO.MemoryStream stream = new System.IO.MemoryStream())
{
//Create an instance of GifOptions and set its various properties including the Source property
Aspose.Imaging.ImageOptions.GifOptions gifOptions = new Aspose.Imaging.ImageOptions.GifOptions();
gifOptions.Source = new Aspose.Imaging.Sources.StreamSource(stream);
//Create an instance of Image
using (Aspose.Imaging.RasterImage image = (Aspose.Imaging.RasterImage)Aspose.Imaging.Image.Create(gifOptions, 500, 500))
{
//Get the pixels of image by specifying the area as image boundary
Aspose.Imaging.Color[] pixels = image.LoadPixels(image.Bounds);
//Loop over the Array and sets color of alrenative indexed pixel
for (int index = 0; index < pixels.Length; index++)
{
if (index % 2 == 0)
{
//Set the indexed pixel color to yellow
pixels[index] = Aspose.Imaging.Color.Yellow;
}
else
{
//Set the indexed pixel color to blue
pixels[index] = Aspose.Imaging.Color.Blue;
}
}
//Apply the pixel changes to the image
image.SavePixels(image.Bounds, pixels);
// save all changes.
image.Save();
}
// Write MemoryStream to File
using (System.IO.FileStream fileStream = new System.IO.FileStream(@"C:\temp\output.gif", System.IO.FileMode.Create))
{
stream.WriteTo(fileStream);
}
}
Constructors
RasterImage()
启动了 Aspose.Imaging.RasterImage 类的新例子。
[JsonConstructor]
protected RasterImage()
RasterImage(色彩色彩)
启动了 Aspose.Imaging.RasterImage 类的新例子。
protected RasterImage(IColorPalette colorPalette)
Parameters
colorPalette
IColorPalette
颜色板。
Fields
xmp数据
XMP 数据
[JsonProperty]
protected XmpPacketWrapper xmpData
领域价值
Properties
DataLoader
接收或设置数据加载器。
[JsonProperty]
protected IRasterImageArgb32PixelLoader DataLoader { get; set; }
财产价值
HasAlpha
得到一个值,表明这个例子是否有阿尔法。
public virtual bool HasAlpha { get; }
财产价值
Examples
下面的例子上传了拉斯特图像,并打印了关于原始数据格式和阿尔法频道的信息。
// The image files to load.
string[] fileNames = new string[]
{
@"c:\temp\sample.bmp",
@"c:\temp\alpha.png",
};
foreach (string fileName in fileNames)
{
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(fileName))
{
Aspose.Imaging.RasterImage rasterImage = (Aspose.Imaging.RasterImage)image;
System.Console.WriteLine("ImageFile={0}, FileFormat={1}, HasAlpha={2}", fileName, rasterImage.RawDataFormat, rasterImage.HasAlpha);
}
}
// The output may look like this:
// ImageFile=c:\temp\sample.bmp, FileFormat=Rgb24Bpp, used channels: 8,8,8, HasAlpha=False
// ImageFile=c:\temp\alpha.png, FileFormat=RGBA32Bpp, used channels: 8,8,8,8, HasAlpha=True
下面的例子显示如何从BMP图像中提取关于原始数据格式和阿尔法频道的信息。
// Create a 32-bpp BMP image of 100 x 100 px.
using (Aspose.Imaging.FileFormats.Bmp.BmpImage bmpImage = new Aspose.Imaging.FileFormats.Bmp.BmpImage(100, 100, 32, null))
{
System.Console.WriteLine("FileFormat={0}, RawDataFormat={1}, HasAlpha={2}", bmpImage.FileFormat, bmpImage.RawDataFormat, bmpImage.HasAlpha);
};
// Create a 24-bpp BMP image of 100 x 100 px.
using (Aspose.Imaging.FileFormats.Bmp.BmpImage bmpImage = new Aspose.Imaging.FileFormats.Bmp.BmpImage(100, 100, 24, null))
{
System.Console.WriteLine("FileFormat={0}, RawDataFormat={1}, HasAlpha={2}", bmpImage.FileFormat, bmpImage.RawDataFormat, bmpImage.HasAlpha);
};
// Generally, BMP doesn't support alpha channel so the output will look like this:
// FileFormat = Bmp, RawDataFormat = Rgb32Bpp, used channels: 8,8,8,8, HasAlpha = False
// FileFormat = Bmp, RawDataFormat = Rgb24Bpp, used channels: 8,8,8, HasAlpha = False
HasTransparentColor
收到一个值,表明图像是否有透明的颜色。
public virtual bool HasTransparentColor { get; set; }
财产价值
HorizontalResolution
接收或设置这个 Aspose.Imaging.RasterImage 的水平分辨率,每英寸的像素。
public virtual double HorizontalResolution { get; set; }
财产价值
Examples
下面的例子表明如何设置一个拉斯特图像的水平/垂直分辨率。
string dir = "c:\\temp\\";
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.jpg"))
{
Aspose.Imaging.RasterImage rasterImage = (Aspose.Imaging.RasterImage)image;
// Get horizontal and vertical resolution of the image
double horizontalResolution = rasterImage.HorizontalResolution;
double verticalResolution = rasterImage.VerticalResolution;
System.Console.WriteLine("The horizontal resolution, in pixels per inch: {0}", horizontalResolution);
System.Console.WriteLine("The vertical resolution, in pixels per inch: {0}", verticalResolution);
if (horizontalResolution != 96.0 || verticalResolution != 96.0)
{
// Use the SetResolution method for updating both resolution values in a single call.
System.Console.WriteLine("Set resolution values to 96 dpi");
rasterImage.SetResolution(96.0, 96.0);
System.Console.WriteLine("The horizontal resolution, in pixels per inch: {0}", rasterImage.HorizontalResolution);
System.Console.WriteLine("The vertical resolution, in pixels per inch: {0}", rasterImage.VerticalResolution);
}
// The output may look like this:
// The horizontal resolution, in pixels per inch: 300
// The vertical resolution, in pixels per inch: 300
// Set resolution values to 96 dpi
// The horizontal resolution, in pixels per inch: 96
// The vertical resolution, in pixels per inch: 96
}
Remarks
默认情况下,这个值总是 96 因为不同的平台无法返回屏幕分辨率. 您可以考虑使用 SetResolution 方法在单个通话中更新两个分辨率值。
ImageOpacity
这个图像是不可思议的。
public virtual float ImageOpacity { get; }
财产价值
IsRawDataAvailable
收到一个值,表明原始数据充电是否可用。
public bool IsRawDataAvailable { get; }
财产价值
PremultiplyComponents
收到或设置一个值,表明图像组件是否必须提前加倍。
public virtual bool PremultiplyComponents { get; set; }
财产价值
Examples
下面的例子创建了一个新的拉斯特图像,保存了指定的半透明像素,然后加载了这些像素,并在预复制的形式获得最终颜色。
int imageWidth = 3;
int imageHeight = 2;
Aspose.Imaging.Color[] colors = new Aspose.Imaging.Color[]
{
Aspose.Imaging.Color.FromArgb(127, 255, 0, 0),
Aspose.Imaging.Color.FromArgb(127, 0, 255, 0),
Aspose.Imaging.Color.FromArgb(127, 0, 0, 255),
Aspose.Imaging.Color.FromArgb(127, 255, 255, 0),
Aspose.Imaging.Color.FromArgb(127, 255, 0, 255),
Aspose.Imaging.Color.FromArgb(127, 0, 255, 255),
};
Aspose.Imaging.ImageOptions.PngOptions createOptions = new Aspose.Imaging.ImageOptions.PngOptions();
createOptions.Source = new Aspose.Imaging.Sources.StreamSource(new System.IO.MemoryStream(), true);
createOptions.ColorType = Aspose.Imaging.FileFormats.Png.PngColorType.TruecolorWithAlpha;
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Create(createOptions, imageWidth, imageHeight))
{
Aspose.Imaging.RasterImage rasterImage = (Aspose.Imaging.RasterImage)image;
// Save pixels for the whole image.
rasterImage.SavePixels(rasterImage.Bounds, colors);
// The pixels are stored in the original image in the non-premultiplied form.
// Need to specify the corresponding option explicitly to obtain premultiplied color components.
// The premultiplied color components are calculated by the formulas:
// red = original_red * alpha / 255;
// green = original_green * alpha / 255;
// blue = original_blue * alpha / 255;
rasterImage.PremultiplyComponents = true;
Aspose.Imaging.Color[] premultipliedColors = rasterImage.LoadPixels(rasterImage.Bounds);
for (int i = 0; i < colors.Length; i++)
{
System.Console.WriteLine("Original color: {0}", colors[i].ToString());
System.Console.WriteLine("Premultiplied color: {0}", premultipliedColors[i].ToString());
}
}
RawCustomColorConverter
接收或设置自定义颜色转换器
public IColorConverter RawCustomColorConverter { get; set; }
财产价值
RawDataFormat
获取原始数据格式。
public virtual PixelDataFormat RawDataFormat { get; }
财产价值
Examples
下面的例子上传了拉斯特图像,并打印了关于原始数据格式和阿尔法频道的信息。
// The image files to load.
string[] fileNames = new string[]
{
@"c:\temp\sample.bmp",
@"c:\temp\alpha.png",
};
foreach (string fileName in fileNames)
{
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(fileName))
{
Aspose.Imaging.RasterImage rasterImage = (Aspose.Imaging.RasterImage)image;
System.Console.WriteLine("ImageFile={0}, FileFormat={1}, HasAlpha={2}", fileName, rasterImage.RawDataFormat, rasterImage.HasAlpha);
}
}
// The output may look like this:
// ImageFile=c:\temp\sample.bmp, FileFormat=Rgb24Bpp, used channels: 8,8,8, HasAlpha=False
// ImageFile=c:\temp\alpha.png, FileFormat=RGBA32Bpp, used channels: 8,8,8,8, HasAlpha=True
此示例显示如何从文件流中加载DJVU图像并打印有关页面的信息。
string dir = "c:\\temp\\";
// Load a DJVU image from a file stream.
using (System.IO.Stream stream = System.IO.File.OpenRead(dir + "sample.djvu"))
{
using (Aspose.Imaging.FileFormats.Djvu.DjvuImage djvuImage = new Aspose.Imaging.FileFormats.Djvu.DjvuImage(stream))
{
System.Console.WriteLine("The total number of pages: {0}", djvuImage.Pages.Length);
System.Console.WriteLine("The active page number: {0}", djvuImage.ActivePage.PageNumber);
System.Console.WriteLine("The first page number: {0}", djvuImage.FirstPage.PageNumber);
System.Console.WriteLine("The last page number: {0}", djvuImage.LastPage.PageNumber);
foreach (Aspose.Imaging.FileFormats.Djvu.DjvuPage djvuPage in djvuImage.Pages)
{
System.Console.WriteLine("--------------------------------------------------");
System.Console.WriteLine("Page number: {0}", djvuPage.PageNumber);
System.Console.WriteLine("Page size: {0}", djvuPage.Size);
System.Console.WriteLine("Page raw format: {0}", djvuPage.RawDataFormat);
}
}
}
//The output may look like this:
//The total number of pages: 2
//The active page number: 1
//The first page number: 1
//The last page number: 2
//--------------------------------------------------
//Page number: 1
//Page size: { Width = 2481, Height = 3508}
//Page raw format: RgbIndexed1Bpp, used channels: 1
//--------------------------------------------------
//Page number: 2
//Page size: { Width = 2481, Height = 3508}
//Page raw format: RgbIndexed1Bpp, used channels: 1
RawDataSettings
获取当前的原始数据设置 请注意,在使用这些设置时,数据不会转换。
[JsonIgnore]
public RawDataSettings RawDataSettings { get; }
财产价值
RawFallbackIndex
获取或设置下跌指数,当板块指数不限时使用
public int RawFallbackIndex { get; set; }
财产价值
RawIndexedColorConverter
接收或设置索引的颜色转换器
public IIndexedColorConverter RawIndexedColorConverter { get; set; }
财产价值
RawLineSize
它在比特中获得原始线大小。
public virtual int RawLineSize { get; }
财产价值
TransparentColor
让图像透明的颜色。
public virtual Color TransparentColor { get; set; }
财产价值
UpdateXmpData
收到或设置一个值,表明是否要更新 XMP 数据。
public virtual bool UpdateXmpData { get; set; }
财产价值
UsePalette
收到一个值,表明图像板是否被使用。
public override bool UsePalette { get; }
财产价值
UseRawData
收到或设置一个值,表明在原始数据充电可用时是否使用原始数据充电。
public virtual bool UseRawData { get; set; }
财产价值
VerticalResolution
接收或设置这个 Aspose.Imaging.RasterImage 的垂直分辨率,每英寸的像素。
public virtual double VerticalResolution { get; set; }
财产价值
Examples
下面的例子表明如何设置一个拉斯特图像的水平/垂直分辨率。
string dir = "c:\\temp\\";
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.jpg"))
{
Aspose.Imaging.RasterImage rasterImage = (Aspose.Imaging.RasterImage)image;
// Get horizontal and vertical resolution of the image
double horizontalResolution = rasterImage.HorizontalResolution;
double verticalResolution = rasterImage.VerticalResolution;
System.Console.WriteLine("The horizontal resolution, in pixels per inch: {0}", horizontalResolution);
System.Console.WriteLine("The vertical resolution, in pixels per inch: {0}", verticalResolution);
if (horizontalResolution != 96.0 || verticalResolution != 96.0)
{
// Use the SetResolution method for updating both resolution values in a single call.
System.Console.WriteLine("Set resolution values to 96 dpi");
rasterImage.SetResolution(96.0, 96.0);
System.Console.WriteLine("The horizontal resolution, in pixels per inch: {0}", rasterImage.HorizontalResolution);
System.Console.WriteLine("The vertical resolution, in pixels per inch: {0}", rasterImage.VerticalResolution);
}
// The output may look like this:
// The horizontal resolution, in pixels per inch: 300
// The vertical resolution, in pixels per inch: 300
// Set resolution values to 96 dpi
// The horizontal resolution, in pixels per inch: 96
// The vertical resolution, in pixels per inch: 96
}
Remarks
默认情况下,这个值总是 96 因为不同的平台无法返回屏幕分辨率. 您可以考虑使用 SetResolution 方法在单个通话中更新两个分辨率值。
XmpData
接收或设置 XMP 数据。
public virtual XmpPacketWrapper XmpData { get; set; }
财产价值
Methods
AdjustBrightness(因特)
调整图像的亮度。
public virtual void AdjustBrightness(int brightness)
Parameters
brightness
int
光的价值。
Examples
下面的例子执行图像的亮度纠正。
string dir = "c:\\temp\\";
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.png"))
{
Aspose.Imaging.RasterImage rasterImage = (Aspose.Imaging.RasterImage)image;
// Set the brightness value. The accepted values of brightness are in the range [-255, 255].
rasterImage.AdjustBrightness(50);
rasterImage.Save(dir + "sample.AdjustBrightness.png");
}
AdjustContrast(航海)
图像对比
public virtual void AdjustContrast(float contrast)
Parameters
contrast
float
对比值(在范围内(100;100)
Examples
下面的例子是对图像的对比纠正。
string dir = "c:\\temp\\";
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.png"))
{
Aspose.Imaging.RasterImage rasterImage = (Aspose.Imaging.RasterImage)image;
// Set the contrast value. The accepted values of contrast are in the range [-100f, 100f].
rasterImage.AdjustContrast(50);
rasterImage.Save(dir + "sample.AdjustContrast.png");
}
AdjustGamma(航海、航海、航海)
图像的Gamma修复。
public virtual void AdjustGamma(float gammaRed, float gammaGreen, float gammaBlue)
Parameters
gammaRed
float
红频率的Gamma
gammaGreen
float
绿色频道的Gamma
gammaBlue
float
蓝色频道的Gamma
Examples
下面的例子进行图像的伽马修复,适用于颜色组件的不同比例。
string dir = "c:\\temp\\";
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.png"))
{
Aspose.Imaging.RasterImage rasterImage = (Aspose.Imaging.RasterImage)image;
// Set individual gamma coefficients for red, green and blue channels.
rasterImage.AdjustGamma(1.5f, 2.5f, 3.5f);
rasterImage.Save(dir + "sample.AdjustGamma.png");
}
AdjustGamma(航海)
图像的Gamma修复。
public virtual void AdjustGamma(float gamma)
Parameters
gamma
float
红色、绿色和蓝色频道的Gamma
Examples
下面的例子执行图像的伽马修复。
string dir = "c:\\temp\\";
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.png"))
{
Aspose.Imaging.RasterImage rasterImage = (Aspose.Imaging.RasterImage)image;
// Set gamma coefficient for red, green and blue channels.
rasterImage.AdjustGamma(2.5f);
rasterImage.Save(dir + "sample.AdjustGamma.png");
}
BinarizeBradley(双重)
使用布拉德利的适应边界算法进行图像二元化,使用整体图像边界
public virtual void BinarizeBradley(double brightnessDifference)
Parameters
brightnessDifference
double
像素之间的亮度差异和一个 s x s 窗口的像素在这个像素周围的平均差异。
BinarizeBradley(双重, int)
使用布拉德利的适应边界算法进行图像二元化,使用整体图像边界
public virtual void BinarizeBradley(double brightnessDifference, int windowSize)
Parameters
brightnessDifference
double
像素之间的亮度差异和一个 s x s 窗口的像素在这个像素周围的平均差异。
windowSize
int
这个像素周围集中的像素的 x s 窗口的尺寸
Examples
下面的例子将拉斯特图像与布拉德利的适应边界算法与指定的窗口大小二元化。
string dir = "c:\\temp\\";
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.png"))
{
Aspose.Imaging.RasterImage rasterImage = (Aspose.Imaging.RasterImage)image;
// Binarize the image with a brightness difference of 5. The brightness is a difference between a pixel and the average of an 10 x 10 window of pixels centered around this pixel.
rasterImage.BinarizeBradley(5, 10);
rasterImage.Save(dir + "sample.BinarizeBradley5_10x10.png");
}
BinarizeFixed(比特)
图像的二元化与预先定义边界
public virtual void BinarizeFixed(byte threshold)
Parameters
threshold
byte
如果一个像素的相应灰色值超过边界,则将分配给它255的值,否则将分配给它0。
Examples
下面的例子二元化了与预定范围的拉斯特图像,二元化图像只包含2种颜色 - 黑色和白色。
string dir = "c:\\temp\\";
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.png"))
{
Aspose.Imaging.RasterImage rasterImage = (Aspose.Imaging.RasterImage)image;
// Binarize the image with a threshold value of 127.
// If a corresponding gray value of a pixel is greater than 127, a value of 255 will be assigned to it, 0 otherwise.
rasterImage.BinarizeFixed(127);
rasterImage.Save(dir + "sample.BinarizeFixed.png");
}
BinarizeOtsu()
图像的二元化与 Otsu 边界
public virtual void BinarizeOtsu()
Examples
下面的例子二元化一个拉斯特图像与Otsu边界。二元化图像只包含2种颜色 - 黑色和白色。
string dir = "c:\\temp\\";
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.png"))
{
Aspose.Imaging.RasterImage rasterImage = (Aspose.Imaging.RasterImage)image;
// Binarize the image with Otsu thresholding.
rasterImage.BinarizeOtsu();
rasterImage.Save(dir + "sample.BinarizeOtsu.png");
}
Blend(点, RasterImage, Rectangle, byte)
将此图像示例与 overlay’ 图像混合。
public virtual void Blend(Point origin, RasterImage overlay, Rectangle overlayArea, byte overlayAlpha = 255)
Parameters
origin
Point
背景图像混合起源。
overlay
RasterImage
超越的形象。
overlayArea
Rectangle
超级区域。
overlayAlpha
byte
超级阿尔法。
Blend(点, RasterImage, byte)
将此图像示例与 overlay’ 图像混合。
public void Blend(Point origin, RasterImage overlay, byte overlayAlpha = 255)
Parameters
origin
Point
背景图像混合起源。
overlay
RasterImage
超越的形象。
overlayAlpha
byte
超级阿尔法。
Dither(通用方法, int)
表现在当前图像上旋转。
public void Dither(DitheringMethod ditheringMethod, int bitsCount)
Parameters
ditheringMethod
DitheringMethod
定位方法。
bitsCount
int
最后的比特数为Ditering。
Examples
下面的例子加载了一个拉斯特图像,并使用不同的板块深度进行边界和流动直径。
string dir = "c:\\temp\\";
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.png"))
{
Aspose.Imaging.RasterImage rasterImage = (Aspose.Imaging.RasterImage)image;
// Perform threshold dithering using 4-bit color palette which contains 16 colors.
// The more bits specified the higher quality and the bigger size of the output image.
// Note that only 1-bit, 4-bit and 8-bit palettes are supported at the moment.
rasterImage.Dither(Aspose.Imaging.DitheringMethod.ThresholdDithering, 4);
rasterImage.Save(dir + "sample.ThresholdDithering4.png");
}
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.png"))
{
Aspose.Imaging.RasterImage rasterImage = (Aspose.Imaging.RasterImage)image;
// Perform floyd dithering using 1-bit color palette which contains only 2 colors - black and white.
// The more bits specified the higher quality and the bigger size of the output image.
// Note that only 1-bit, 4-bit and 8-bit palettes are supported at the moment.
rasterImage.Dither(Aspose.Imaging.DitheringMethod.FloydSteinbergDithering, 1);
rasterImage.Save(dir + "sample.FloydSteinbergDithering1.png");
}
Dither(DitheringMethod, int,IColorPalette)
表现在当前图像上旋转。
public abstract void Dither(DitheringMethod ditheringMethod, int bitsCount, IColorPalette customPalette)
Parameters
ditheringMethod
DitheringMethod
定位方法。
bitsCount
int
最后的比特数为Ditering。
customPalette
IColorPalette
可用于Ditering的配件。
Filter(Rectangle, FilterOptions 基于)
过滤指定的直角。
public virtual void Filter(Rectangle rectangle, FilterOptionsBase options)
Parameters
rectangle
Rectangle
直角。
options
FilterOptionsBase
选项的。
Examples
下面的例子适用于各种类型的过滤器的拉斯特图像。
string dir = "c:\\temp\\";
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.png"))
{
Aspose.Imaging.RasterImage rasterImage = (Aspose.Imaging.RasterImage)image;
// Apply a median filter with a rectangle size of 5 to the entire image.
rasterImage.Filter(rasterImage.Bounds, new Aspose.Imaging.ImageFilters.FilterOptions.MedianFilterOptions(5));
rasterImage.Save(dir + "sample.MedianFilter.png");
}
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.png"))
{
Aspose.Imaging.RasterImage rasterImage = (Aspose.Imaging.RasterImage)image;
// Apply a bilateral smoothing filter with a kernel size of 5 to the entire image.
rasterImage.Filter(rasterImage.Bounds, new Aspose.Imaging.ImageFilters.FilterOptions.BilateralSmoothingFilterOptions(5));
rasterImage.Save(dir + "sample.BilateralSmoothingFilter.png");
}
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.png"))
{
Aspose.Imaging.RasterImage rasterImage = (Aspose.Imaging.RasterImage)image;
// Apply a Gaussian blur filter with a radius of 5 and a sigma value of 4.0 to the entire image.
rasterImage.Filter(rasterImage.Bounds, new Aspose.Imaging.ImageFilters.FilterOptions.GaussianBlurFilterOptions(5, 4.0));
rasterImage.Save(dir + "sample.GaussianBlurFilter.png");
}
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.png"))
{
Aspose.Imaging.RasterImage rasterImage = (Aspose.Imaging.RasterImage)image;
// Apply a Gauss-Wiener filter with a radius of 5 and a smooth value of 4.0 to the entire image.
rasterImage.Filter(rasterImage.Bounds, new Aspose.Imaging.ImageFilters.FilterOptions.GaussWienerFilterOptions(5, 4.0));
rasterImage.Save(dir + "sample.GaussWienerFilter.png");
}
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.png"))
{
Aspose.Imaging.RasterImage rasterImage = (Aspose.Imaging.RasterImage)image;
// Apply a motion wiener filter with a length of 5, a smooth value of 4.0 and an angle of 90.0 degrees to the entire image.
rasterImage.Filter(rasterImage.Bounds, new Aspose.Imaging.ImageFilters.FilterOptions.MotionWienerFilterOptions(10, 1.0, 90.0));
rasterImage.Save(dir + "sample.MotionWienerFilter.png");
}
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.png"))
{
Aspose.Imaging.RasterImage rasterImage = (Aspose.Imaging.RasterImage)image;
// Apply a sharpen filter with a kernel size of 5 and a sigma value of 4.0 to the entire image.
rasterImage.Filter(rasterImage.Bounds, new Aspose.Imaging.ImageFilters.FilterOptions.SharpenFilterOptions(5, 4.0));
rasterImage.Save(dir + "sample.SharpenFilter.png");
}
GetArgb32Pixel(int , int , int)
获取图像 32 位 ARGB 像素。
public int GetArgb32Pixel(int x, int y)
Parameters
x
int
像素 x 位置
y
int
像素和位置。
Returns
指定位置的 32 位 ARGB 像素。
Examples
下面的例子加载了拉斯特图像,并获得了一个自愿的像素的颜色,作为一个32位的整体值。
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(@"c:\temp\sample.png"))
{
Aspose.Imaging.RasterImage rasterImage = (Aspose.Imaging.RasterImage)image;
// Get an integer representation of the color of the top-left pixel of the image.
int color = rasterImage.GetArgb32Pixel(0, 0);
// To obtain the values of the individual color components, shift the color value by a corresponding number of bits
int alpha = (color >> 24) & 0xff;
int red = (color >> 16) & 0xff;
int green = (color >> 8) & 0xff;
int blue = (color >> 0) & 0xff;
System.Console.WriteLine("The color of the pixel(0,0) is A={0},R={1},G={2},B={3}", alpha, red, green, blue);
}
下面的例子表明图像缓存如何影响性能. 一般情况下,阅读缓存数据比阅读非缓存数据更快。
string dir = "c:\\temp\\";
// Load an image from a PNG file.
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.png"))
{
// Cache all pixel data so that no additional data loading will be performed from the underlying data stream
image.CacheData();
System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch();
stopwatch.Start();
// Reading all pixels is pretty fast.
Aspose.Imaging.RasterImage rasterImage = (Aspose.Imaging.RasterImage)image;
for (int y = 0; y < image.Height; y++)
{
for (int x = 0; x < image.Width; x++)
{
int color = rasterImage.GetArgb32Pixel(x, y);
}
}
stopwatch.Stop();
System.Console.WriteLine("Reading all cached pixels took {0} ms.", stopwatch.ElapsedMilliseconds);
}
// Load an image from a PNG file
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.png"))
{
System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch();
stopwatch.Start();
// Reading all pixels is not as fast as when caching
Aspose.Imaging.RasterImage rasterImage = (Aspose.Imaging.RasterImage)image;
for (int y = 0; y < image.Height; y++)
{
for (int x = 0; x < image.Width; x++)
{
int color = rasterImage.GetArgb32Pixel(x, y);
}
}
stopwatch.Stop();
System.Console.WriteLine("Reading all pixels without preliminary caching took {0} ms.", stopwatch.ElapsedMilliseconds);
}
// The output may look like this:
// Reading all cached pixels took 1500 ms.
// Reading all pixels without preliminary caching took 150000 ms.
GetDefaultArgb32Pixels(Rectangle)
获取默认 32 位 ARGB 像素序列。
public int[] GetDefaultArgb32Pixels(Rectangle rectangle)
Parameters
rectangle
Rectangle
直角以获得像素。
Returns
int ( )
默认的Pixels Array。
GetDefaultPixels(直角,IPartialArgb32PixelLoader)
通过使用部分像素加载器接收默认的像素。
public void GetDefaultPixels(Rectangle rectangle, IPartialArgb32PixelLoader partialPixelLoader)
Parameters
rectangle
Rectangle
直角以获得像素。
partialPixelLoader
IPartialArgb32PixelLoader
部分像素充电器。
GetDefaultRawData(Rectangle, IPartialRawDataLoader, RawDataSettings)
通过使用部分像素加载器获得默认的原始数据序列。
public void GetDefaultRawData(Rectangle rectangle, IPartialRawDataLoader partialRawDataLoader, RawDataSettings rawDataSettings)
Parameters
rectangle
Rectangle
直角以获得像素。
partialRawDataLoader
IPartialRawDataLoader
部分原始数据加载器。
rawDataSettings
RawDataSettings
原始数据设置。
GetDefaultRawData(直角,RawDataSettings)
获取默认的原始数据序列。
public byte[] GetDefaultRawData(Rectangle rectangle, RawDataSettings rawDataSettings)
Parameters
rectangle
Rectangle
直角以获取原始数据。
rawDataSettings
RawDataSettings
原始数据设置。
Returns
byte ( )
虚假的原始数据。
GetModifyDate(博尔)
收到资源图像最后修改的日期和时间。
public virtual DateTime GetModifyDate(bool useDefault)
Parameters
useDefault
bool
如果设置为“真实”,则使用 FileInfo 的信息作为默认值。
Returns
资源图像的日期和时间最后修改。
GetPixel(int , int , int)
接收图像像像素。
public Color GetPixel(int x, int y)
Parameters
x
int
像素 x 位置
y
int
像素和位置。
Returns
指定的位置的像素颜色。
Examples
下面的例子加载了拉斯特图像,并获得了自愿的像素的颜色。
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(@"c:\temp\sample.png"))
{
Aspose.Imaging.RasterImage rasterImage = (Aspose.Imaging.RasterImage)image;
// Get the color of the top-left pixel of the image.
Color color = rasterImage.GetPixel(0, 0);
// Obtain the values of the individual color components
byte alpha = color.A;
byte red = color.R;
int green = color.G;
int blue = color.B;
System.Console.WriteLine("The color of the pixel(0,0) is A={0},R={1},G={2},B={3}", alpha, red, green, blue);
}
GetSkewAngle()
接到滑角。这种方法适用于扫描文档,以确定扫描时的滑角。
public float GetSkewAngle()
Returns
天花板的角度,在等级。
Grayscale()
将图像转化为其灰色代表性
public virtual void Grayscale()
Examples
下面的例子将彩色拉斯特图像转化为其灰色图像,灰色图像仅由灰色的阴影组成,仅提供强度信息。
string dir = "c:\\temp\\";
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.png"))
{
Aspose.Imaging.RasterImage rasterImage = (Aspose.Imaging.RasterImage)image;
rasterImage.Grayscale();
rasterImage.Save(dir + "sample.Grayscale.png");
}
LoadArgb32Pixels(Rectangle)
加载 32 位 ARGB 像素。
public int[] LoadArgb32Pixels(Rectangle rectangle)
Parameters
rectangle
Rectangle
直角从中充电像素。
Returns
int ( )
加载的 32 位 ARGB 像素。
Examples
下面的例子表明如何加载和处理图像的像素,像素被描述为32位的整体值,例如,考虑计算图像的完全透明像素的问题。
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(@"c:\temp\alpha.png"))
{
Aspose.Imaging.RasterImage rasterImage = (Aspose.Imaging.RasterImage)image;
// Load pixels for the whole image. Any rectangular part of the image can be specified as a parameter of the Aspose.Imaging.RasterImage.LoadArgb32Pixels method.
int[] pixels = rasterImage.LoadArgb32Pixels(rasterImage.Bounds);
int count = 0;
foreach (int pixel in pixels)
{
int alpha = (pixel >> 24) & 0xff;
if (alpha == 0)
{
count++;
}
}
System.Console.WriteLine("The number of fully transparent pixels is {0}", count);
System.Console.WriteLine("The total number of pixels is {0}", image.Width * image.Height);
}
LoadArgb64Pixels(Rectangle)
64 位 ARGB 像素。
public long[] LoadArgb64Pixels(Rectangle rectangle)
Parameters
rectangle
Rectangle
直角从中充电像素。
Returns
long ( )
加载 64 位 ARGB 像素。
Examples
下面的例子表明如何加载和处理图像的像素,像素被描述为64位的整体值,例如,考虑计算图像的完全透明像素的问题。
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(@"c:\temp\16rgba.png"))
{
Aspose.Imaging.RasterImage rasterImage = (Aspose.Imaging.RasterImage)image;
// Load pixels for the whole image. Any rectangular part of the image can be specified as a parameter of the Aspose.Imaging.RasterImage.LoadArgb64Pixels method.
// Note that the image itself must have 16 bits per sample, because Aspose.Imaging.RasterImage.LoadArgb64Pixels doesn't work with 8 bit per sample.
// In order to work with 8 bits per sample please use the good old Aspose.Imaging.RasterImage.LoadArgb32Pixels method.
long[] pixels = rasterImage.LoadArgb64Pixels(rasterImage.Bounds);
int count = 0;
foreach (int pixel in pixels)
{
// Note that all color components including alpha are represented by 16-bit values, so their allowed values are in the range [0, 63535].
int alpha = (pixel >> 48) & 0xffff;
if (alpha == 0)
{
count++;
}
}
System.Console.WriteLine("The number of fully transparent pixels is {0}", count);
System.Console.WriteLine("The total number of pixels is {0}", image.Width * image.Height);
}
LoadCmyk32Pixels(Rectangle)
以 CMYK 格式加载像素。
public int[] LoadCmyk32Pixels(Rectangle rectangle)
Parameters
rectangle
Rectangle
直角从中充电像素。
Returns
int ( )
加载的 CMYK 像素作为 32 位无标值。
LoadCmykPixels(Rectangle)
以 CMYK 格式加载像素。请更有效地使用 Aspose.Imaging.RasterImage.LoadCmyk32Pixels(Aspose.Imaging.Rectangle)方法。
[Obsolete("Method is obsolete")]
public CmykColor[] LoadCmykPixels(Rectangle rectangle)
Parameters
rectangle
Rectangle
直角从中充电像素。
Returns
CmykColor ( )
加载的CMYK像素。
LoadPartialArgb32Pixels(直角,IPartialArgb32PixelLoader)
通过包装部分加载 32 位 ARGB 像素。
public void LoadPartialArgb32Pixels(Rectangle rectangle, IPartialArgb32PixelLoader partialPixelLoader)
Parameters
rectangle
Rectangle
想要的直角。
partialPixelLoader
IPartialArgb32PixelLoader
32 位 ARGB 像素充电器。
Examples
下面的例子显示如何使用自己的部分处理器加载和处理图像的像素。 例如,考虑计算图像的完全透明像素的问题. 为了使用部分加载机制计算透明像素,引入了一个单独的类 TransparentArgb32PixelCounter 实施 Aspose.Imaging.IPartialArgb32PixelLoader。
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(@"c:\temp\alpha.png"))
{
Aspose.Imaging.RasterImage rasterImage = (Aspose.Imaging.RasterImage)image;
// Create an instance of the Aspose.Imaging.IPartialArgb32PixelLoader and pass it to the Aspose.Imaging.RasterImage.LoadPartialArgb32Pixels
TransparentArgb32PixelCounter counter = new TransparentArgb32PixelCounter();
// Load pixels for the whole image. Any rectangular part of the image can be specified as the first parameter of the Aspose.Imaging.RasterImage.LoadPartialArgb32Pixels method.
rasterImage.LoadPartialArgb32Pixels(rasterImage.Bounds, counter);
System.Console.WriteLine("The number of fully transparent pixels is {0}", counter.Count);
System.Console.WriteLine("The total number of pixels is {0}", image.Width * image.Height);
}
// The counter may look like this:
/// <summary>
/// Counts the number of fully transparent pixels with alpha channel value of 0.
/// </summary>
private class TransparentArgb32PixelCounter : IPartialArgb32PixelLoader
{
/// <summary>
/// The number of fully transparent pixels.
/// </summary>
private int count;
/// <summary>
/// Gets the number of fully transparent pixels.
/// </summary>
public int Count
{
get { return this.count; }
}
/// <summary>
/// Processes the loaded pixels. This method is called back every time when a new portion of pixels is loaded.
/// </summary>
/// <param name="pixelsRectangle"/>The pixels rectangle.
/// <param name="pixels"/>The 32-bit ARGB pixels.
/// <param name="start"/>The start pixels point.
/// <param name="end"/>The end pixels point.
public void Process(Aspose.Imaging.Rectangle pixelsRectangle, int[] pixels, Aspose.Imaging.Point start, Aspose.Imaging.Point end)
{
foreach (int pixel in pixels)
{
int alpha = (pixel >> 24) & 0xff;
if (alpha == 0)
{
this.count++;
}
}
}
}
LoadPartialArgb64Pixels(直角,IPartialArgb64PixelLoader)
通过包装部分加载 64 位 ARGB 像素。
public void LoadPartialArgb64Pixels(Rectangle rectangle, IPartialArgb64PixelLoader partialPixelLoader)
Parameters
rectangle
Rectangle
想要的直角。
partialPixelLoader
IPartialArgb64PixelLoader
64 位 ARGB 像素充電器。
LoadPartialPixels(直角,IPartialPixelLoader)
通过包装部分加载像素。
public void LoadPartialPixels(Rectangle desiredRectangle, IPartialPixelLoader pixelLoader)
Parameters
desiredRectangle
Rectangle
想要的直角。
pixelLoader
IPartialPixelLoader
像素充电器。
Examples
下面的例子显示如何使用自己的部分处理器加载和处理图像的像素。 例如,考虑计算图像的完全透明像素的问题. 为了使用部分加载机制加载透明的像素,一个单独的类 TransparentPixelCounter 实施 Aspose.Imaging.IPartialPixelLoader 被引入。
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(@"c:\temp\alpha.png"))
{
Aspose.Imaging.RasterImage rasterImage = (Aspose.Imaging.RasterImage)image;
// Create an instance of the Aspose.Imaging.IPartialPixelLoader and pass it to the Aspose.Imaging.RasterImage.LoadPartialPixels
TransparentPixelCounter counter = new TransparentPixelCounter();
// Load pixels for the whole image. Any rectangular part of the image can be specified as the first parameter of the Aspose.Imaging.RasterImage.LoadPartialPixels method.
rasterImage.LoadPartialPixels(rasterImage.Bounds, counter);
System.Console.WriteLine("The number of fully transparent pixels is {0}", counter.Count);
System.Console.WriteLine("The total number of pixels is {0}", image.Width * image.Height);
}
// The counter may look like this:
/// <summary>
/// Counts the number of fully transparent pixels with alpha channel value of 0.
/// </summary>
private class TransparentPixelCounter : IPartialPixelLoader
{
/// <summary>
/// The number of fully transparent pixels.
/// </summary>
private int count;
/// <summary>
/// Gets the number of fully transparent pixels.
/// </summary>
public int Count
{
get { return this.count; }
}
/// <summary>
/// Processes the loaded pixels. This method is called back every time when a new portion of pixels is loaded.
/// </summary>
/// <param name="pixelsRectangle"/>The pixels rectangle.
/// <param name="pixels"/>The 32-bit ARGB pixels.
/// <param name="start"/>The start pixels point.
/// <param name="end"/>The end pixels point.
public void Process(Aspose.Imaging.Rectangle pixelsRectangle, Aspose.Imaging.Color[] pixels, Aspose.Imaging.Point start, Aspose.Imaging.Point end)
{
foreach (Color pixel in pixels)
{
if (pixel.A == 0)
{
this.count++;
}
}
}
}
LoadPixels(Rectangle)
充电像素。
public Color[] LoadPixels(Rectangle rectangle)
Parameters
rectangle
Rectangle
直角从中充电像素。
Returns
Color ( )
加载的Pixels Array。
Examples
下面的例子表明如何加载和处理拉斯特图像的像素,例如,考虑计算图像的完全透明像素的问题。
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(@"c:\temp\alpha.png"))
{
Aspose.Imaging.RasterImage rasterImage = (Aspose.Imaging.RasterImage)image;
// Load pixels for the whole image. Any rectangular part of the image can be specified as a parameter of the Aspose.Imaging.RasterImage.LoadPixels method.
Color[] pixels = rasterImage.LoadPixels(rasterImage.Bounds);
int count = 0;
foreach (Color pixel in pixels)
{
if (pixel.A == 0)
{
count++;
}
}
System.Console.WriteLine("The number of fully transparent pixels is {0}", count);
System.Console.WriteLine("The total number of pixels is {0}", image.Width * image.Height);
}
此示例显示如何在类型颜色序列中加载Pixel信息,操纵序列并将其重新设置为图像。 为了执行这些操作,此示例创建一个新的图像文件(GIF格式) uisng MemoryStream 对象。
//Create an instance of MemoryStream
using (System.IO.MemoryStream stream = new System.IO.MemoryStream())
{
//Create an instance of GifOptions and set its various properties including the Source property
Aspose.Imaging.ImageOptions.GifOptions gifOptions = new Aspose.Imaging.ImageOptions.GifOptions();
gifOptions.Source = new Aspose.Imaging.Sources.StreamSource(stream);
//Create an instance of Image
using (Aspose.Imaging.RasterImage image = (Aspose.Imaging.RasterImage)Aspose.Imaging.Image.Create(gifOptions, 500, 500))
{
//Get the pixels of image by specifying the area as image boundary
Aspose.Imaging.Color[] pixels = image.LoadPixels(image.Bounds);
//Loop over the Array and sets color of alrenative indexed pixel
for (int index = 0; index < pixels.Length; index++)
{
if (index % 2 == 0)
{
//Set the indexed pixel color to yellow
pixels[index] = Aspose.Imaging.Color.Yellow;
}
else
{
//Set the indexed pixel color to blue
pixels[index] = Aspose.Imaging.Color.Blue;
}
}
//Apply the pixel changes to the image
image.SavePixels(image.Bounds, pixels);
// save all changes.
image.Save();
}
// Write MemoryStream to File
using (System.IO.FileStream fileStream = new System.IO.FileStream(@"C:\temp\output.gif", System.IO.FileMode.Create))
{
stream.WriteTo(fileStream);
}
}
LoadRawData(Rectangle, RawDataSettings, IPartialRawDataLoader)
加载原始数据。
public void LoadRawData(Rectangle rectangle, RawDataSettings rawDataSettings, IPartialRawDataLoader rawDataLoader)
Parameters
rectangle
Rectangle
直角充电原料数据。
rawDataSettings
RawDataSettings
原始数据设置用于加载数据. 请注意,如果数据不在指定的格式,则数据转换将进行。
rawDataLoader
IPartialRawDataLoader
原始数据加载器。
Examples
下面的例子表明如何使用RawDataSettings从原始图像数据中提取像素,例如,考虑图像的完全透明像素的计算问题。
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(@"c:\temp\GrayscaleWithAlpha.png"))
{
Aspose.Imaging.RasterImage rasterImage = (Aspose.Imaging.RasterImage)image;
Aspose.Imaging.RawDataSettings settings = rasterImage.RawDataSettings;
TransparentPixelRawDataCounter rawDataLoader = new TransparentPixelRawDataCounter(settings);
// Load pixels for the whole image. Any rectangular part of the image can be specified as a parameter of the Aspose.Imaging.RasterImage.LoadRawData method.
rasterImage.LoadRawData(rasterImage.Bounds, settings, rawDataLoader);
System.Console.WriteLine("The number of fully transparent pixels is {0}", rawDataLoader.Count);
System.Console.WriteLine("The total number of pixels is {0}", image.Width * image.Height);
}
// In case of raw data, the counter may look like this:
/// <summary>
/// Counts the number of fully transparent pixels with alpha channel value of 0.
/// </summary>
private class TransparentPixelRawDataCounter : IPartialRawDataLoader
{
/// <summary>
/// The number of fully transparent pixels.
/// </summary>
private int count;
/// <summary>
/// The raw data settings of the loaded image.
/// </summary>
private Aspose.Imaging.RawDataSettings rawDataSettings;
/// <summary>
/// Gets the number of fully transparent pixels.
/// </summary>
public int Count
{
get { return this.count; }
}
/// <summary>
/// Initializes a new instance of the <see transparentpixelrawdatacounter=""></see> class.
/// </summary>
/// <param name="settings"/>The raw data settings allow to extract color components from raw data.
public TransparentPixelRawDataCounter(Aspose.Imaging.RawDataSettings settings)
{
this.rawDataSettings = settings;
this.count = 0;
}
/// <summary>
/// Processes the loaded raw data. This method is called back every time when a new portion of raw data is loaded.
/// </summary>
/// <param name="dataRectangle"/>The raw data rectangle.
/// <param name="data"/>The raw data.
/// <param name="start"/>The start data point.
/// <param name="end"/>The end data point.
public void Process(Aspose.Imaging.Rectangle dataRectangle, byte[] data, Aspose.Imaging.Point start, Aspose.Imaging.Point end)
{
int[] channelBits = this.rawDataSettings.PixelDataFormat.ChannelBits;
// Only simple formats are consdired here to simplify the code.
// Let's consider only images with 8 bits per sample.
for (int i = 0; i < channelBits.Length; i++)
{
if (channelBits[i] != 8)
{
throw new System.NotSupportedException();
}
}
switch (this.rawDataSettings.PixelDataFormat.PixelFormat)
{
case PixelFormat.Rgb:
case PixelFormat.Bgr:
{
if (channelBits.Length == 4)
{
// ARGB
for (int i = 0; i < data.Length; i += 4)
{
// The alpha channel is stored last, after the color components.
if (data[i + 3] == 0)
{
this.count++;
}
}
}
}
break;
case PixelFormat.Grayscale:
{
if (channelBits.Length == 2)
{
// Grayscale Alpha
for (int i = 0; i < data.Length; i += 2)
{
// The alpha channel is stored last, after the color components.
if (data[i + 1] == 0)
{
this.count++;
}
}
}
}
break;
default:
throw new System.ArgumentOutOfRangeException("PixelFormat");
}
}
/// <summary>
/// Processes the loaded raw data. This method is called back every time when a new portion of raw data is loaded.
/// </summary>
/// <param name="dataRectangle"/>The raw data rectangle.
/// <param name="data"/>The raw data.
/// <param name="start"/>The start data point.
/// <param name="end"/>The end data point.
/// <param name="loadOptions"/>The load options.
public void Process(Aspose.Imaging.Rectangle dataRectangle, byte[] data, Aspose.Imaging.Point start, Aspose.Imaging.Point end, Aspose.Imaging.LoadOptions loadOptions)
{
this.Process(dataRectangle, data, start, end);
}
}
LoadRawData(Rectangle、Rectangle、RawDataSettings、IPartialRawDataLoader)
加载原始数据。
public void LoadRawData(Rectangle rectangle, Rectangle destImageBounds, RawDataSettings rawDataSettings, IPartialRawDataLoader rawDataLoader)
Parameters
rectangle
Rectangle
直角充电原料数据。
destImageBounds
Rectangle
清晰的图像界限
rawDataSettings
RawDataSettings
原始数据设置用于加载数据. 请注意,如果数据不在指定的格式,则数据转换将进行。
rawDataLoader
IPartialRawDataLoader
原始数据加载器。
NormalizeAngle()
正常化角度。这种方法适用于扫描文档,以摆脱扫描的扫描。此方法使用 Aspose.Imaging.RasterImage.GetSkewAngle 和 Aspose.Imaging.RasterImage.Rotate(System.Single) 方法。
public void NormalizeAngle()
NormalizeAngle(白色,颜色)
正常化角度。这种方法适用于扫描文档,以摆脱扫描的扫描。此方法使用 Aspose.Imaging.RasterImage.GetSkewAngle 和 Aspose.Imaging.RasterImage.Rotate(System.Single,System.Boolean,Aspose.Imaging.Color) 方法。
public virtual void NormalizeAngle(bool resizeProportionally, Color backgroundColor)
Parameters
resizeProportionally
bool
如果设置为“真实”,您的图像大小将根据旋转直角(角点)的投影而改变,否则它会使尺寸不受触摸,只有内部图像内容被旋转。
backgroundColor
Color
背景的颜色。
Examples
Skew 是一种在文档扫描过程中可能出现的作品,当文档的文本/图像在轻微的角度旋转时,它可能有各种原因,但最常见的是,在扫描过程中,纸张被错误地定位。
string dir = "c:\\aspose.imaging\\issues\\net\\3567\\";
string inputFilePath = dir + "skewed.png";
string outputFilePath = dir + "skewed.out.png";
// Get rid of the skewed scan with default parameters
using (Aspose.Imaging.RasterImage image = (Aspose.Imaging.RasterImage)Aspose.Imaging.Image.Load(inputFilePath))
{
// Deskew
image.NormalizeAngle(false /*do not resize*/, Aspose.Imaging.Color.LightGray /*background color*/);
image.Save(outputFilePath);
}
NormalizeHistogram()
正常化图像 histogram - 调整像素值使用所有可用的范围。
public virtual void NormalizeHistogram()
ReadArgb32ScanLine(因特)
通过指定的扫描线指数阅读整个扫描线。
public int[] ReadArgb32ScanLine(int scanLineIndex)
Parameters
scanLineIndex
int
以零为基础的扫描线指数。
Returns
int ( )
扫描线 32 位 ARGB 颜色值序列。
ReadScanLine(因特)
通过指定的扫描线指数阅读整个扫描线。
public Color[] ReadScanLine(int scanLineIndex)
Parameters
scanLineIndex
int
以零为基础的扫描线指数。
Returns
Color ( )
扫描线 pixel 颜色值序列。
ReleaseManagedResources()
释放管理资源 确保没有未管理资源在这里释放,因为它们可能已经释放了。
protected override void ReleaseManagedResources()
RemoveMetadata()
删除此图像示例 meta 数据 通过设置此 Aspose.Imaging.Xmp.IHasXMPData。 零.
public override void RemoveMetadata()
ReplaceColor(颜色、比特、颜色)
它用允许的差异替换一个颜色,并保留原始的阿尔法值,以节省顺利的边缘。
public void ReplaceColor(Color oldColor, byte oldColorDiff, Color newColor)
Parameters
oldColor
Color
可取代旧的颜色。
oldColorDiff
byte
允许旧颜色的差异,以便能够扩展取代的颜色色调。
newColor
Color
新的颜色取代旧的颜色。
ReplaceColor(int , byte , int)
它用允许的差异替换一个颜色,并保留原始的阿尔法值,以节省顺利的边缘。
public virtual void ReplaceColor(int oldColorArgb, byte oldColorDiff, int newColorArgb)
Parameters
oldColorArgb
int
旧颜色 ARGB 值将被取代。
oldColorDiff
byte
允许旧颜色的差异,以便能够扩展取代的颜色色调。
newColorArgb
int
新颜色 ARGB 值取代旧颜色。
ReplaceNonTransparentColors(Color)
它将所有不透明的颜色替换为新的颜色,并保留原始的阿尔法值,以节省顺利的边缘。注意:如果您在没有透明度的图像上使用它,则所有颜色都会被单一的颜色取代。
public void ReplaceNonTransparentColors(Color newColor)
Parameters
newColor
Color
新颜色取代不透明的颜色。
ReplaceNonTransparentColors(因特)
它将所有不透明的颜色替换为新的颜色,并保留原始的阿尔法值,以节省顺利的边缘。注意:如果您在没有透明度的图像上使用它,则所有颜色都会被单一的颜色取代。
public virtual void ReplaceNonTransparentColors(int newColorArgb)
Parameters
newColorArgb
int
新颜色ARGB值取代不透明的颜色。
Resize(int , int , ImageResizeSettings)
用扩展选项重新绘制图像。
public override void Resize(int newWidth, int newHeight, ImageResizeSettings settings)
Parameters
newWidth
int
新的宽度。
newHeight
int
新高度。
settings
ImageResizeSettings
重新设置。
Examples
这个例子加载了拉斯特图像,并使用各种重复设置重复图像。
string dir = "c:\\temp\\";
Aspose.Imaging.ImageResizeSettings resizeSettings = new Aspose.Imaging.ImageResizeSettings();
// The adaptive algorithm based on weighted and blended rational function and lanczos3 interpolation.
resizeSettings.Mode = Aspose.Imaging.ResizeType.AdaptiveResample;
// The small rectangular filter
resizeSettings.FilterType = Aspose.Imaging.ImageFilterType.SmallRectangular;
// The number of colors in the palette.
resizeSettings.EntriesCount = 256;
// The color quantization is not used
resizeSettings.ColorQuantizationMethod = ColorQuantizationMethod.None;
// The euclidian method
resizeSettings.ColorCompareMethod = ColorCompareMethod.Euclidian;
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.gif"))
{
// Scale down by 2 times using adaptive resampling.
image.Resize(image.Width / 2, image.Height / 2, resizeSettings);
image.Save(dir + "downsample.adaptive.gif");
}
Rotate(彩色 , 彩色 , 彩色)
旋转图像周围的中心。
public virtual void Rotate(float angle, bool resizeProportionally, Color backgroundColor)
Parameters
angle
float
旋转的角度在度,积极的值会旋转时钟。
resizeProportionally
bool
如果设置为“真实”,您的图像大小将根据旋转直角(角点)的投影而改变,否则它会使尺寸不受触摸,只有内部图像内容被旋转。
backgroundColor
Color
背景的颜色。
Exceptions
未实施的例外
Rotate(航海)
旋转图像周围的中心。
public override void Rotate(float angle)
Parameters
angle
float
旋转的角度在度,积极的值会旋转时钟。
Save(流, ImageOptionsBase, 直角)
根据保存选项,将图像的数据存储到指定的文件格式中。
public override void Save(Stream stream, ImageOptionsBase optionsBase, Rectangle boundsRectangle)
Parameters
stream
Stream
流以保存图像的数据。
optionsBase
ImageOptionsBase
储蓄选项。
boundsRectangle
Rectangle
目的地图像限制直角 设置空直角使用源界限。
SaveArgb32Pixels(直角, int[])
存储 32 位 ARGB 像素。
public void SaveArgb32Pixels(Rectangle rectangle, int[] pixels)
Parameters
rectangle
Rectangle
直角可以保存像素。
pixels
int
( )
32 位 ARGB 像素。
Examples
下面的例子用 Aspose.Imaging.RasterImage.SaveArgb32Pixels 方法填写了拉斯特图像的中心区域。
string dir = "c:\\temp\\";
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.png"))
{
Aspose.Imaging.RasterImage rasterImage = (Aspose.Imaging.RasterImage)image;
// The black square
int[] pixels = new int[(rasterImage.Width / 2) * (rasterImage.Height / 2)];
for (int i = 0; i < pixels.Length; i++)
{
pixels[i] = Color.Black.ToArgb();
}
// Draw the black square at the center of the image.
Aspose.Imaging.Rectangle area = new Aspose.Imaging.Rectangle(rasterImage.Width / 4, rasterImage.Height / 4, rasterImage.Width / 2, rasterImage.Height / 2);
rasterImage.SaveArgb32Pixels(area, pixels);
rasterImage.Save(dir + "sample.SaveArgb32Pixels.png");
}
SaveCmyk32Pixels(直角, int[])
保存像素。
public void SaveCmyk32Pixels(Rectangle rectangle, int[] pixels)
Parameters
rectangle
Rectangle
直角可以保存像素。
pixels
int
( )
CMYK 像素被列为 32 位一体值。
Examples
下面的例子用 Aspose.Imaging.RasterImage.SaveCmyk32Pixels 方法填写了拉斯特图像的中心区域。
string dir = @"c:\temp\";
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.png"))
{
Aspose.Imaging.RasterImage rasterImage = (Aspose.Imaging.RasterImage)image;
// Get an integer representation of black in the CMYK color space.
int blackCmyk = Aspose.Imaging.CmykColorHelper.ToCmyk(Color.Black);
// The black square.
int[] pixels = new int[(rasterImage.Width / 2) * (rasterImage.Height / 2)];
for (int i = 0; i < pixels.Length; i++)
{
pixels[i] = blackCmyk;
}
// Draw the black square at the center of the image.
Aspose.Imaging.Rectangle area = new Aspose.Imaging.Rectangle(rasterImage.Width / 4, rasterImage.Height / 4, rasterImage.Width / 2, rasterImage.Height / 2);
rasterImage.SaveCmyk32Pixels(area, pixels);
rasterImage.Save(dir + "sample.SaveCmyk32Pixels.png");
}
SaveCmykPixels(直角,CmykColor[])
保存像素。请更有效地使用 Aspose.Imaging.RasterImage.SaveCmyk32Pixels(Aspose.Imaging.Rectangle,System.Int32)方法。
[Obsolete("Method is obsolete")]
public void SaveCmykPixels(Rectangle rectangle, CmykColor[] pixels)
Parameters
rectangle
Rectangle
直角可以保存像素。
pixels
CmykColor
( )
CMYK 像素。
SavePixels(直角,颜色[])
保存像素。
public void SavePixels(Rectangle rectangle, Color[] pixels)
Parameters
rectangle
Rectangle
直角可以保存像素。
pixels
Color
( )
皮克斯的发射。
Examples
下面的例子用 Aspose.Imaging.RasterImage.SavePixels 方法填补了拉斯特图像的中心区域。
string dir = "c:\\temp\\";
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.png"))
{
Aspose.Imaging.RasterImage rasterImage = (Aspose.Imaging.RasterImage)image;
// The black square
Color[] pixels = new Color[(rasterImage.Width / 2) * (rasterImage.Height / 2)];
for (int i = 0; i < pixels.Length; i++)
{
pixels[i] = Color.Black;
}
// Draw the black square at the center of the image.
Aspose.Imaging.Rectangle area = new Aspose.Imaging.Rectangle(rasterImage.Width / 4, rasterImage.Height / 4, rasterImage.Width / 2, rasterImage.Height / 2);
rasterImage.SavePixels(area, pixels);
rasterImage.Save(dir + "sample.SavePixels.png");
}
此示例显示如何在类型颜色序列中加载Pixel信息,操纵序列并将其重新设置为图像。 为了执行这些操作,此示例创建一个新的图像文件(GIF格式) uisng MemoryStream 对象。
//Create an instance of MemoryStream
using (System.IO.MemoryStream stream = new System.IO.MemoryStream())
{
//Create an instance of GifOptions and set its various properties including the Source property
Aspose.Imaging.ImageOptions.GifOptions gifOptions = new Aspose.Imaging.ImageOptions.GifOptions();
gifOptions.Source = new Aspose.Imaging.Sources.StreamSource(stream);
//Create an instance of Image
using (Aspose.Imaging.RasterImage image = (Aspose.Imaging.RasterImage)Aspose.Imaging.Image.Create(gifOptions, 500, 500))
{
//Get the pixels of image by specifying the area as image boundary
Aspose.Imaging.Color[] pixels = image.LoadPixels(image.Bounds);
//Loop over the Array and sets color of alrenative indexed pixel
for (int index = 0; index < pixels.Length; index++)
{
if (index % 2 == 0)
{
//Set the indexed pixel color to yellow
pixels[index] = Aspose.Imaging.Color.Yellow;
}
else
{
//Set the indexed pixel color to blue
pixels[index] = Aspose.Imaging.Color.Blue;
}
}
//Apply the pixel changes to the image
image.SavePixels(image.Bounds, pixels);
// save all changes.
image.Save();
}
// Write MemoryStream to File
using (System.IO.FileStream fileStream = new System.IO.FileStream(@"C:\temp\output.gif", System.IO.FileMode.Create))
{
stream.WriteTo(fileStream);
}
}
SaveRawData(比特( ), int , Rectangle , RawDataSettings)
存储原始数据。
public void SaveRawData(byte[] data, int dataOffset, Rectangle rectangle, RawDataSettings rawDataSettings)
Parameters
data
byte
( )
原始数据。
dataOffset
int
初始原始数据的折扣。
rectangle
Rectangle
原始数据直角。
rawDataSettings
RawDataSettings
原始数据设置数据在其中。
SetArgb32Pixel(int , int , int , int)
为指定位置设置图像 32 位 ARGB 像素。
public void SetArgb32Pixel(int x, int y, int argb32Color)
Parameters
x
int
像素 x 位置
y
int
像素和位置。
argb32Color
int
32 位 ARGB 像素为指定的位置。
Examples
下面的例子加载了拉斯特图像,并设置了一个自愿的像素的颜色。
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(@"c:\temp\sample.png"))
{
Aspose.Imaging.RasterImage rasterImage = (Aspose.Imaging.RasterImage)image;
// Sets the color of the top-left pixel.
rasterImage.SetArgb32Pixel(0, 0, Aspose.Imaging.Color.Aqua.ToArgb());
// Another way is to pass an instance of the Aspose.Imaging.Color directly
rasterImage.SetPixel(0, 0, Aspose.Imaging.Color.Aqua);
}
SetPalette(彩色 彩色 彩色)
设置图像板。
public override void SetPalette(IColorPalette palette, bool updateColors)
Parameters
palette
IColorPalette
要安排的板块。
updateColors
bool
如果设置为“真实”颜色,将根据新板更新;否则颜色指数仍然不变. 请注意,如果某些指数没有相应的板输入,不变的指数可能会破坏上载的图像。
SetPixel(int , int , 颜色)
设置图像像像为指定的位置。
public void SetPixel(int x, int y, Color color)
Parameters
x
int
像素 x 位置
y
int
像素和位置。
color
Color
指定的位置的像素颜色。
Examples
下面的例子加载了拉斯特图像,并设置了一个自愿的像素的颜色。
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(@"c:\temp\sample.png"))
{
Aspose.Imaging.RasterImage rasterImage = (Aspose.Imaging.RasterImage)image;
// Sets the color of the top-left pixel.
rasterImage.SetArgb32Pixel(0, 0, Aspose.Imaging.Color.Aqua.ToArgb());
// Another way is to pass an instance of the Aspose.Imaging.Color directly
rasterImage.SetPixel(0, 0, Aspose.Imaging.Color.Aqua);
}
SetResolution(双,双)
设置此 Aspose.Imaging.RasterImage 的分辨率。
public virtual void SetResolution(double dpiX, double dpiY)
Parameters
dpiX
double
垂直分辨率,每英寸点,的Aspose.Imaging.RasterImage。
dpiY
double
垂直分辨率,每英寸点,的Aspose.Imaging.RasterImage。
Examples
下面的例子表明如何设置一个拉斯特图像的水平/垂直分辨率。
string dir = "c:\\temp\\";
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.jpg"))
{
Aspose.Imaging.RasterImage rasterImage = (Aspose.Imaging.RasterImage)image;
// Get horizontal and vertical resolution of the image
double horizontalResolution = rasterImage.HorizontalResolution;
double verticalResolution = rasterImage.VerticalResolution;
System.Console.WriteLine("The horizontal resolution, in pixels per inch: {0}", horizontalResolution);
System.Console.WriteLine("The vertical resolution, in pixels per inch: {0}", verticalResolution);
if (horizontalResolution != 96.0 || verticalResolution != 96.0)
{
// Use the SetResolution method for updating both resolution values in a single call.
System.Console.WriteLine("Set resolution values to 96 dpi");
rasterImage.SetResolution(96.0, 96.0);
System.Console.WriteLine("The horizontal resolution, in pixels per inch: {0}", rasterImage.HorizontalResolution);
System.Console.WriteLine("The vertical resolution, in pixels per inch: {0}", rasterImage.VerticalResolution);
}
// The output may look like this:
// The horizontal resolution, in pixels per inch: 300
// The vertical resolution, in pixels per inch: 300
// Set resolution values to 96 dpi
// The horizontal resolution, in pixels per inch: 96
// The vertical resolution, in pixels per inch: 96
}
ToBitmap()
将 raster 图像转换为 bitmap。此方法在 .Net7.0 或更高版本中不支持
public virtual Bitmap ToBitmap()
Returns
比特币
UpdateDimensions(int , int , int)
更新图像尺寸。
protected abstract void UpdateDimensions(int newWidth, int newHeight)
Parameters
newWidth
int
新图像宽度。
newHeight
int
新图像高度。
UpdateMetadata()
更新图像数据。
protected virtual void UpdateMetadata()
WriteArgb32ScanLine(int , int , int[])
将整个扫描线写入指定的扫描线指数。
public void WriteArgb32ScanLine(int scanLineIndex, int[] argb32Pixels)
Parameters
scanLineIndex
int
以零为基础的扫描线指数。
argb32Pixels
int
( )
32 位 ARGB 色彩可以编写。
WriteScanLine(色彩,色彩[])
将整个扫描线写入指定的扫描线指数。
public void WriteScanLine(int scanLineIndex, Color[] pixels)
Parameters
scanLineIndex
int
以零为基础的扫描线指数。
pixels
Color
( )
像素颜色可以写作。