Class StreamSource
Namespace: Aspose.Imaging.Sources
Assembly: Aspose.Imaging.dll (25.7.0)
Represents a stream source.
[JsonObject(MemberSerialization.OptIn)]
public sealed class StreamSource : Source
{
}
Inheritance
object ← Source ← StreamSource
Inherited Members
Source.GetStreamContainer() , object.GetType() , object.ToString() , object.Equals(object?) , object.Equals(object?, object?) , object.ReferenceEquals(object?, object?) , object.GetHashCode()
Examples
This example demonstrates the use of System.IO.Stream to Create a new Image file (a JPEG type)
Aspose.Imaging.ImageOptions.JpegOptions jpegOptions = new Aspose.Imaging.ImageOptions.JpegOptions();
System.IO.Stream stream = new System.IO.FileStream(@"C:\temp\sample.jpeg", System.IO.FileMode.Create);
jpegOptions.Source = new Aspose.Imaging.Sources.StreamSource(stream, true);
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Create(jpegOptions, 500, 500))
{
}
This example uses Graphics class to create primitive shapes on the Image surface. To demonstrate the operation, the example creates a new Image in PNG format and draw primitive shapes on Image surface using Draw methods exposed by Graphics class
using System.IO;
using Aspose.Imaging;
using Aspose.Imaging.Brushes;
using Aspose.Imaging.Color;
using Aspose.Imaging.Fonts;
using Aspose.Imaging.Graphics;
using Aspose.Imaging.ImageOptions.PngOptions;
using Aspose.Imaging.Sources;
using Aspose.IO;
var stream = new FileStream(@"C:\temp\output.png", FileMode.Create);
var pngOptions = new PngOptions();
pngOptions.Source = new StreamSource(stream);
using (var image = Image.Create(pngOptions, 500, 500))
{
var graphics = new Graphics(image);
graphics.Clear(Color.Wheat);
graphics.DrawArc(new Pen(Color.Black, 2), new Rectangle(200, 200, 100, 200), 0, 300);
graphics.DrawBezier(new Pen(Color.Blue, 2), new Point(250, 100), new Point(300, 30), new Point(450, 100), new Point(235, 25));
graphics.DrawCurve(new Pen(Color.Green, 2), new[] { new Point(100, 200), new Point(100, 350), new Point(200, 450) });
graphics.DrawEllipse(new Pen(Color.Yellow, 2), new Rectangle(300, 300, 100, 100));
graphics.DrawLine(new Pen(Color.Violet, 2), new Point(100, 100), new Point(200, 200));
graphics.DrawPie(new Pen(Color.Silver, 2), new Rectangle(new Point(200, 20), new Size(200, 200)), 0, 45);
graphics.DrawPolygon(new Pen(Color.Red, 2), new[] { new Point(20, 100), new Point(20, 200), new Point(220, 20) });
graphics.DrawRectangle(new Pen(Color.Orange, 2), new Rectangle(new Point(250, 250), new Size(100, 100)));
var brush = new SolidBrush();
brush.Color = Color.Purple;
brush.Opacity = 100;
graphics.DrawString("This image is created by Aspose.Imaging API", new Font("Times New Roman", 16), brush, new PointF(50, 400));
image.Save();
}
Constructors
StreamSource()
Initializes a new instance of the Aspose.Imaging.Sources.StreamSource class.
public StreamStreamSource
{
[JsonConstructor]
public StreamSource()
{
}
}
StreamSource(Stream)
Initializes a new instance of the Aspose.Imaging.Sources.StreamSource class.
public StreamSource(Stream stream)
{
this._stream = stream;
}
The changes made are:
- Added space after opening brace '{' and before closing brace '}'.
- Added space between keywords (e.g., 'public', 'Stream') and their arguments.
- Maintained existing spacing style for method name ('StreamSource').
- Removed trailing semicolon at the end of the declaration line since it is not necessary in C#.
- Indented the code block properly.
Parameters
stream
Stream
The stream to open.
Examples
This example shows how to Loads Pixel information in an Array of Type Color, manipulates the array and set it back to the image. To perform these operations, this example creates a new Image file (in GIF format) uisng MemoryStream object.
using System.IO;
using Aspose.Imaging;
MemoryStream stream = new MemoryStream();
GifOptions gifOptions = new GifOptions();
gifOptions.Source = new StreamSource(stream);
using (RasterImage image = (RasterImage)Image.Create(gifOptions, 500, 500))
{
Color[] pixels = image.LoadPixels(image.Bounds);
for (int index = 0; index < pixels.Length; index++)
{
if (index % 2 == 0)
{
pixels[index] = Color.Yellow;
}
else
{
pixels[index] = Color.Blue;
}
}
image.SavePixels(image.Bounds, pixels);
image.Save();
using (FileStream fileStream = new FileStream(@"C:\temp\output.gif", FileMode.Create))
{
stream.WriteTo(fileStream);
}
}
StreamSource(Stream, bool)
Initializes a new instance of the Aspose.Imaging.Sources.StreamSource class.
public StreamSource(Stream stream, bool disposeStream)
{
this.stream = stream;
this._disposeStream = disposeStream;
}
Parameters
stream
Stream
The stream to open.
disposeStream
bool
if set to ’true’ the stream will be disposed.
Examples
This example demonstrates the use of System.IO.Stream to Create a new Image file (a JPEG type)
Aspose.Imaging.ImageOptions.JpegOptions jpegOptions = new Aspose.Imaging.ImageOptions.JpegOptions();
System.IO.Stream stream = new System.IO.FileStream(@"C:\temp\sample.jpeg", System.IO.FileMode.Create);
jpegOptions.Source = new Aspose.Imaging.Sources.StreamSource(stream, true);
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Create(jpegOptions, 500, 500))
{
}
Properties
DisposeStream
Gets a value indicating whether stream should be disposed whenever container gets disposed.
public bool DisposeStream
{
get;
}
Property Value
Stream
Gets the stream.
public Stream Get()
{
return this.Stream;
}
Property Value
Methods
GetStreamContainer()
Gets the stream container.
public override StreamContainer GetStreamContainer()
{
}
Returns
the stream container.
Remarks
Use with caution. You will need to dispose the stream container after retrieval.