Class StreamSource

Class StreamSource

A név: Aspose.Imaging.Sources Összefoglaló: Aspose.Imaging.dll (25.4.0)

Ez egy áramforrás.

[JsonObject(MemberSerialization.OptIn)]
public sealed class StreamSource : Source

Inheritance

object Source StreamSource

Örökletes tagok

Source.GetStreamContainer() , object.GetType() , object.ToString() , object.Equals(object?) , object.Equals(object?, object?) , object.ReferenceEquals(object?, object?) , object.GetHashCode()

Examples

Ez a példa azt mutatja, hogy a System.IO.Stream új képfájlt hoz létre (JPEG típus)

//Creates an instance of JpegOptions and set its various properties
                                                                                                         Aspose.Imaging.ImageOptions.JpegOptions jpegOptions = new Aspose.Imaging.ImageOptions.JpegOptions();

                                                                                                         //Create an instance of System.IO.Stream
                                                                                                         System.IO.Stream stream = new System.IO.FileStream(@"C:\temp\sample.jpeg", System.IO.FileMode.Create);

                                                                                                         //Define the source property for the instance of JpegOptions
                                                                                                         //Second boolean parameter determins if the Stream is disposed once get out of scope
                                                                                                         jpegOptions.Source = new Aspose.Imaging.Sources.StreamSource(stream, true);

                                                                                                         //Creates an instance of Image and call Create method with JpegOptions as parameter to initialize the Image object   
                                                                                                         using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Create(jpegOptions, 500, 500))
                                                                                                         {
                                                                                                             //do some image processing
                                                                                                         }

Ez a példa a Graphics-osztályt használja az elsődleges formák létrehozására a kép felszínén.A művelet demonstrálása érdekében a minta egy új PNG formátumú képet hoz létre, és a grafika osztály által kimutatott rajz módszerekkel rajzol primitív formákat.

//Creates an instance of FileStream
                                                                                                                                                                                                                                                                using (System.IO.FileStream stream = new System.IO.FileStream(@"C:\temp\output.png", System.IO.FileMode.Create))
                                                                                                                                                                                                                                                                {
                                                                                                                                                                                                                                                                    //Create an instance of PngOptions and set its various properties
                                                                                                                                                                                                                                                                    Aspose.Imaging.ImageOptions.PngOptions pngOptions = new Aspose.Imaging.ImageOptions.PngOptions();

                                                                                                                                                                                                                                                                    //Set the Source for PngOptions
                                                                                                                                                                                                                                                                    pngOptions.Source = new Aspose.Imaging.Sources.StreamSource(stream);

                                                                                                                                                                                                                                                                    //Create an instance of Image 
                                                                                                                                                                                                                                                                    using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Create(pngOptions, 500, 500))
                                                                                                                                                                                                                                                                    {
                                                                                                                                                                                                                                                                        //Create and initialize an instance of Graphics class
                                                                                                                                                                                                                                                                        Aspose.Imaging.Graphics graphics = new Aspose.Imaging.Graphics(image);

                                                                                                                                                                                                                                                                        //Clear Graphics surface
                                                                                                                                                                                                                                                                        graphics.Clear(Aspose.Imaging.Color.Wheat);

                                                                                                                                                                                                                                                                        //Draw an Arc by specifying the Pen object having Black color, 
                                                                                                                                                                                                                                                                        //a Rectangle surrounding the Arc, Start Angle and Sweep Angle
                                                                                                                                                                                                                                                                        graphics.DrawArc(new Aspose.Imaging.Pen(Aspose.Imaging.Color.Black, 2), new Aspose.Imaging.Rectangle(200, 200, 100, 200), 0, 300);

                                                                                                                                                                                                                                                                        //Draw a Bezier by specifying the Pen object having Blue color and co-ordinate Points.
                                                                                                                                                                                                                                                                        graphics.DrawBezier(new Aspose.Imaging.Pen(Aspose.Imaging.Color.Blue, 2), new Aspose.Imaging.Point(250, 100), new Aspose.Imaging.Point(300, 30), new Aspose.Imaging.Point(450, 100), new Aspose.Imaging.Point(235, 25));

                                                                                                                                                                                                                                                                        //Draw a Curve by specifying the Pen object having Green color and an array of Points
                                                                                                                                                                                                                                                                        graphics.DrawCurve(new Aspose.Imaging.Pen(Aspose.Imaging.Color.Green, 2), new[] { new Aspose.Imaging.Point(100, 200), new Aspose.Imaging.Point(100, 350), new Aspose.Imaging.Point(200, 450) });

                                                                                                                                                                                                                                                                        //Draw an Ellipse using the Pen object and a surrounding Rectangle
                                                                                                                                                                                                                                                                        graphics.DrawEllipse(new Aspose.Imaging.Pen(Aspose.Imaging.Color.Yellow, 2), new Aspose.Imaging.Rectangle(300, 300, 100, 100));

                                                                                                                                                                                                                                                                        //Draw a Line 
                                                                                                                                                                                                                                                                        graphics.DrawLine(new Aspose.Imaging.Pen(Aspose.Imaging.Color.Violet, 2), new Aspose.Imaging.Point(100, 100), new Aspose.Imaging.Point(200, 200));

                                                                                                                                                                                                                                                                        //Draw a Pie segment
                                                                                                                                                                                                                                                                        graphics.DrawPie(new Aspose.Imaging.Pen(Aspose.Imaging.Color.Silver, 2), new Aspose.Imaging.Rectangle(new Aspose.Imaging.Point(200, 20), new Aspose.Imaging.Size(200, 200)), 0, 45);

                                                                                                                                                                                                                                                                        //Draw a Polygon by specifying the Pen object having Red color and an array of Points
                                                                                                                                                                                                                                                                        graphics.DrawPolygon(new Aspose.Imaging.Pen(Aspose.Imaging.Color.Red, 2), new[] { new Aspose.Imaging.Point(20, 100), new Aspose.Imaging.Point(20, 200), new Aspose.Imaging.Point(220, 20) });

                                                                                                                                                                                                                                                                        //Draw a Rectangle
                                                                                                                                                                                                                                                                        graphics.DrawRectangle(new Aspose.Imaging.Pen(Aspose.Imaging.Color.Orange, 2), new Aspose.Imaging.Rectangle(new Aspose.Imaging.Point(250, 250), new Aspose.Imaging.Size(100, 100)));

                                                                                                                                                                                                                                                                        //Create a SolidBrush object and set its various properties
                                                                                                                                                                                                                                                                        Aspose.Imaging.Brushes.SolidBrush brush = new Aspose.Imaging.Brushes.SolidBrush();
                                                                                                                                                                                                                                                                        brush.Color = Color.Purple;
                                                                                                                                                                                                                                                                        brush.Opacity = 100;

                                                                                                                                                                                                                                                                        //Draw a String using the SolidBrush object and Font, at specific Point
                                                                                                                                                                                                                                                                        graphics.DrawString("This image is created by Aspose.Imaging API", new Aspose.Imaging.Font("Times New Roman", 16), brush, new Aspose.Imaging.PointF(50, 400));

                                                                                                                                                                                                                                                                        // save all changes.
                                                                                                                                                                                                                                                                        image.Save();
                                                                                                                                                                                                                                                                    }
                                                                                                                                                                                                                                                                }

Constructors

StreamSource()

Kezdeményez egy új példát a Aspose.Imaging.Sources.StreamSource osztály.

[JsonConstructor]
public StreamSource()

StreamSource(Stream)

Kezdeményez egy új példát a Aspose.Imaging.Sources.StreamSource osztály.

public StreamSource(Stream stream)

Parameters

stream Stream

A folyó megnyílik.

Examples

Ez a példa azt mutatja, hogyan kell feltölteni a Pixel információt egy Type Color Array, manipulálja a array és helyezze vissza a képet. Ahhoz, hogy ezeket a műveleteket, ez a példány hoz létre egy új Image fájlt (GIF formátumban) uisng MemoryStream objektum.

//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);
                                                                                                                                                                                                                                                             }   
                                                                                                                                                                                                                                                         }

StreamSource(Áramlás, Bool)

Kezdeményez egy új példát a Aspose.Imaging.Sources.StreamSource osztály.

public StreamSource(Stream stream, bool disposeStream)

Parameters

stream Stream

A folyó megnyílik.

disposeStream bool

Ha „igaznak” van beállítva, az áramlat megszűnik.

Examples

Ez a példa azt mutatja, hogy a System.IO.Stream új képfájlt hoz létre (JPEG típus)

//Creates an instance of JpegOptions and set its various properties
                                                                                                         Aspose.Imaging.ImageOptions.JpegOptions jpegOptions = new Aspose.Imaging.ImageOptions.JpegOptions();

                                                                                                         //Create an instance of System.IO.Stream
                                                                                                         System.IO.Stream stream = new System.IO.FileStream(@"C:\temp\sample.jpeg", System.IO.FileMode.Create);

                                                                                                         //Define the source property for the instance of JpegOptions
                                                                                                         //Second boolean parameter determins if the Stream is disposed once get out of scope
                                                                                                         jpegOptions.Source = new Aspose.Imaging.Sources.StreamSource(stream, true);

                                                                                                         //Creates an instance of Image and call Create method with JpegOptions as parameter to initialize the Image object   
                                                                                                         using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Create(jpegOptions, 500, 500))
                                                                                                         {
                                                                                                             //do some image processing
                                                                                                         }

Properties

DisposeStream

Megkap egy értéket, amely azt jelzi, hogy az áramot minden alkalommal el kell-e szüntetni, amikor a konténert el kell szüntetni.

public bool DisposeStream { get; }

ingatlan értéke

bool

Stream

Megkapja az áramlást.

public Stream Stream { get; }

ingatlan értéke

Stream

Methods

GetStreamContainer()

Megkapja az áramtartót.

public override StreamContainer GetStreamContainer()

Returns

StreamContainer

A konténer áramlása.

Remarks

Használjon óvatosan. meg kell oldani az áramtartót a visszaküldés után.

 Magyar