Class DataStreamSupporter
Namespace: Aspose.Imaging
Assembly: Aspose.Imaging.dll (25.2.0)
The data stream container.
[JsonObject(MemberSerialization.OptIn)]
public abstract class DataStreamSupporter : DisposableObject, IDisposable
Inheritance
object ← DisposableObject ← DataStreamSupporter
Derived
Implements
Inherited Members
DisposableObject.Dispose(), DisposableObject.ReleaseManagedResources(), DisposableObject.ReleaseUnmanagedResources(), DisposableObject.VerifyNotDisposed(), DisposableObject.Disposed, object.GetType(), object.MemberwiseClone(), object.ToString(), object.Equals(object?), object.Equals(object?, object?), object.ReferenceEquals(object?, object?), object.GetHashCode()
Constructors
DataStreamSupporter()
Initializes a new instance of the Aspose.Imaging.DataStreamSupporter class.
[JsonConstructor]
protected DataStreamSupporter()
Fields
timeout
The timeout to wait for synchronization
[JsonProperty]
protected int timeout
Field Value
Properties
DataStreamContainer
Gets the object’s data stream.
public StreamContainer DataStreamContainer { get; }
Property Value
IsCached
Gets a value indicating whether object’s data is cached currently and no data reading is required.
public abstract bool IsCached { get; }
Property Value
Methods
CacheData()
Caches the data and ensures no additional data loading will be performed from the underlying Aspose.Imaging.DataStreamSupporter.DataStreamContainer.
public abstract void CacheData()
Examples
The following example shows how image caching affects performance. In general case, reading cached data is performed faster than reading non-cached data.```csharp [C#]
string dir = "c:\\temp\\";
// Load an image from a PNG file.
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.png"))
{
// Cache all pixel data so that no additional data loading will be performed from the underlying data stream
image.CacheData();
System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch();
stopwatch.Start();
// Reading all pixels is pretty fast.
Aspose.Imaging.RasterImage rasterImage = (Aspose.Imaging.RasterImage)image;
for (int y = 0; y < image.Height; y++)
{
for (int x = 0; x < image.Width; x++)
{
int color = rasterImage.GetArgb32Pixel(x, y);
}
}
stopwatch.Stop();
System.Console.WriteLine("Reading all cached pixels took {0} ms.", stopwatch.ElapsedMilliseconds);
}
// Load an image from a PNG file
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.png"))
{
System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch();
stopwatch.Start();
// Reading all pixels is not as fast as when caching
Aspose.Imaging.RasterImage rasterImage = (Aspose.Imaging.RasterImage)image;
for (int y = 0; y < image.Height; y++)
{
for (int x = 0; x < image.Width; x++)
{
int color = rasterImage.GetArgb32Pixel(x, y);
}
}
stopwatch.Stop();
System.Console.WriteLine("Reading all pixels without preliminary caching took {0} ms.", stopwatch.ElapsedMilliseconds);
}
// The output may look like this:
// Reading all cached pixels took 1500 ms.
// Reading all pixels without preliminary caching took 150000 ms.
### <a id="Aspose_Imaging_DataStreamSupporter_OnDataStreamContainerChanging_Aspose_Imaging_StreamContainer_"></a> OnDataStreamContainerChanging\(StreamContainer\)
Called when data stream container is changing.
```csharp
protected virtual void OnDataStreamContainerChanging(StreamContainer streamContainer)
Parameters
streamContainer
StreamContainer
The stream container.
ReleaseManagedResources()
Releases the managed resources. Make sure no unmanaged resources are released here, since they may have been already released.
protected override void ReleaseManagedResources()
Save()
Saves the object’s data to the current Aspose.Imaging.DataStreamSupporter.
public virtual void Save()
Save(Stream)
Saves the object’s data to the specified stream.
public void Save(Stream stream)
Parameters
stream
Stream
The stream to save the object’s data to.
Save(string)
Saves the object’s data to the specified file location.
public virtual void Save(string filePath)
Parameters
filePath
string
The file path to save the object’s data to.
Save(string, bool)
Saves the object’s data to the specified file location.
public virtual void Save(string filePath, bool overWrite)
Parameters
filePath
string
The file path to save the object’s data to.
overWrite
bool
if set to true
over write the file contents, otherwise append will occur.
SaveData(Stream)
Saves the data.
protected abstract void SaveData(Stream stream)
Parameters
stream
Stream
The stream to save data to.