Saves a
Image to a stream using an offset within it, in any of the supported compressed or uncompressed formats.
Syntax
Parameters
- stream
- A Stream where the image data will be saved.
- offset
- The offset within the specified stream, in which the saved image file will be embedded. For example, if you specify 5,
then 5 bytes of other data will precede the embedded file.
- format
- The output file format. For valid values, refer to
Summary of All Supported Image File Formats.
- bitsPerPixel
- Resulting file's pixel depth. Note that not all bits per pixel are
available to all file formats. For valid values, refer to
Summary of All Supported Image File Formats. If
bitsPerPixel is 0, the image will be stored using the closest bits per pixel value supported by that format.
For example, if a file format supports 1, 4, and 24 bits per pixel, and
RasterImage.BitsPerPixel is 5, the file will be stored as a 24-bit image.
Likewise, if
RasterImage.BitsPerPixel is 2, the file will be stored as a 4-bit image.
- qualityFactor
- A quality factor to be used when saving the RasterImageViewer.Image to a stream.
Return Value
The size of the embedded image file, in bytes.
Example
This example will save an image to a stream before loading it back.
Visual Basic | Copy Code |
---|
Public Sub RasterImageViewer_Save3(ByVal viewer As RasterImageViewer)
Dim srcFileName As String = "C:\Program Files\LEAD Technologies\LEADTOOLS 15\Images\Image1.cmp"
Dim destFileName As String = "C:\Program Files\LEAD Technologies\LEADTOOLS 15\Images\Image1_SaveStream3.bin"
viewer.Load(srcFileName, 0, CodecsLoadByteOrder.BgrOrGray, 1)
Dim ms As MemoryStream = New MemoryStream()
Console.WriteLine("Saving the image")
Dim position As Long = viewer.Save(ms, 0, RasterImageFormat.Cmp, 24, 128)
Console.WriteLine("{0} bytes saved to the stream")
Dim fs As FileStream = File.Create(destFileName)
Try
ms.WriteTo(fs)
Finally
CType(fs, IDisposable).Dispose()
End Try
ms.Close()
Console.WriteLine("Loading the file back")
viewer.Load(destFileName, 0, CodecsLoadByteOrder.BgrOrGray, 1)
End Sub |
C# | Copy Code |
---|
public void RasterImageViewer_Save3(RasterImageViewer viewer) { string srcFileName = @"C:\Program Files\LEAD Technologies\LEADTOOLS 15\Images\Image1.cmp"; string destFileName = @"C:\Program Files\LEAD Technologies\LEADTOOLS 15\Images\Image1_SaveStream3.bin"; // Load the source image viewer.Load(srcFileName, 0, CodecsLoadByteOrder.BgrOrGray, 1); // Create a memory stream MemoryStream ms = new MemoryStream(); // Save this image to the stream after the header Console.WriteLine("Saving the image"); long position = viewer.Save(ms, 0, RasterImageFormat.Cmp, 24, 128); Console.WriteLine("{0} bytes saved to the stream"); // Save the stream to a file using (FileStream fs = File.Create(destFileName)) ms.WriteTo(fs); ms.Close(); // Make sure the saved file works // Save the image to disk Console.WriteLine("Loading the file back"); viewer.Load(destFileName, 0, CodecsLoadByteOrder.BgrOrGray, 1); } |
Remarks
Requirements
Target Platforms: Microsoft .NET Framework 3.0, Windows XP, Windows Vista, and Windows Server 2003 family
See Also