Class BmpImage
Το όνομα: Aspose.Imaging.FileFormats.Bmp Συγκέντρωση: Aspose.Imaging.dll (25.4.0)
Μπορείτε εύκολα να χειριστείτε Bitmap (BMP) και Device Independent Bitmap(DIB) αρχεία, διευκολύνοντας την αποτελεσματική χειραγώγηση και επεξεργασία του ράστερΠαρουσιάζοντας διάφορες λειτουργίες στις εικόνες, αυτό το API απλοποιεί τηνροή εργασίας, προσφέροντας στους προγραμματιστές ένα αξιόπιστο σύνολο εργαλείων για να εργαστούν με το BMP καιΟι μορφές DIB στις εφαρμογές λογισμικού τους.
[JsonObject(MemberSerialization.OptIn)]
public sealed class BmpImage : RasterCachedImage, IDisposable, IObjectWithBounds, IRasterImageArgb32PixelLoader, IRasterImageRawDataLoader, IHasXmpData, IHasMetadata
Inheritance
object ← DisposableObject ← DataStreamSupporter ← Image ← RasterImage ← RasterCachedImage ← BmpImage
Implements
IDisposable , IObjectWithBounds , IRasterImageArgb32PixelLoader , IRasterImageRawDataLoader , IHasXmpData , IHasMetadata
Κληρονομημένα μέλη
RasterCachedImage.CacheData() , RasterCachedImage.Blend(Point, RasterImage, Rectangle, byte) , RasterCachedImage.Resize(int, int, ResizeType) , RasterCachedImage.Resize(int, int, ImageResizeSettings) , RasterCachedImage.RotateFlip(RotateFlipType) , RasterCachedImage.Rotate(float, bool, Color) , RasterCachedImage.Crop(Rectangle) , RasterCachedImage.Dither(DitheringMethod, int, IColorPalette) , RasterCachedImage.Grayscale() , RasterCachedImage.NormalizeHistogram() , RasterCachedImage.BinarizeFixed(byte) , RasterCachedImage.BinarizeOtsu() , RasterCachedImage.BinarizeBradley(double, int) , RasterCachedImage.BinarizeBradley(double) , RasterCachedImage.AdjustBrightness(int) , RasterCachedImage.AdjustContrast(float) , RasterCachedImage.AdjustGamma(float, float, float) , RasterCachedImage.AdjustGamma(float) , RasterCachedImage.IsCached , RasterImage.RemoveMetadata() , RasterImage.Save(Stream, ImageOptionsBase, Rectangle) , RasterImage.GetModifyDate(bool) , RasterImage.Dither(DitheringMethod, int) , RasterImage.Dither(DitheringMethod, int, IColorPalette) , RasterImage.GetDefaultPixels(Rectangle, IPartialArgb32PixelLoader) , RasterImage.GetDefaultRawData(Rectangle, IPartialRawDataLoader, RawDataSettings) , RasterImage.GetDefaultArgb32Pixels(Rectangle) , RasterImage.GetDefaultRawData(Rectangle, RawDataSettings) , RasterImage.GetArgb32Pixel(int, int) , RasterImage.GetPixel(int, int) , RasterImage.SetArgb32Pixel(int, int, int) , RasterImage.SetPixel(int, int, Color) , RasterImage.ReadScanLine(int) , RasterImage.ReadArgb32ScanLine(int) , RasterImage.WriteScanLine(int, Color[]) , RasterImage.WriteArgb32ScanLine(int, int[]) , RasterImage.LoadPartialArgb32Pixels(Rectangle, IPartialArgb32PixelLoader) , RasterImage.LoadPartialPixels(Rectangle, IPartialPixelLoader) , RasterImage.LoadArgb32Pixels(Rectangle) , RasterImage.LoadArgb64Pixels(Rectangle) , RasterImage.LoadPartialArgb64Pixels(Rectangle, IPartialArgb64PixelLoader) , RasterImage.LoadPixels(Rectangle) , RasterImage.LoadCmykPixels(Rectangle) , RasterImage.LoadCmyk32Pixels(Rectangle) , RasterImage.LoadRawData(Rectangle, RawDataSettings, IPartialRawDataLoader) , RasterImage.LoadRawData(Rectangle, Rectangle, RawDataSettings, IPartialRawDataLoader) , RasterImage.SaveRawData(byte[], int, Rectangle, RawDataSettings) , RasterImage.SaveArgb32Pixels(Rectangle, int[]) , RasterImage.SavePixels(Rectangle, Color[]) , RasterImage.SaveCmykPixels(Rectangle, CmykColor[]) , RasterImage.SaveCmyk32Pixels(Rectangle, int[]) , RasterImage.SetResolution(double, double) , RasterImage.SetPalette(IColorPalette, bool) , RasterImage.Resize(int, int, ImageResizeSettings) , RasterImage.Rotate(float, bool, Color) , RasterImage.Rotate(float) , RasterImage.BinarizeFixed(byte) , RasterImage.BinarizeOtsu() , RasterImage.BinarizeBradley(double) , RasterImage.BinarizeBradley(double, int) , RasterImage.Blend(Point, RasterImage, Rectangle, byte) , RasterImage.Blend(Point, RasterImage, byte) , RasterImage.Grayscale() , RasterImage.NormalizeHistogram() , RasterImage.AdjustBrightness(int) , RasterImage.AdjustContrast(float) , RasterImage.AdjustGamma(float, float, float) , RasterImage.AdjustGamma(float) , RasterImage.GetSkewAngle() , RasterImage.NormalizeAngle() , RasterImage.NormalizeAngle(bool, Color) , RasterImage.Filter(Rectangle, FilterOptionsBase) , RasterImage.ReplaceColor(Color, byte, Color) , RasterImage.ReplaceColor(int, byte, int) , RasterImage.ReplaceNonTransparentColors(Color) , RasterImage.ReplaceNonTransparentColors(int) , RasterImage.ToBitmap() , RasterImage.PremultiplyComponents , RasterImage.UseRawData , RasterImage.UpdateXmpData , RasterImage.XmpData , RasterImage.RawIndexedColorConverter , RasterImage.RawCustomColorConverter , RasterImage.RawFallbackIndex , RasterImage.RawDataSettings , RasterImage.UsePalette , RasterImage.RawDataFormat , RasterImage.RawLineSize , RasterImage.IsRawDataAvailable , RasterImage.HorizontalResolution , RasterImage.VerticalResolution , RasterImage.HasTransparentColor , RasterImage.HasAlpha , RasterImage.TransparentColor , RasterImage.ImageOpacity , 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.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.CacheData() , DataStreamSupporter.Save() , DataStreamSupporter.Save(Stream) , DataStreamSupporter.Save(string) , DataStreamSupporter.Save(string, bool) , DataStreamSupporter.DataStreamContainer , DataStreamSupporter.IsCached , DisposableObject.Dispose() , DisposableObject.Disposed , object.GetType() , object.ToString() , object.Equals(object?) , object.Equals(object?, object?) , object.ReferenceEquals(object?, object?) , object.GetHashCode()
Examples
Decompress BMP εικόνα που προηγουμένως συμπιέστηκε χρησιμοποιώντας το αλγόριθμο συμπίεσης DXT1.
using (var image = Image.Load("CompressedTiger.bmp"))
{
image.Save("DecompressedTiger.bmp", new BmpOptions());
}
Συμπίεση εικόνας BMP χρησιμοποιώντας το αλγόριθμο συμπίεσης DXT1.
using (var image = Image.Load("Tiger.bmp"))
{
image.Save("CompressedTiger.bmp", new BmpOptions { Compression = BitmapCompression.Dxt1 });
}
Το παράδειγμα δείχνει πώς να αφαιρέσετε οποιοδήποτε αντικείμενο από την εικόνα χρησιμοποιώντας το Graphics Path με το αλγόριθμο Telea.
var imageFilePath = "ball.png";
using (var image = Image.Load(imageFilePath))
{
var pngImage = (PngImage)image;
var mask = new GraphicsPath();
var firstFigure = new Figure();
firstFigure.AddShape(new EllipseShape(new RectangleF(350, 170, 570 - 350, 400 - 170)));
mask.AddFigure(firstFigure);
var options = new TeleaWatermarkOptions(mask);
var result = WatermarkRemover.PaintOver(pngImage, options);
result.Save(outputPath);
}
Το παράδειγμα δείχνει πώς να εξάγει ένα BmpImage με τον τύπο συμπίεσης Rgb.
string sourcePath = "input.png";
// Load a PNG image from a file.
using (Image pngImage = Image.Load(sourcePath))
{
// BMP image is saved with transparency support by default, that is achieved by using the BitmapCompression.Bitfields compression method.
// To save a BMP image with the Rgb compression method, the BmpOptions with the Compression property set to BitmapCompression.Rgb should be specified.
pngImage.Save(outputPath, new BmpOptions() { Compression = BitmapCompression.Rgb });
}
Το παράδειγμα δείχνει πώς να αφαιρέσετε οποιοδήποτε αντικείμενο από την εικόνα χρησιμοποιώντας Graphics Path με Content Aware συμπλήρωση αλγόριθμο.
var imageFilePath = "ball.png";
using (var image = Image.Load(imageFilePath))
{
var pngImage = (PngImage)image;
var mask = new GraphicsPath();
var firstFigure = new Figure();
firstFigure.AddShape(new EllipseShape(new RectangleF(350, 170, 570 - 350, 400 - 170)));
mask.AddFigure(firstFigure);
var options = new ContentAwareFillWatermarkOptions(mask)
{
MaxPaintingAttempts = 4
};
var result = WatermarkRemover.PaintOver(pngImage, options);
result.Save(outputPath);
}
Το παρακάτω παράδειγμα δείχνει πώς να δημιουργήσετε μια εικόνα BMP του καθορισμένου μεγέθους.
string dir = "c:\\temp\\";
// Create a BMP image 100 x 100 px.
using (Aspose.Imaging.FileFormats.Bmp.BmpImage bmpImage = new Aspose.Imaging.FileFormats.Bmp.BmpImage(100, 100))
{
// Fill the image with a simple linear red-black gradient.
int width = bmpImage.Width;
int height = bmpImage.Height;
for (int y = 0; y < height; y++)
{
for (int x = 0; x < width; x++)
{
int hue = (255 * x) / width;
bmpImage.SetPixel(x, y, Aspose.Imaging.Color.FromArgb(255, hue, 0, 0));
}
}
using (System.IO.FileStream stream = new System.IO.FileStream(dir + "output.bmp", System.IO.FileMode.Create))
{
bmpImage.Save(stream);
}
}
Το παράδειγμα δείχνει πώς να εξάγετε ένα BmpImage από ένα αρχείο Png ενώ κρατάτε το αλφα κανάλι, αποθηκεύοντας ένα αρχείο Bmp με διαφάνεια.
string sourcePath = "input.png";
// Load a PNG image from a file.
using (Image pngImage = Image.Load(sourcePath))
{
// BMP image is saved with transparency support by default.
// If you want to explicitly specify such mode, the BmpOptions's Compression property should be set to BitmapCompression.Bitfields.
// The BitmapCompression.Bitfields compression method is the default compression method in the BmpOptions.
// So the same result of exporting a Bmp image with transparency can be achieved by either one of the following ways.
// With an implicit default options:
pngImage.Save(outputPath);
// With an explicit default options:
pngImage.Save(outputPath, new BmpOptions());
// Specifying the BitmapCompression.Bitfields compression method:
pngImage.Save(outputPath, new BmpOptions() { Compression = BitmapCompression.Bitfields });
}
Constructors
BmpImage(Σύνδεσμος)
Ξεκινήστε τη χρήση της κατηγορίας BmpImage χωρίς προσπάθεια με αυτόν τον κατασκευαστή πουξεκινά μια νέα περίπτωση. ιδανικό για τους προγραμματιστές που θέλουν να ανέβουν και ναΛειτουργεί με Aspose.Imaging.FileFormats.Bmp.BmpImage αντικείμενα γρήγορα και αποτελεσματικά.
public BmpImage(string path)
Parameters
path
string
Ο δρόμος για να φορτώσετε την εικόνα από και να ξεκινήσετε τα pixel και τα δεδομένα παλέτας με.
Examples
Το παράδειγμα δείχνει πώς να φορτώσετε ένα BmpImage από ένα αρχείο.
string dir = "c:\\temp\\";
// Load a BMP image from a file.
// The source pixels will be converted to 32-bpp format if required.
using (Aspose.Imaging.FileFormats.Bmp.BmpImage bmpImage = new Aspose.Imaging.FileFormats.Bmp.BmpImage(dir + "sample.bmp"))
{
// Do some image processing.
// Save to another BMP file.
bmpImage.Save(dir + "sample.output.32bpp.bmp");
}
Exceptions
Η εικόνα του RASTER είναι μηδενική.
Το ύψος πρέπει να είναι θετικό.
Η παλέτα πρέπει να προσδιορίζεται για εικόνες με 8 bit ανά pixel ή λιγότερο.
BmpImage(Δύσκολη, διπλή, BitmapCompression, διπλή, διπλή)
Δυσκολεύεστε να δημιουργήσετε μια νέα περίπτωση της κατηγορίας Aspose.Imaging.FileFormats.Bmp.BmpImage με αυτόν τον κατασκευαστή,χρησιμοποιώντας καθορισμένες παραμέτρους όπως ο δρόμος, bitsPerPixel, και συμπίεση. ιδανικό για τους προγραμματιστέςΠροσπαθήστε να ξεκινήσετε τα αντικείμενα BmpImage γρήγορα και αποτελεσματικά, με ακριβή έλεγχοπάνω από τα χαρακτηριστικά της εικόνας.
public BmpImage(string path, ushort bitsPerPixel, BitmapCompression compression, double horizontalResolution, double verticalResolution)
Parameters
path
string
Ο δρόμος για να φορτώσετε την εικόνα από και να ξεκινήσετε τα pixel και τα δεδομένα παλέτας με.
bitsPerPixel
ushort
Τα bit ανά pixel.
compression
BitmapCompression
Η συμπίεση για χρήση.
horizontalResolution
double
Η οριζόντια ανάλυση. σημειώστε ότι λόγω της περιστροφής η προκύπτουσα ανάλυση μπορεί να διαφέρει ελαφρώς από την προηγούμενη.
verticalResolution
double
Σημείωση λόγω της περιστροφής η προκύπτουσα ανάλυση μπορεί να διαφέρει ελαφρώς από την προηγούμενη.
Examples
Το παράδειγμα δείχνει πώς να φορτώσετε ένα BmpImage από ένα αρχείο με το καθορισμένο βάθος bit και ανάλυση.
string dir = "c:\\temp\\";
// Load a BMP image from a file.
// The source pixels will be converted to 24-bpp format if required.
// The resolution will be set to 96 dpi.
using (Aspose.Imaging.FileFormats.Bmp.BmpImage bmpImage =
new Aspose.Imaging.FileFormats.Bmp.BmpImage(dir + "sample.bmp", 24, Aspose.Imaging.FileFormats.Bmp.BitmapCompression.Rgb, 96.0, 96.0))
{
// Do some image processing.
// Save to another BMP file.
bmpImage.Save(dir + "sample.output.24bpp.96dpi.bmp");
}
Exceptions
Η εικόνα του RASTER είναι μηδενική.
Το ύψος πρέπει να είναι θετικό.
Η παλέτα πρέπει να προσδιορίζεται για εικόνες με 8 bit ανά pixel ή λιγότερο.
BmpImage(Stream)
Ξεκινήστε τη χρήση της κατηγορίας Aspose.Imaging.FileFormats.Bmp.BmpImage χωρίς προσπάθεια ξεκινώντας μια νέα περίπτωσημε αυτόν τον κατασκευαστή, χρησιμοποιώντας ένα ρεύμα ως εισαγωγή. ιδανικό για τους προγραμματιστές που αναζητούνένας βολικός τρόπος για να εργαστείτε με αντικείμενα BmpImage από διάφορες πηγές δεδομένων,Εξασφάλιση ευελιξίας και ευκολίας ολοκλήρωσης.
public BmpImage(Stream stream)
Parameters
stream
Stream
Η ροή για να φορτώσει την εικόνα από και να ξεκινήσει τα pixel και τα δεδομένα παλέτα με.
Examples
Το παράδειγμα δείχνει πώς να φορτώσετε ένα BmpImage από μια ροή αρχείων.
string dir = "c:\\temp\\";
// Load a BMP image from a file stream.
// The source pixels will be converted to 32-bpp format if required.
using (System.IO.Stream stream = System.IO.File.OpenRead(dir + "sample.bmp"))
{
using (Aspose.Imaging.FileFormats.Bmp.BmpImage bmpImage = new Aspose.Imaging.FileFormats.Bmp.BmpImage(stream))
{
// Do some image processing.
// Save to another BMP file.
bmpImage.Save(dir + "sample.output.32bpp.bmp");
}
}
Exceptions
Η εικόνα του RASTER είναι μηδενική.
Το ύψος πρέπει να είναι θετικό.
Η παλέτα πρέπει να προσδιορίζεται για εικόνες με 8 bit ανά pixel ή λιγότερο.
BmpImage(Stream, ushort, BitmapCompression, διπλή, διπλή)
Ξεκινήστε την εργασία με το Aspose.Imaging.FileFormats.Bmp.BmpImage τάξη αδιάκοπα δημιουργώνταςμια νέα περίπτωση χρησιμοποιώντας ένα ρεύμα, μαζί με καθορισμένες παραμέτρους όπως bitsPerPixelκαι συμπίεση. ιδανικό για τους προγραμματιστές που αναζητούν έναν απλό τρόπο αντιμετώπισηςBmpImage αντικείμενα, εξασφαλίζοντας την ευελιξία και την αποτελεσματικότητα στα έργα τους.
public BmpImage(Stream stream, ushort bitsPerPixel, BitmapCompression compression, double horizontalResolution, double verticalResolution)
Parameters
stream
Stream
Η ροή για να φορτώσει την εικόνα από και να ξεκινήσει τα pixel και τα δεδομένα παλέτα με.
bitsPerPixel
ushort
Τα bit ανά pixel.
compression
BitmapCompression
Η συμπίεση για χρήση.
horizontalResolution
double
Η οριζόντια ανάλυση. σημειώστε ότι λόγω της περιστροφής η προκύπτουσα ανάλυση μπορεί να διαφέρει ελαφρώς από την προηγούμενη.
verticalResolution
double
Σημείωση λόγω της περιστροφής η προκύπτουσα ανάλυση μπορεί να διαφέρει ελαφρώς από την προηγούμενη.
Examples
Το παράδειγμα δείχνει πώς να φορτώσετε ένα BmpImage από μια ροή αρχείων με το καθορισμένο βάθος bit και ανάλυση.
string dir = "c:\\temp\\";
// Load a BMP image from a file stream.
// The source pixels will be converted to 24-bpp format if required.
// The resolution will be set to 96 dpi.
using (System.IO.Stream stream = System.IO.File.OpenRead(dir + "sample.bmp"))
{
using (Aspose.Imaging.FileFormats.Bmp.BmpImage bmpImage =
new Aspose.Imaging.FileFormats.Bmp.BmpImage(stream, 24, Aspose.Imaging.FileFormats.Bmp.BitmapCompression.Rgb, 96.0, 96.0))
{
// Do some image processing.
// Save to another BMP file.
bmpImage.Save(dir + "sample.output.24bpp.96dpi.bmp");
}
}
Exceptions
Η εικόνα του RASTER είναι μηδενική.
Το ύψος πρέπει να είναι θετικό.
Η παλέτα πρέπει να προσδιορίζεται για εικόνες με 8 bit ανά pixel ή λιγότερο.
BmpImage(RasterImage)
Δημιουργήστε εύκολα μια νέα παράσταση της κατηγορίας Aspose.Imaging.FileFormats.Bmp.BmpImageμε την εκκίνηση του με ένα αντικείμενο RasterImage. ιδανικό για τους προγραμματιστές που αναζητούννα μετατρέψετε αμέσως τις υπάρχουσες εικόνες ράστερ στη μορφή BmpImage, διασφαλίζοντας ότιευκολία και ευκολία ενσωμάτωσης στα έργα τους.
public BmpImage(RasterImage rasterImage)
Parameters
rasterImage
RasterImage
Η εικόνα για να ξεκινήσει τα pixel και τα δεδομένα παλέτα με.
Examples
Το παράδειγμα δείχνει πώς να φορτώσετε ένα BmpImage από άλλη περίπτωση του RasterImage.
string dir = "c:\\temp\\";
// Create a new PNG image.
Aspose.Imaging.ImageOptions.PngOptions createOptions = new Aspose.Imaging.ImageOptions.PngOptions();
createOptions.Source = new Aspose.Imaging.Sources.StreamSource(new System.IO.MemoryStream(), true);
using (Aspose.Imaging.RasterImage rasterImage = (Aspose.Imaging.RasterImage)Aspose.Imaging.Image.Create(createOptions, 100, 100))
{
// Fill the entire PNG image in red.
Aspose.Imaging.Graphics gr = new Aspose.Imaging.Graphics(rasterImage);
Aspose.Imaging.Brushes.SolidBrush brush = new Aspose.Imaging.Brushes.SolidBrush(Aspose.Imaging.Color.Red);
gr.FillRectangle(brush, rasterImage.Bounds);
// Create a BMP image based on the PNG image.
// The source pixels will be converted to 32-bpp format if required.
using (Aspose.Imaging.FileFormats.Bmp.BmpImage bmpImage = new Aspose.Imaging.FileFormats.Bmp.BmpImage(rasterImage))
{
// Save to a BMP file
bmpImage.Save(dir + "output.32bpp.bmp");
}
}
Exceptions
Η εικόνα του RASTER είναι μηδενική.
Το ύψος πρέπει να είναι θετικό.
Η παλέτα πρέπει να προσδιορίζεται για εικόνες με 8 bit ανά pixel ή λιγότερο.
BmpImage(RasterImage, ushort, BitmapCompression, διπλή, διπλή)
Ξεκινήστε την εργασία με την κατηγορία Aspose.Imaging.FileFormats.Bmp.BmpImage αδιάκοπα δημιουργώντας μια νέα περίπτωσηχρησιμοποιώντας ένα rasterImage μαζί με καθορισμένες παραμέτρους όπως bitsPerPixel και συμπίεση.Ιδανικό για τους προγραμματιστές που αναζητούν έναν απλό τρόπο να χειριστούν τα αντικείμενα BmpImage,διασφάλιση της ευελιξίας και της αποτελεσματικότητας των έργων τους.
public BmpImage(RasterImage rasterImage, ushort bitsPerPixel, BitmapCompression compression, double horizontalResolution, double verticalResolution)
Parameters
rasterImage
RasterImage
Η εικόνα για να ξεκινήσει τα pixel και τα δεδομένα παλέτα με.
bitsPerPixel
ushort
Τα bit ανά pixel.
compression
BitmapCompression
Η συμπίεση για χρήση.
horizontalResolution
double
Η οριζόντια ανάλυση. σημειώστε ότι λόγω της περιστροφής η προκύπτουσα ανάλυση μπορεί να διαφέρει ελαφρώς από την προηγούμενη.
verticalResolution
double
Σημείωση λόγω της περιστροφής η προκύπτουσα ανάλυση μπορεί να διαφέρει ελαφρώς από την προηγούμενη.
Examples
Το παράδειγμα δείχνει πώς να φορτώσετε ένα BmpImage από μια άλλη περίπτωση του RasterImage με το καθορισμένο βάθος bit και συμπίεση.
string dir = "c:\\temp\\";
// Create a new PNG image.
Aspose.Imaging.ImageOptions.PngOptions createOptions = new Aspose.Imaging.ImageOptions.PngOptions();
createOptions.Source = new Aspose.Imaging.Sources.StreamSource(new System.IO.MemoryStream(), true);
using (Aspose.Imaging.RasterImage rasterImage = (Aspose.Imaging.RasterImage)Aspose.Imaging.Image.Create(createOptions, 100, 100))
{
// Fill the entire PNG image in red.
Aspose.Imaging.Graphics gr = new Aspose.Imaging.Graphics(rasterImage);
Aspose.Imaging.Brushes.SolidBrush brush = new Aspose.Imaging.Brushes.SolidBrush(Aspose.Imaging.Color.Red);
gr.FillRectangle(brush, rasterImage.Bounds);
// Create a BMP image based on the PNG image.
// The source pixels will be converted to 24-bpp format if required.
// The resolution will be set to 96 dpi.
using (Aspose.Imaging.FileFormats.Bmp.BmpImage bmpImage = new Aspose.Imaging.FileFormats.Bmp.BmpImage(rasterImage, 24, Aspose.Imaging.FileFormats.Bmp.BitmapCompression.Rgb, 96.0, 96.0))
{
// Save to a BMP file
bmpImage.Save(dir + "output.24bpp.96dpi.bmp");
}
}
Exceptions
Η εικόνα του RASTER είναι μηδενική.
Το ύψος πρέπει να είναι θετικό.
Η παλέτα πρέπει να προσδιορίζεται για εικόνες με 8 bit ανά pixel ή λιγότερο.
BmpImage(ΕΝΤ, ΕΝΤ)
Ξεκινήστε τη χρήση της κατηγορίας Aspose.Imaging.FileFormats.Bmp.BmpImage χωρίς προσπάθεια δημιουργώντας μια νέα περίπτωσημε καθορισμένες παραμέτρους πλάτους και ύψους. ιδανικό για τους προγραμματιστές που αναζητούνένας βολικός τρόπος για τη δημιουργία αντικειμένων BmpImage προσαρμοσμένων διαστάσεων, εξασφαλίζονταςευελιξία και ευκολία ενσωμάτωσης στα έργα τους.
public BmpImage(int width, int height)
Parameters
width
int
Το πλάτος της εικόνας.
height
int
Το ύψος της εικόνας.
Examples
Το παράδειγμα δείχνει πώς να δημιουργήσετε ένα BmpImage του καθορισμένου μεγέθους.
string dir = "c:\\temp\\";
// 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))
{
// Fill the entire image in red.
Aspose.Imaging.Graphics gr = new Aspose.Imaging.Graphics(bmpImage);
Aspose.Imaging.Brushes.SolidBrush brush = new Aspose.Imaging.Brushes.SolidBrush(Aspose.Imaging.Color.Red);
gr.FillRectangle(brush, bmpImage.Bounds);
// Save to a BMP file
bmpImage.Save(dir + "output.bmp");
}
Το παρακάτω παράδειγμα δείχνει πώς να παλέσει μια εικόνα BMP για να μειώσει το μέγεθος της παραγωγής της.
// Create a BMP image 100 x 100 px.
using (Aspose.Imaging.FileFormats.Bmp.BmpImage bmpImage = new Aspose.Imaging.FileFormats.Bmp.BmpImage(100, 100))
{
// The linear gradient from the left-top to the right-bottom corner of the image.
Aspose.Imaging.Brushes.LinearGradientBrush brush =
new Aspose.Imaging.Brushes.LinearGradientBrush(
new Aspose.Imaging.Point(0, 0),
new Aspose.Imaging.Point(bmpImage.Width, bmpImage.Height),
Aspose.Imaging.Color.Red,
Aspose.Imaging.Color.Green);
// Fill the entire image with the linear gradient brush.
Aspose.Imaging.Graphics gr = new Aspose.Imaging.Graphics(bmpImage);
gr.FillRectangle(brush, bmpImage.Bounds);
// Get the closest 8-bit color palette which covers as many pixels as possible, so that a palettized image
// is almost visually indistinguishable from a non-palletized one.
Aspose.Imaging.IColorPalette palette = Aspose.Imaging.ColorPaletteHelper.GetCloseImagePalette(bmpImage, 256);
// 8-bit palette contains at most 256 colors.
Aspose.Imaging.ImageOptions.BmpOptions saveOptions = new Aspose.Imaging.ImageOptions.BmpOptions();
saveOptions.Palette = palette;
saveOptions.BitsPerPixel = 8;
using (System.IO.MemoryStream stream = new System.IO.MemoryStream())
{
bmpImage.Save(stream, saveOptions);
System.Console.WriteLine("The palettized image size is {0} bytes.", stream.Length);
}
using (System.IO.MemoryStream stream = new System.IO.MemoryStream())
{
bmpImage.Save(stream);
System.Console.WriteLine("The non-palettized image size is {0} bytes.", stream.Length);
}
}
// The output looks like this:
// The palettized image size is 11078 bytes.
// The non-palettized image size is 40054 bytes.
Exceptions
Το ύψος πρέπει να είναι θετικό.
Η παλέτα πρέπει να προσδιορίζεται για εικόνες με 8 bit ανά pixel ή λιγότερο.
BmpImage(Ιντ, Ιντ, Ιντ, Ιντ, Ιντ)
Ξεκινήστε τη χρήση της κατηγορίας Aspose.Imaging.FileFormats.Bmp.BmpImage αδιάλειπτα με την έναρξη μιας νέας παραδείγματοςμε παραμέτρους όπως πλάτος, ύψος, βάθος και παλέτα.οι προγραμματιστές που αναζητούν έναν απλό τρόπο δημιουργίας αντικειμένων BmpImage μεΠροσαρμοσμένες διαστάσεις και διαμορφώσεις χρωμάτων, εξασφαλίζοντας την ευελιξία και την αποτελεσματικότητα των έργων τους.
public BmpImage(int width, int height, ushort bitsPerPixel, IColorPalette palette)
Parameters
width
int
Το πλάτος της εικόνας.
height
int
Το ύψος της εικόνας.
bitsPerPixel
ushort
Τα bit ανά pixel.
palette
IColorPalette
Το χρώμα της παλέτας.
Examples
Το παράδειγμα δείχνει πώς να δημιουργήσετε ένα BmpImage του καθορισμένου μεγέθους με την καθορισμένη παλέτα.
string dir = "c:\\temp\\";
Aspose.Imaging.Color[] paletterColors = new Aspose.Imaging.Color[]
{
Aspose.Imaging.Color.Red,
Aspose.Imaging.Color.Green,
};
// Create a monochrome palette which contains only red and green colors.
Aspose.Imaging.IColorPalette palette = new Aspose.Imaging.ColorPalette(paletterColors);
// Create a monochrome 1-bpp BMP image of 100 x 100 px.
using (Aspose.Imaging.FileFormats.Bmp.BmpImage bmpImage = new Aspose.Imaging.FileFormats.Bmp.BmpImage(100, 100, 1, palette))
{
Aspose.Imaging.Graphics gr = new Aspose.Imaging.Graphics(bmpImage);
// Fill the upper half of the image in red.
Aspose.Imaging.Brushes.SolidBrush redBrush = new Aspose.Imaging.Brushes.SolidBrush(Aspose.Imaging.Color.Red);
gr.FillRectangle(redBrush, new Aspose.Imaging.Rectangle(0, 0, bmpImage.Width, bmpImage.Height / 2));
// Fill the lower half of the image in green.
Aspose.Imaging.Brushes.SolidBrush greenBrush = new Aspose.Imaging.Brushes.SolidBrush(Aspose.Imaging.Color.Green);
gr.FillRectangle(greenBrush, new Aspose.Imaging.Rectangle(0, bmpImage.Height / 2, bmpImage.Width, bmpImage.Height / 2));
// Save to BMP
bmpImage.Save(dir + "output.monochrome.bmp");
}
Exceptions
Το ύψος πρέπει να είναι θετικό.
Η παλέτα πρέπει να προσδιορίζεται για εικόνες με 8 bit ανά pixel ή λιγότερο.
BmpImage(int, int, ushort, IColorPalette, BitmapCompression, διπλή, διπλή)
Δυσκολεύεστε να δημιουργήσετε μια νέα περίπτωση της κατηγορίας Aspose.Imaging.FileFormats.Bmp.BmpImage με αυτόν τον κατασκευαστή,προσδιορίζοντας παραμέτρους όπως πλάτος, ύψος, bitsPerPixel, και παλέτα.Αναζητώντας έναν βολικό τρόπο για τη δημιουργία αντικειμένων BmpImage με προσαρμοσμένες διαστάσειςκαι διαμόρφωση χρωμάτων, διασφαλίζοντας την ευελιξία και την ευκολία ένταξης στα έργα τους.
public BmpImage(int width, int height, ushort bitsPerPixel, IColorPalette palette, BitmapCompression compression, double horizontalResolution, double verticalResolution)
Parameters
width
int
Το πλάτος της εικόνας.
height
int
Το ύψος της εικόνας.
bitsPerPixel
ushort
Τα bit ανά pixel.
palette
IColorPalette
Το χρώμα της παλέτας.
compression
BitmapCompression
Η συμπίεση για χρήση.
horizontalResolution
double
Η οριζόντια ανάλυση. σημειώστε ότι λόγω της περιστροφής η προκύπτουσα ανάλυση μπορεί να διαφέρει ελαφρώς από την προηγούμενη.
verticalResolution
double
Σημείωση λόγω της περιστροφής η προκύπτουσα ανάλυση μπορεί να διαφέρει ελαφρώς από την προηγούμενη.
Examples
Το παράδειγμα δείχνει πώς να δημιουργήσετε ένα BmpImage χρησιμοποιώντας διάφορες επιλογές.
string dir = "c:\\temp\\";
Aspose.Imaging.Color[] paletterColors = new Aspose.Imaging.Color[]
{
Aspose.Imaging.Color.Red,
Aspose.Imaging.Color.Green,
};
// Create a monochrome palette which contains only red and green colors.
Aspose.Imaging.IColorPalette palette = new Aspose.Imaging.ColorPalette(paletterColors);
// Create a monochrome 1-bpp BMP image of 100 x 100 px.
// The horizontal and vertical resolution will be set to 96 dpi.
using (Aspose.Imaging.FileFormats.Bmp.BmpImage bmpImage = new Aspose.Imaging.FileFormats.Bmp.BmpImage(100, 100, 1, palette, Aspose.Imaging.FileFormats.Bmp.BitmapCompression.Rgb, 96.0, 96.0))
{
Aspose.Imaging.Graphics gr = new Aspose.Imaging.Graphics(bmpImage);
// Fill the upper half of the image in red.
Aspose.Imaging.Brushes.SolidBrush redBrush = new Aspose.Imaging.Brushes.SolidBrush(Aspose.Imaging.Color.Red);
gr.FillRectangle(redBrush, new Aspose.Imaging.Rectangle(0, 0, bmpImage.Width, bmpImage.Height / 2));
// Fill the lower half of the image in green.
Aspose.Imaging.Brushes.SolidBrush greenBrush = new Aspose.Imaging.Brushes.SolidBrush(Aspose.Imaging.Color.Green);
gr.FillRectangle(greenBrush, new Aspose.Imaging.Rectangle(0, bmpImage.Height / 2, bmpImage.Width, bmpImage.Height / 2));
// Save to a BMP file
bmpImage.Save(dir + "output.monochrome.96dpi.bmp");
}
Exceptions
Το ύψος πρέπει να είναι θετικό.
Η παλέτα πρέπει να προσδιορίζεται για εικόνες με 8 bit ανά pixel ή λιγότερο.
Properties
BitmapInfoHeader
Γρήγορη πρόσβαση σε βασικές λεπτομέρειες σχετικά με την εικόνα bitmap σας με αυτή την απλή λειτουργία.Ιδανικό για τους προγραμματιστές που χρειάζονται πληροφορίες τίτλου για τις εικόνες τους.
public BitmapInfoHeader BitmapInfoHeader { get; }
Αξία ιδιοκτησίας
Examples
Το παρακάτω παράδειγμα λαμβάνει τις πληροφορίες από τον επικεφαλής BMP και τις εκτυπώνει στην κονσόλα.
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(@"c:\temp\sample.bmp"))
{
Aspose.Imaging.FileFormats.Bmp.BmpImage bmpImage = (Aspose.Imaging.FileFormats.Bmp.BmpImage)image;
Aspose.Imaging.FileFormats.Bmp.BitmapInfoHeader header = bmpImage.BitmapInfoHeader;
System.Console.WriteLine("The number of palette colors that are required for displaying the bitmap: {0}", header.BitmapColorsImportant);
System.Console.WriteLine("The number of palette colors used in the bitmap: {0}", header.BitmapColorsUsed);
System.Console.WriteLine("The bitmap compression: {0}", header.BitmapCompression);
System.Console.WriteLine("The bitmap height: {0}", header.BitmapHeight);
System.Console.WriteLine("The bitmap width: {0}", header.BitmapWidth);
System.Console.WriteLine("The bitmap raw data size in bytes: {0}", header.BitmapImageSize);
System.Console.WriteLine("The number of planes: {0}", header.BitmapPlanes);
System.Console.WriteLine("The horizontal resolution of the bitmap, in pixels-per-meter: {0}", header.BitmapXPelsPerMeter);
System.Console.WriteLine("The vertical resolution of the bitmap, in pixels-per-meter: {0}", header.BitmapYPelsPerMeter);
System.Console.WriteLine("The number of bits per pixel: {0}", header.BitsPerPixel);
System.Console.WriteLine("The extra bits masks: {0}", header.ExtraBitMasks);
System.Console.WriteLine("The header size in bytes: {0}", header.HeaderSize);
}
//The output may look like this:
//The number of palette colors that are required for displaying the bitmap: 0
//The number of palette colors used in the bitmap: 0
//The bitmap compression: 0
//The bitmap height: 375
//The bitmap width: 500
//The bitmap raw data size in bytes: 562500
//The number of planes: 1
//The horizontal resolution of the bitmap, in pixels-per-meter: 0
//The vertical resolution of the bitmap, in pixels-per-meter: 0
//The number of bits per pixel: 24
//The extra bits masks:
//The header size in bytes: 40
BitsPerPixel
Πρόσβαση στον αριθμό των bit ανά pixel για την εικόνα με εύκολη χρήση αυτής της ιδιότητας.Ιδανικό για τους προγραμματιστές που αναζητούν γρήγορες πληροφορίες σχετικά με την ποιότητα και το βάθος της εικόνας.
public override int BitsPerPixel { get; }
Αξία ιδιοκτησίας
Examples
Το παρακάτω παράδειγμα λαμβάνει τις γενικές πληροφορίες για την εικόνα, συμπεριλαμβανομένης της μορφής pixel, του μεγέθους της εικόνας, της ανάλυσης, της συμπίεσης κλπ.
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(@"c:\temp\sample.bmp"))
{
Aspose.Imaging.FileFormats.Bmp.BmpImage bmpImage = (Aspose.Imaging.FileFormats.Bmp.BmpImage)image;
System.Console.WriteLine("The pixel format: {0}", bmpImage.RawDataFormat);
System.Console.WriteLine("The raw line size in bytes: {0}", bmpImage.RawLineSize);
System.Console.WriteLine("The bitmap compression: {0}", bmpImage.Compression);
System.Console.WriteLine("The bitmap width: {0}", bmpImage.Width);
System.Console.WriteLine("The bitmap height: {0}", bmpImage.Height);
System.Console.WriteLine("The number of bits per pixel: {0}", bmpImage.BitsPerPixel);
double hres = bmpImage.HorizontalResolution;
double vres = bmpImage.VerticalResolution;
System.Console.WriteLine("The horizontal resolution, in pixels per inch: {0}", hres);
System.Console.WriteLine("The vertical resolution, in pixels per inch: {0}", vres);
if (hres != 96.0 || vres != 96.0)
{
// You may consider using the SetResolution method for updating both resolution values in single call.
System.Console.WriteLine("Set resolution values to 96 dpi");
bmpImage.SetResolution(96.0, 96.0);
System.Console.WriteLine("The horizontal resolution, in pixels per inch: {0}", bmpImage.HorizontalResolution);
System.Console.WriteLine("The vertical resolution, in pixels per inch: {0}", bmpImage.VerticalResolution);
}
//The output may look like this:
//The pixel format: Rgb24Bpp, used channels: 8,8,8
//The raw line size in bytes: 1500
//The bitmap compression: Rgb
//The bitmap width: 500
//The bitmap height: 375
//The number of bits per pixel: 24
//The horizontal resolution, in pixels per inch: 0
//The vertical resolution, in pixels per inch: 0
//Set resolution values to 96 dpi
//The horizontal resolution, in pixels per inch: 96.012
//The vertical resolution, in pixels per inch: 96.012
}
Το παρακάτω παράδειγμα δείχνει πώς η συμπίεση bitmap επηρεάζει το μέγεθος της εικόνας εξόδου.
Aspose.Imaging.FileFormats.Bmp.BitmapCompression[] compressions = new Aspose.Imaging.FileFormats.Bmp.BitmapCompression[]
{
Aspose.Imaging.FileFormats.Bmp.BitmapCompression.Rgb,
Aspose.Imaging.FileFormats.Bmp.BitmapCompression.Rle8,
};
Aspose.Imaging.Color[] paletterColors = new Aspose.Imaging.Color[]
{
Aspose.Imaging.Color.Red,
Aspose.Imaging.Color.Green,
};
// Create a monochrome palette which contains only red and green colors.
Aspose.Imaging.IColorPalette palette = new Aspose.Imaging.ColorPalette(paletterColors);
foreach (Aspose.Imaging.FileFormats.Bmp.BitmapCompression compression in compressions)
{
// Create a 8-bpp BMP image of 100 x 100 px.
using (Aspose.Imaging.FileFormats.Bmp.BmpImage bmpImage = new Aspose.Imaging.FileFormats.Bmp.BmpImage(100, 100, 8, palette, compression, 0.0, 0.0))
{
Aspose.Imaging.Graphics gr = new Aspose.Imaging.Graphics(bmpImage);
// Fill the entire image in red.
Aspose.Imaging.Brushes.SolidBrush redBrush = new Aspose.Imaging.Brushes.SolidBrush(Aspose.Imaging.Color.Red);
gr.FillRectangle(redBrush, bmpImage.Bounds);
// Save the image to a stream to get the output image size.
using (System.IO.MemoryStream stream = new System.IO.MemoryStream())
{
bmpImage.Save(stream);
System.Console.WriteLine("---------------------------------------------");
System.Console.WriteLine("The compression={0}", bmpImage.Compression);
System.Console.WriteLine("The number of bits per pixel={0}", bmpImage.BitsPerPixel);
System.Console.WriteLine("The image dimensions={0} x {1}", bmpImage.Width, bmpImage.Height);
System.Console.WriteLine("The raw line size={0}", bmpImage.RawLineSize);
System.Console.WriteLine("The output size in bytes={0}", stream.Length);
}
}
}
// The output looks like this:
// ---------------------------------------------
// The compression = Rgb
// The number of bits per pixel = 8
// The image dimensions = 100 x 100
// The raw line size = 100
// The output size in bytes = 11078
// ---------------------------------------------
// The compression = Rle8
// The number of bits per pixel = 8
// The image dimensions = 100 x 100
// The raw line size = 100
// The output size in bytes = 856
Compression
Αποκαταστήστε τον τύπο συμπίεσης που χρησιμοποιείται για την εικόνα χωρίς προσπάθεια με αυτή την ιδιότητα.Ιδανικό για τους προγραμματιστές που χρειάζονται γρήγορη πρόσβαση σε πληροφορίες σχετικά με την συμπίεση εικόνας.
public BitmapCompression Compression { get; }
Αξία ιδιοκτησίας
Examples
Το παρακάτω παράδειγμα λαμβάνει τις γενικές πληροφορίες για την εικόνα, συμπεριλαμβανομένης της μορφής pixel, του μεγέθους της εικόνας, της ανάλυσης, της συμπίεσης κλπ.
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(@"c:\temp\sample.bmp"))
{
Aspose.Imaging.FileFormats.Bmp.BmpImage bmpImage = (Aspose.Imaging.FileFormats.Bmp.BmpImage)image;
System.Console.WriteLine("The pixel format: {0}", bmpImage.RawDataFormat);
System.Console.WriteLine("The raw line size in bytes: {0}", bmpImage.RawLineSize);
System.Console.WriteLine("The bitmap compression: {0}", bmpImage.Compression);
System.Console.WriteLine("The bitmap width: {0}", bmpImage.Width);
System.Console.WriteLine("The bitmap height: {0}", bmpImage.Height);
System.Console.WriteLine("The number of bits per pixel: {0}", bmpImage.BitsPerPixel);
double hres = bmpImage.HorizontalResolution;
double vres = bmpImage.VerticalResolution;
System.Console.WriteLine("The horizontal resolution, in pixels per inch: {0}", hres);
System.Console.WriteLine("The vertical resolution, in pixels per inch: {0}", vres);
if (hres != 96.0 || vres != 96.0)
{
// You may consider using the SetResolution method for updating both resolution values in single call.
System.Console.WriteLine("Set resolution values to 96 dpi");
bmpImage.SetResolution(96.0, 96.0);
System.Console.WriteLine("The horizontal resolution, in pixels per inch: {0}", bmpImage.HorizontalResolution);
System.Console.WriteLine("The vertical resolution, in pixels per inch: {0}", bmpImage.VerticalResolution);
}
//The output may look like this:
//The pixel format: Rgb24Bpp, used channels: 8,8,8
//The raw line size in bytes: 1500
//The bitmap compression: Rgb
//The bitmap width: 500
//The bitmap height: 375
//The number of bits per pixel: 24
//The horizontal resolution, in pixels per inch: 0
//The vertical resolution, in pixels per inch: 0
//Set resolution values to 96 dpi
//The horizontal resolution, in pixels per inch: 96.012
//The vertical resolution, in pixels per inch: 96.012
}
Το παρακάτω παράδειγμα δείχνει πώς η συμπίεση bitmap επηρεάζει το μέγεθος της εικόνας εξόδου.
Aspose.Imaging.FileFormats.Bmp.BitmapCompression[] compressions = new Aspose.Imaging.FileFormats.Bmp.BitmapCompression[]
{
Aspose.Imaging.FileFormats.Bmp.BitmapCompression.Rgb,
Aspose.Imaging.FileFormats.Bmp.BitmapCompression.Rle8,
};
Aspose.Imaging.Color[] paletterColors = new Aspose.Imaging.Color[]
{
Aspose.Imaging.Color.Red,
Aspose.Imaging.Color.Green,
};
// Create a monochrome palette which contains only red and green colors.
Aspose.Imaging.IColorPalette palette = new Aspose.Imaging.ColorPalette(paletterColors);
foreach (Aspose.Imaging.FileFormats.Bmp.BitmapCompression compression in compressions)
{
// Create a 8-bpp BMP image of 100 x 100 px.
using (Aspose.Imaging.FileFormats.Bmp.BmpImage bmpImage = new Aspose.Imaging.FileFormats.Bmp.BmpImage(100, 100, 8, palette, compression, 0.0, 0.0))
{
Aspose.Imaging.Graphics gr = new Aspose.Imaging.Graphics(bmpImage);
// Fill the entire image in red.
Aspose.Imaging.Brushes.SolidBrush redBrush = new Aspose.Imaging.Brushes.SolidBrush(Aspose.Imaging.Color.Red);
gr.FillRectangle(redBrush, bmpImage.Bounds);
// Save the image to a stream to get the output image size.
using (System.IO.MemoryStream stream = new System.IO.MemoryStream())
{
bmpImage.Save(stream);
System.Console.WriteLine("---------------------------------------------");
System.Console.WriteLine("The compression={0}", bmpImage.Compression);
System.Console.WriteLine("The number of bits per pixel={0}", bmpImage.BitsPerPixel);
System.Console.WriteLine("The image dimensions={0} x {1}", bmpImage.Width, bmpImage.Height);
System.Console.WriteLine("The raw line size={0}", bmpImage.RawLineSize);
System.Console.WriteLine("The output size in bytes={0}", stream.Length);
}
}
}
// The output looks like this:
// ---------------------------------------------
// The compression = Rgb
// The number of bits per pixel = 8
// The image dimensions = 100 x 100
// The raw line size = 100
// The output size in bytes = 11078
// ---------------------------------------------
// The compression = Rle8
// The number of bits per pixel = 8
// The image dimensions = 100 x 100
// The raw line size = 100
// The output size in bytes = 856
FileFormat
Μπορείτε εύκολα να ανακτήσετε την αξία της μορφής αρχείου με αυτή τη φιλική προς τον χρήστη ιδιότητα.Ιδανικό για τους προγραμματιστές που αναζητούν γρήγορη πρόσβαση σε πληροφορίες σχετικά με τη μορφή αρχείου.
public override FileFormat FileFormat { get; }
Αξία ιδιοκτησίας
Examples
Το παρακάτω παράδειγμα δείχνει πώς να εξαγάγετε πληροφορίες σχετικά με τη μορφή πρώτων δεδομένων και το αλφα κανάλι από μια εικόνα 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
HasAlpha
Αποκτά μια τιμή που υποδεικνύει εάν αυτή η περίπτωση έχει alpha.
public override bool HasAlpha { get; }
Αξία ιδιοκτησίας
Height
Αποκτήστε το ύψος της εικόνας χωρίς προσπάθεια με αυτή την ιδιότητα. ιδανικό για τους προγραμματιστέςΧρειάζεται γρήγορη πρόσβαση σε πληροφορίες σχετικά με τις διαστάσεις της εικόνας.
public override int Height { get; }
Αξία ιδιοκτησίας
Examples
Το παρακάτω παράδειγμα λαμβάνει τις γενικές πληροφορίες για την εικόνα, συμπεριλαμβανομένης της μορφής pixel, του μεγέθους της εικόνας, της ανάλυσης, της συμπίεσης κλπ.
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(@"c:\temp\sample.bmp"))
{
Aspose.Imaging.FileFormats.Bmp.BmpImage bmpImage = (Aspose.Imaging.FileFormats.Bmp.BmpImage)image;
System.Console.WriteLine("The pixel format: {0}", bmpImage.RawDataFormat);
System.Console.WriteLine("The raw line size in bytes: {0}", bmpImage.RawLineSize);
System.Console.WriteLine("The bitmap compression: {0}", bmpImage.Compression);
System.Console.WriteLine("The bitmap width: {0}", bmpImage.Width);
System.Console.WriteLine("The bitmap height: {0}", bmpImage.Height);
System.Console.WriteLine("The number of bits per pixel: {0}", bmpImage.BitsPerPixel);
double hres = bmpImage.HorizontalResolution;
double vres = bmpImage.VerticalResolution;
System.Console.WriteLine("The horizontal resolution, in pixels per inch: {0}", hres);
System.Console.WriteLine("The vertical resolution, in pixels per inch: {0}", vres);
if (hres != 96.0 || vres != 96.0)
{
// You may consider using the SetResolution method for updating both resolution values in single call.
System.Console.WriteLine("Set resolution values to 96 dpi");
bmpImage.SetResolution(96.0, 96.0);
System.Console.WriteLine("The horizontal resolution, in pixels per inch: {0}", bmpImage.HorizontalResolution);
System.Console.WriteLine("The vertical resolution, in pixels per inch: {0}", bmpImage.VerticalResolution);
}
//The output may look like this:
//The pixel format: Rgb24Bpp, used channels: 8,8,8
//The raw line size in bytes: 1500
//The bitmap compression: Rgb
//The bitmap width: 500
//The bitmap height: 375
//The number of bits per pixel: 24
//The horizontal resolution, in pixels per inch: 0
//The vertical resolution, in pixels per inch: 0
//Set resolution values to 96 dpi
//The horizontal resolution, in pixels per inch: 96.012
//The vertical resolution, in pixels per inch: 96.012
}
Το παρακάτω παράδειγμα δείχνει πώς η συμπίεση bitmap επηρεάζει το μέγεθος της εικόνας εξόδου.
Aspose.Imaging.FileFormats.Bmp.BitmapCompression[] compressions = new Aspose.Imaging.FileFormats.Bmp.BitmapCompression[]
{
Aspose.Imaging.FileFormats.Bmp.BitmapCompression.Rgb,
Aspose.Imaging.FileFormats.Bmp.BitmapCompression.Rle8,
};
Aspose.Imaging.Color[] paletterColors = new Aspose.Imaging.Color[]
{
Aspose.Imaging.Color.Red,
Aspose.Imaging.Color.Green,
};
// Create a monochrome palette which contains only red and green colors.
Aspose.Imaging.IColorPalette palette = new Aspose.Imaging.ColorPalette(paletterColors);
foreach (Aspose.Imaging.FileFormats.Bmp.BitmapCompression compression in compressions)
{
// Create a 8-bpp BMP image of 100 x 100 px.
using (Aspose.Imaging.FileFormats.Bmp.BmpImage bmpImage = new Aspose.Imaging.FileFormats.Bmp.BmpImage(100, 100, 8, palette, compression, 0.0, 0.0))
{
Aspose.Imaging.Graphics gr = new Aspose.Imaging.Graphics(bmpImage);
// Fill the entire image in red.
Aspose.Imaging.Brushes.SolidBrush redBrush = new Aspose.Imaging.Brushes.SolidBrush(Aspose.Imaging.Color.Red);
gr.FillRectangle(redBrush, bmpImage.Bounds);
// Save the image to a stream to get the output image size.
using (System.IO.MemoryStream stream = new System.IO.MemoryStream())
{
bmpImage.Save(stream);
System.Console.WriteLine("---------------------------------------------");
System.Console.WriteLine("The compression={0}", bmpImage.Compression);
System.Console.WriteLine("The number of bits per pixel={0}", bmpImage.BitsPerPixel);
System.Console.WriteLine("The image dimensions={0} x {1}", bmpImage.Width, bmpImage.Height);
System.Console.WriteLine("The raw line size={0}", bmpImage.RawLineSize);
System.Console.WriteLine("The output size in bytes={0}", stream.Length);
}
}
}
// The output looks like this:
// ---------------------------------------------
// The compression = Rgb
// The number of bits per pixel = 8
// The image dimensions = 100 x 100
// The raw line size = 100
// The output size in bytes = 11078
// ---------------------------------------------
// The compression = Rle8
// The number of bits per pixel = 8
// The image dimensions = 100 x 100
// The raw line size = 100
// The output size in bytes = 856
HorizontalResolution
Αυτή η ιδιοκτησία σας επιτρέπει να πάρετε ή να ρυθμίσετε εύκολα την οριζόντια ανάλυση,μετρήθηκε σε pixels ανά ίντσα, του αντικειμένου Aspose.Imaging.RasterImage.Οι προγραμματιστές χρειάζονται ακριβή έλεγχο της ανάλυσης εικόνας για τις εφαρμογές τους.
public override double HorizontalResolution { get; set; }
Αξία ιδιοκτησίας
Examples
Το παρακάτω παράδειγμα δείχνει πώς να ρυθμίσετε οριζόντια / κάθετη ανάλυση μιας εικόνας BMP.
string dir = "c:\\temp\\";
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.bmp"))
{
Aspose.Imaging.FileFormats.Bmp.BmpImage bmpImage = (Aspose.Imaging.FileFormats.Bmp.BmpImage)image;
// Get horizontal and vertical resolution of the BmpImage
double horizontalResolution = bmpImage.HorizontalResolution;
double verticalResolution = bmpImage.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");
bmpImage.SetResolution(96.0, 96.0);
System.Console.WriteLine("The horizontal resolution, in pixels per inch: {0}", bmpImage.HorizontalResolution);
System.Console.WriteLine("The vertical resolution, in pixels per inch: {0}", bmpImage.VerticalResolution);
}
// The output may look like this:
// The horizontal resolution, in pixels per inch: 0
// The vertical resolution, in pixels per inch: 0
// Set resolution values to 96 dpi
// The horizontal resolution, in pixels per inch: 96.012
// The vertical resolution, in pixels per inch: 96.012
}
Το παρακάτω παράδειγμα λαμβάνει τις γενικές πληροφορίες για την εικόνα, συμπεριλαμβανομένης της μορφής pixel, του μεγέθους της εικόνας, της ανάλυσης, της συμπίεσης κλπ.
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(@"c:\temp\sample.bmp"))
{
Aspose.Imaging.FileFormats.Bmp.BmpImage bmpImage = (Aspose.Imaging.FileFormats.Bmp.BmpImage)image;
System.Console.WriteLine("The pixel format: {0}", bmpImage.RawDataFormat);
System.Console.WriteLine("The raw line size in bytes: {0}", bmpImage.RawLineSize);
System.Console.WriteLine("The bitmap compression: {0}", bmpImage.Compression);
System.Console.WriteLine("The bitmap width: {0}", bmpImage.Width);
System.Console.WriteLine("The bitmap height: {0}", bmpImage.Height);
System.Console.WriteLine("The number of bits per pixel: {0}", bmpImage.BitsPerPixel);
double hres = bmpImage.HorizontalResolution;
double vres = bmpImage.VerticalResolution;
System.Console.WriteLine("The horizontal resolution, in pixels per inch: {0}", hres);
System.Console.WriteLine("The vertical resolution, in pixels per inch: {0}", vres);
if (hres != 96.0 || vres != 96.0)
{
// You may consider using the SetResolution method for updating both resolution values in single call.
System.Console.WriteLine("Set resolution values to 96 dpi");
bmpImage.SetResolution(96.0, 96.0);
System.Console.WriteLine("The horizontal resolution, in pixels per inch: {0}", bmpImage.HorizontalResolution);
System.Console.WriteLine("The vertical resolution, in pixels per inch: {0}", bmpImage.VerticalResolution);
}
//The output may look like this:
//The pixel format: Rgb24Bpp, used channels: 8,8,8
//The raw line size in bytes: 1500
//The bitmap compression: Rgb
//The bitmap width: 500
//The bitmap height: 375
//The number of bits per pixel: 24
//The horizontal resolution, in pixels per inch: 0
//The vertical resolution, in pixels per inch: 0
//Set resolution values to 96 dpi
//The horizontal resolution, in pixels per inch: 96.012
//The vertical resolution, in pixels per inch: 96.012
}
Remarks
Σημειώστε προεπιλογή αυτή η τιμή είναι πάντα 96 καθώς διαφορετικές πλατφόρμες δεν μπορούν να επιστρέψουν την ανάλυση οθόνης. Μπορείτε να εξετάσετε τη χρήση της μεθόδου SetResolution για την ενημέρωση και των δύο τιμών ανάλυση σε μία κλήση.
RawDataFormat
Αποκτήστε εύκολα τη μορφή των πρώτων δεδομένων σας με αυτή τη φιλική προς τον χρήστη λειτουργία.Ιδανικό για τους προγραμματιστές που επιθυμούν να έχουν γρήγορη πρόσβαση σε κρίσιμες πληροφορίες σχετικά με τη μορφή δεδομένων τους.
public override PixelDataFormat RawDataFormat { get; }
Αξία ιδιοκτησίας
Examples
Το παρακάτω παράδειγμα δείχνει πώς να εξαγάγετε πληροφορίες σχετικά με τη μορφή πρώτων δεδομένων και το αλφα κανάλι από μια εικόνα 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
Το παρακάτω παράδειγμα λαμβάνει τις γενικές πληροφορίες για την εικόνα, συμπεριλαμβανομένης της μορφής pixel, του μεγέθους της εικόνας, της ανάλυσης, της συμπίεσης κλπ.
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(@"c:\temp\sample.bmp"))
{
Aspose.Imaging.FileFormats.Bmp.BmpImage bmpImage = (Aspose.Imaging.FileFormats.Bmp.BmpImage)image;
System.Console.WriteLine("The pixel format: {0}", bmpImage.RawDataFormat);
System.Console.WriteLine("The raw line size in bytes: {0}", bmpImage.RawLineSize);
System.Console.WriteLine("The bitmap compression: {0}", bmpImage.Compression);
System.Console.WriteLine("The bitmap width: {0}", bmpImage.Width);
System.Console.WriteLine("The bitmap height: {0}", bmpImage.Height);
System.Console.WriteLine("The number of bits per pixel: {0}", bmpImage.BitsPerPixel);
double hres = bmpImage.HorizontalResolution;
double vres = bmpImage.VerticalResolution;
System.Console.WriteLine("The horizontal resolution, in pixels per inch: {0}", hres);
System.Console.WriteLine("The vertical resolution, in pixels per inch: {0}", vres);
if (hres != 96.0 || vres != 96.0)
{
// You may consider using the SetResolution method for updating both resolution values in single call.
System.Console.WriteLine("Set resolution values to 96 dpi");
bmpImage.SetResolution(96.0, 96.0);
System.Console.WriteLine("The horizontal resolution, in pixels per inch: {0}", bmpImage.HorizontalResolution);
System.Console.WriteLine("The vertical resolution, in pixels per inch: {0}", bmpImage.VerticalResolution);
}
//The output may look like this:
//The pixel format: Rgb24Bpp, used channels: 8,8,8
//The raw line size in bytes: 1500
//The bitmap compression: Rgb
//The bitmap width: 500
//The bitmap height: 375
//The number of bits per pixel: 24
//The horizontal resolution, in pixels per inch: 0
//The vertical resolution, in pixels per inch: 0
//Set resolution values to 96 dpi
//The horizontal resolution, in pixels per inch: 96.012
//The vertical resolution, in pixels per inch: 96.012
}
RawLineSize
Γρήγορη πρόσβαση στο μέγεθος κάθε πρώτης γραμμής σε bytes με αυτή την απλή ιδιότητα.Ιδανικό για τους προγραμματιστές που χρειάζονται να χειρίζονται αποτελεσματικά τα πρώτα δεδομένα εικόνας.
public override int RawLineSize { get; }
Αξία ιδιοκτησίας
Examples
Το παρακάτω παράδειγμα λαμβάνει τις γενικές πληροφορίες για την εικόνα, συμπεριλαμβανομένης της μορφής pixel, του μεγέθους της εικόνας, της ανάλυσης, της συμπίεσης κλπ.
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(@"c:\temp\sample.bmp"))
{
Aspose.Imaging.FileFormats.Bmp.BmpImage bmpImage = (Aspose.Imaging.FileFormats.Bmp.BmpImage)image;
System.Console.WriteLine("The pixel format: {0}", bmpImage.RawDataFormat);
System.Console.WriteLine("The raw line size in bytes: {0}", bmpImage.RawLineSize);
System.Console.WriteLine("The bitmap compression: {0}", bmpImage.Compression);
System.Console.WriteLine("The bitmap width: {0}", bmpImage.Width);
System.Console.WriteLine("The bitmap height: {0}", bmpImage.Height);
System.Console.WriteLine("The number of bits per pixel: {0}", bmpImage.BitsPerPixel);
double hres = bmpImage.HorizontalResolution;
double vres = bmpImage.VerticalResolution;
System.Console.WriteLine("The horizontal resolution, in pixels per inch: {0}", hres);
System.Console.WriteLine("The vertical resolution, in pixels per inch: {0}", vres);
if (hres != 96.0 || vres != 96.0)
{
// You may consider using the SetResolution method for updating both resolution values in single call.
System.Console.WriteLine("Set resolution values to 96 dpi");
bmpImage.SetResolution(96.0, 96.0);
System.Console.WriteLine("The horizontal resolution, in pixels per inch: {0}", bmpImage.HorizontalResolution);
System.Console.WriteLine("The vertical resolution, in pixels per inch: {0}", bmpImage.VerticalResolution);
}
//The output may look like this:
//The pixel format: Rgb24Bpp, used channels: 8,8,8
//The raw line size in bytes: 1500
//The bitmap compression: Rgb
//The bitmap width: 500
//The bitmap height: 375
//The number of bits per pixel: 24
//The horizontal resolution, in pixels per inch: 0
//The vertical resolution, in pixels per inch: 0
//Set resolution values to 96 dpi
//The horizontal resolution, in pixels per inch: 96.012
//The vertical resolution, in pixels per inch: 96.012
}
Το παρακάτω παράδειγμα δείχνει πώς η συμπίεση bitmap επηρεάζει το μέγεθος της εικόνας εξόδου.
Aspose.Imaging.FileFormats.Bmp.BitmapCompression[] compressions = new Aspose.Imaging.FileFormats.Bmp.BitmapCompression[]
{
Aspose.Imaging.FileFormats.Bmp.BitmapCompression.Rgb,
Aspose.Imaging.FileFormats.Bmp.BitmapCompression.Rle8,
};
Aspose.Imaging.Color[] paletterColors = new Aspose.Imaging.Color[]
{
Aspose.Imaging.Color.Red,
Aspose.Imaging.Color.Green,
};
// Create a monochrome palette which contains only red and green colors.
Aspose.Imaging.IColorPalette palette = new Aspose.Imaging.ColorPalette(paletterColors);
foreach (Aspose.Imaging.FileFormats.Bmp.BitmapCompression compression in compressions)
{
// Create a 8-bpp BMP image of 100 x 100 px.
using (Aspose.Imaging.FileFormats.Bmp.BmpImage bmpImage = new Aspose.Imaging.FileFormats.Bmp.BmpImage(100, 100, 8, palette, compression, 0.0, 0.0))
{
Aspose.Imaging.Graphics gr = new Aspose.Imaging.Graphics(bmpImage);
// Fill the entire image in red.
Aspose.Imaging.Brushes.SolidBrush redBrush = new Aspose.Imaging.Brushes.SolidBrush(Aspose.Imaging.Color.Red);
gr.FillRectangle(redBrush, bmpImage.Bounds);
// Save the image to a stream to get the output image size.
using (System.IO.MemoryStream stream = new System.IO.MemoryStream())
{
bmpImage.Save(stream);
System.Console.WriteLine("---------------------------------------------");
System.Console.WriteLine("The compression={0}", bmpImage.Compression);
System.Console.WriteLine("The number of bits per pixel={0}", bmpImage.BitsPerPixel);
System.Console.WriteLine("The image dimensions={0} x {1}", bmpImage.Width, bmpImage.Height);
System.Console.WriteLine("The raw line size={0}", bmpImage.RawLineSize);
System.Console.WriteLine("The output size in bytes={0}", stream.Length);
}
}
}
// The output looks like this:
// ---------------------------------------------
// The compression = Rgb
// The number of bits per pixel = 8
// The image dimensions = 100 x 100
// The raw line size = 100
// The output size in bytes = 11078
// ---------------------------------------------
// The compression = Rle8
// The number of bits per pixel = 8
// The image dimensions = 100 x 100
// The raw line size = 100
// The output size in bytes = 856
VerticalResolution
Μπορείτε εύκολα να ανακτήσετε ή να ρυθμίσετε την κάθετη ανάλυση, μετρημένη σε pixels ανά δισκίο,από αυτό το Aspose.Imaging.RasterImage αντικείμενο με αυτή την ιδιότητα. ιδανικό για τους προγραμματιστές που απαιτούνακριβής έλεγχος της ανάλυσης εικόνας στις εφαρμογές τους.
public override double VerticalResolution { get; set; }
Αξία ιδιοκτησίας
Examples
Το παρακάτω παράδειγμα δείχνει πώς να ρυθμίσετε οριζόντια / κάθετη ανάλυση μιας εικόνας BMP.
string dir = "c:\\temp\\";
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.bmp"))
{
Aspose.Imaging.FileFormats.Bmp.BmpImage bmpImage = (Aspose.Imaging.FileFormats.Bmp.BmpImage)image;
// Get horizontal and vertical resolution of the BmpImage
double horizontalResolution = bmpImage.HorizontalResolution;
double verticalResolution = bmpImage.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");
bmpImage.SetResolution(96.0, 96.0);
System.Console.WriteLine("The horizontal resolution, in pixels per inch: {0}", bmpImage.HorizontalResolution);
System.Console.WriteLine("The vertical resolution, in pixels per inch: {0}", bmpImage.VerticalResolution);
}
// The output may look like this:
// The horizontal resolution, in pixels per inch: 0
// The vertical resolution, in pixels per inch: 0
// Set resolution values to 96 dpi
// The horizontal resolution, in pixels per inch: 96.012
// The vertical resolution, in pixels per inch: 96.012
}
Το παρακάτω παράδειγμα λαμβάνει τις γενικές πληροφορίες για την εικόνα, συμπεριλαμβανομένης της μορφής pixel, του μεγέθους της εικόνας, της ανάλυσης, της συμπίεσης κλπ.
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(@"c:\temp\sample.bmp"))
{
Aspose.Imaging.FileFormats.Bmp.BmpImage bmpImage = (Aspose.Imaging.FileFormats.Bmp.BmpImage)image;
System.Console.WriteLine("The pixel format: {0}", bmpImage.RawDataFormat);
System.Console.WriteLine("The raw line size in bytes: {0}", bmpImage.RawLineSize);
System.Console.WriteLine("The bitmap compression: {0}", bmpImage.Compression);
System.Console.WriteLine("The bitmap width: {0}", bmpImage.Width);
System.Console.WriteLine("The bitmap height: {0}", bmpImage.Height);
System.Console.WriteLine("The number of bits per pixel: {0}", bmpImage.BitsPerPixel);
double hres = bmpImage.HorizontalResolution;
double vres = bmpImage.VerticalResolution;
System.Console.WriteLine("The horizontal resolution, in pixels per inch: {0}", hres);
System.Console.WriteLine("The vertical resolution, in pixels per inch: {0}", vres);
if (hres != 96.0 || vres != 96.0)
{
// You may consider using the SetResolution method for updating both resolution values in single call.
System.Console.WriteLine("Set resolution values to 96 dpi");
bmpImage.SetResolution(96.0, 96.0);
System.Console.WriteLine("The horizontal resolution, in pixels per inch: {0}", bmpImage.HorizontalResolution);
System.Console.WriteLine("The vertical resolution, in pixels per inch: {0}", bmpImage.VerticalResolution);
}
//The output may look like this:
//The pixel format: Rgb24Bpp, used channels: 8,8,8
//The raw line size in bytes: 1500
//The bitmap compression: Rgb
//The bitmap width: 500
//The bitmap height: 375
//The number of bits per pixel: 24
//The horizontal resolution, in pixels per inch: 0
//The vertical resolution, in pixels per inch: 0
//Set resolution values to 96 dpi
//The horizontal resolution, in pixels per inch: 96.012
//The vertical resolution, in pixels per inch: 96.012
}
Remarks
Σημειώστε προεπιλογή αυτή η τιμή είναι πάντα 96 καθώς διαφορετικές πλατφόρμες δεν μπορούν να επιστρέψουν την ανάλυση οθόνης. Μπορείτε να εξετάσετε τη χρήση της μεθόδου SetResolution για την ενημέρωση και των δύο τιμών ανάλυση σε μία κλήση.
Width
Πρόσβαση στο πλάτος της εικόνας εύκολα με αυτή την ιδιότητα. ιδανικό για τους προγραμματιστέςΑναζητώντας γρήγορες πληροφορίες σχετικά με τις διαστάσεις της εικόνας.
public override int Width { get; }
Αξία ιδιοκτησίας
Examples
Το παρακάτω παράδειγμα λαμβάνει τις γενικές πληροφορίες για την εικόνα, συμπεριλαμβανομένης της μορφής pixel, του μεγέθους της εικόνας, της ανάλυσης, της συμπίεσης κλπ.
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(@"c:\temp\sample.bmp"))
{
Aspose.Imaging.FileFormats.Bmp.BmpImage bmpImage = (Aspose.Imaging.FileFormats.Bmp.BmpImage)image;
System.Console.WriteLine("The pixel format: {0}", bmpImage.RawDataFormat);
System.Console.WriteLine("The raw line size in bytes: {0}", bmpImage.RawLineSize);
System.Console.WriteLine("The bitmap compression: {0}", bmpImage.Compression);
System.Console.WriteLine("The bitmap width: {0}", bmpImage.Width);
System.Console.WriteLine("The bitmap height: {0}", bmpImage.Height);
System.Console.WriteLine("The number of bits per pixel: {0}", bmpImage.BitsPerPixel);
double hres = bmpImage.HorizontalResolution;
double vres = bmpImage.VerticalResolution;
System.Console.WriteLine("The horizontal resolution, in pixels per inch: {0}", hres);
System.Console.WriteLine("The vertical resolution, in pixels per inch: {0}", vres);
if (hres != 96.0 || vres != 96.0)
{
// You may consider using the SetResolution method for updating both resolution values in single call.
System.Console.WriteLine("Set resolution values to 96 dpi");
bmpImage.SetResolution(96.0, 96.0);
System.Console.WriteLine("The horizontal resolution, in pixels per inch: {0}", bmpImage.HorizontalResolution);
System.Console.WriteLine("The vertical resolution, in pixels per inch: {0}", bmpImage.VerticalResolution);
}
//The output may look like this:
//The pixel format: Rgb24Bpp, used channels: 8,8,8
//The raw line size in bytes: 1500
//The bitmap compression: Rgb
//The bitmap width: 500
//The bitmap height: 375
//The number of bits per pixel: 24
//The horizontal resolution, in pixels per inch: 0
//The vertical resolution, in pixels per inch: 0
//Set resolution values to 96 dpi
//The horizontal resolution, in pixels per inch: 96.012
//The vertical resolution, in pixels per inch: 96.012
}
Το παρακάτω παράδειγμα δείχνει πώς η συμπίεση bitmap επηρεάζει το μέγεθος της εικόνας εξόδου.
Aspose.Imaging.FileFormats.Bmp.BitmapCompression[] compressions = new Aspose.Imaging.FileFormats.Bmp.BitmapCompression[]
{
Aspose.Imaging.FileFormats.Bmp.BitmapCompression.Rgb,
Aspose.Imaging.FileFormats.Bmp.BitmapCompression.Rle8,
};
Aspose.Imaging.Color[] paletterColors = new Aspose.Imaging.Color[]
{
Aspose.Imaging.Color.Red,
Aspose.Imaging.Color.Green,
};
// Create a monochrome palette which contains only red and green colors.
Aspose.Imaging.IColorPalette palette = new Aspose.Imaging.ColorPalette(paletterColors);
foreach (Aspose.Imaging.FileFormats.Bmp.BitmapCompression compression in compressions)
{
// Create a 8-bpp BMP image of 100 x 100 px.
using (Aspose.Imaging.FileFormats.Bmp.BmpImage bmpImage = new Aspose.Imaging.FileFormats.Bmp.BmpImage(100, 100, 8, palette, compression, 0.0, 0.0))
{
Aspose.Imaging.Graphics gr = new Aspose.Imaging.Graphics(bmpImage);
// Fill the entire image in red.
Aspose.Imaging.Brushes.SolidBrush redBrush = new Aspose.Imaging.Brushes.SolidBrush(Aspose.Imaging.Color.Red);
gr.FillRectangle(redBrush, bmpImage.Bounds);
// Save the image to a stream to get the output image size.
using (System.IO.MemoryStream stream = new System.IO.MemoryStream())
{
bmpImage.Save(stream);
System.Console.WriteLine("---------------------------------------------");
System.Console.WriteLine("The compression={0}", bmpImage.Compression);
System.Console.WriteLine("The number of bits per pixel={0}", bmpImage.BitsPerPixel);
System.Console.WriteLine("The image dimensions={0} x {1}", bmpImage.Width, bmpImage.Height);
System.Console.WriteLine("The raw line size={0}", bmpImage.RawLineSize);
System.Console.WriteLine("The output size in bytes={0}", stream.Length);
}
}
}
// The output looks like this:
// ---------------------------------------------
// The compression = Rgb
// The number of bits per pixel = 8
// The image dimensions = 100 x 100
// The raw line size = 100
// The output size in bytes = 11078
// ---------------------------------------------
// The compression = Rle8
// The number of bits per pixel = 8
// The image dimensions = 100 x 100
// The raw line size = 100
// The output size in bytes = 856
Methods
GetDefaultOptions(αντικείμενο[])
Αποκαταστήστε τις προεπιλεγμένες επιλογές χωρίς προσπάθεια με αυτή την απλή μέθοδο.Ιδανικό για τους προγραμματιστές που αναζητούν γρήγορη πρόσβαση σε προεπιλεγμένες ρυθμίσεις ή ρυθμίσεις εικόνας.
public override ImageOptionsBase GetDefaultOptions(object[] args)
Parameters
args
object
[ ]
Τα επιχειρήματα .
Returns
Προεπιλεγμένες επιλογές
OnCached()
Καλούνται όταν τα δεδομένα είναι κρυπτογραφημένα και όλες οι σχετικές πόροι μπορεί να αποκατασταθούν.
protected override void OnCached()
OnPaletteChanging(Ετικέτες IColor, IColorPalette)
Ονομάζεται όταν αλλάζει παλέτα.
protected override void OnPaletteChanging(IColorPalette oldPalette, IColorPalette newPalette)
Parameters
oldPalette
IColorPalette
Η παλιά παλέτα.
newPalette
IColorPalette
Η νέα παλέτα.
SaveData(Stream)
Αποθηκεύει τα δεδομένα.
protected override void SaveData(Stream stream)
Parameters
stream
Stream
Η ροή για να αποθηκεύσετε τα δεδομένα.
SetResolution(ΔΥΟ, ΔΥΟ)
Προσαρμόστε την ανάλυση του Aspose.Imaging.RasterImage χωρίς προσπάθεια με αυτόμέθοδος φιλική προς τον χρήστη. ιδανικό για τους προγραμματιστές που αναζητούν ακριβή έλεγχοΗ ανάλυση εικόνας στις εφαρμογές τους.
public override void SetResolution(double dpiX, double dpiY)
Parameters
dpiX
double
Η οριζόντια ανάλυση, σε σημεία ανά ίντσα, του Aspose.Imaging.RasterImage.
dpiY
double
Η κάθετη ανάλυση, σε σημεία ανά ίντσα, του Aspose.Imaging.RasterImage.
Examples
Το παρακάτω παράδειγμα δείχνει πώς να ρυθμίσετε οριζόντια / κάθετη ανάλυση μιας εικόνας BMP.
string dir = "c:\\temp\\";
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.bmp"))
{
Aspose.Imaging.FileFormats.Bmp.BmpImage bmpImage = (Aspose.Imaging.FileFormats.Bmp.BmpImage)image;
// Get horizontal and vertical resolution of the BmpImage
double horizontalResolution = bmpImage.HorizontalResolution;
double verticalResolution = bmpImage.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");
bmpImage.SetResolution(96.0, 96.0);
System.Console.WriteLine("The horizontal resolution, in pixels per inch: {0}", bmpImage.HorizontalResolution);
System.Console.WriteLine("The vertical resolution, in pixels per inch: {0}", bmpImage.VerticalResolution);
}
// The output may look like this:
// The horizontal resolution, in pixels per inch: 0
// The vertical resolution, in pixels per inch: 0
// Set resolution values to 96 dpi
// The horizontal resolution, in pixels per inch: 96.012
// The vertical resolution, in pixels per inch: 96.012
}
Το παρακάτω παράδειγμα λαμβάνει τις γενικές πληροφορίες για την εικόνα, συμπεριλαμβανομένης της μορφής pixel, του μεγέθους της εικόνας, της ανάλυσης, της συμπίεσης κλπ.
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(@"c:\temp\sample.bmp"))
{
Aspose.Imaging.FileFormats.Bmp.BmpImage bmpImage = (Aspose.Imaging.FileFormats.Bmp.BmpImage)image;
System.Console.WriteLine("The pixel format: {0}", bmpImage.RawDataFormat);
System.Console.WriteLine("The raw line size in bytes: {0}", bmpImage.RawLineSize);
System.Console.WriteLine("The bitmap compression: {0}", bmpImage.Compression);
System.Console.WriteLine("The bitmap width: {0}", bmpImage.Width);
System.Console.WriteLine("The bitmap height: {0}", bmpImage.Height);
System.Console.WriteLine("The number of bits per pixel: {0}", bmpImage.BitsPerPixel);
double hres = bmpImage.HorizontalResolution;
double vres = bmpImage.VerticalResolution;
System.Console.WriteLine("The horizontal resolution, in pixels per inch: {0}", hres);
System.Console.WriteLine("The vertical resolution, in pixels per inch: {0}", vres);
if (hres != 96.0 || vres != 96.0)
{
// You may consider using the SetResolution method for updating both resolution values in single call.
System.Console.WriteLine("Set resolution values to 96 dpi");
bmpImage.SetResolution(96.0, 96.0);
System.Console.WriteLine("The horizontal resolution, in pixels per inch: {0}", bmpImage.HorizontalResolution);
System.Console.WriteLine("The vertical resolution, in pixels per inch: {0}", bmpImage.VerticalResolution);
}
//The output may look like this:
//The pixel format: Rgb24Bpp, used channels: 8,8,8
//The raw line size in bytes: 1500
//The bitmap compression: Rgb
//The bitmap width: 500
//The bitmap height: 375
//The number of bits per pixel: 24
//The horizontal resolution, in pixels per inch: 0
//The vertical resolution, in pixels per inch: 0
//Set resolution values to 96 dpi
//The horizontal resolution, in pixels per inch: 96.012
//The vertical resolution, in pixels per inch: 96.012
}
ToBitmap()
Μπορείτε εύκολα να μετατρέψετε την εικόνα σας σε bitmap με αυτή την απλή μέθοδο.Ιδανικό για τους προγραμματιστές που χρειάζονται αδιάλειπτη μετάβαση μεταξύ διαφορετικών μορφών εικόνας.
public override Bitmap ToBitmap()
Returns
Το bitmap
Examples
Το παρακάτω παράδειγμα μετατρέπει μια εικόνα BMP σε bitmap GDI.
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(@"c:\temp\sample.bmp"))
{
Aspose.Imaging.FileFormats.Bmp.BmpImage bmpImage = (Aspose.Imaging.FileFormats.Bmp.BmpImage)image;
System.Drawing.Bitmap bitmap = bmpImage.ToBitmap();
// Process the GDI bitmap.
}
UpdateDimensions(ΕΝΤ, ΕΝΤ)
Αναβαθμίζει τις διαστάσεις της εικόνας.
protected override void UpdateDimensions(int newWidth, int newHeight)
Parameters
newWidth
int
Το νέο πλάτος της εικόνας.
newHeight
int
Το νέο ύψος της εικόνας.