 |
VectSharp
2.2.1
A light library for C# vector graphics
|
20 using System.Runtime.InteropServices;
66 this.InternalPointer = pointer;
69 private bool disposedValue;
72 protected virtual void Dispose(
bool disposing)
84 Dispose(disposing:
false);
90 Dispose(disposing:
true);
91 GC.SuppressFinalize(
this);
113 public string Id {
get;
protected set; }
123 public int Width {
get;
protected set; }
128 public int Height {
get;
protected set; }
135 private MemoryStream _PNGStream =
null;
144 if (_PNGStream ==
null)
146 _PNGStream =
new MemoryStream();
147 this.EncodeAsPNG(_PNGStream);
149 _PNGStream.Seek(0, SeekOrigin.Begin);
170 public RasterImage(IntPtr pixelData,
int width,
int height,
bool hasAlpha,
bool interpolate)
172 this.
Id = Guid.NewGuid().ToString();
190 this.
Id = Guid.NewGuid().ToString();
210 GC.AddMemoryPressure(data.Length);
212 this.
Id = Guid.NewGuid().ToString();
229 int pixelSize = pixelFormat ==
PixelFormats.BGRA ? 4 : 3;
230 int pixelCount = width * height;
235 for (
int i = 0; i < pixelCount; i++)
237 dataPointer[i * pixelSize] = data[i * pixelSize + 2];
238 dataPointer[i * pixelSize + 1] = data[i * pixelSize + 1];
239 dataPointer[i * pixelSize + 2] = data[i * pixelSize];
242 dataPointer[i * pixelSize + 3] = data[i * pixelSize + 3];
250 private void EncodeAsPNG(Stream outputStream)
263 _PNGStream?.Dispose();
267 private bool disposedValue;
270 protected virtual void Dispose(
bool disposing)
276 _PNGStream?.Dispose();
284 disposedValue =
true;
298 GC.SuppressFinalize(
this);
MemoryStream PNGStream
Contains a representation of the image in PNG format. Generated at the first access and cached until ...
Represents a raster image, created from raw pixel data. Consider using the derived classes included i...
An IDisposable wrapper around an IntPtr that frees the allocated memory when it is disposed.
int Width
The width in pixels of the image.
bool Interpolate
Determines whether the image should be interpolated when it is resized.
bool HasAlpha
Determines whether the image has an alpha channel.
DisposableIntPtr(IntPtr pointer)
Create a new DisposableIntPtr.
readonly IntPtr InternalPointer
The pointer to the unmanaged memory.
RasterImage(IntPtr pixelData, int width, int height, bool hasAlpha, bool interpolate)
Creates a new RasterImage instance from the specified pixel data in RGB or RGBA format.
IDisposable DataHolder
An IDisposable that will be disposed when the image is disposed.
int Height
The height in pixels of the image.
PixelFormats
Represents the pixel format of a raster image.
IntPtr ImageDataAddress
The memory address of the image pixel data.
void ClearPNGCache()
Disposes the PNGStream. Also useful if is is necessary to regenerate it, e.g. because the underlying ...
RasterImage(ref DisposableIntPtr pixelData, int width, int height, bool hasAlpha, bool interpolate)
Creates a new RasterImage instance from the specified pixel data in RGB or RGBA format.
RasterImage(byte[] data, int width, int height, PixelFormats pixelFormat, bool interpolate)
Creates a new RasterImage instance copying the specified pixel data.
string Id
A univocal identifier for this image.