Gets or sets a value that indicates whether to automatically populate the scanline buffers in CodecsSaveImageEventArgs when using the RasterCodecs.SaveImage event.
public bool RetrieveDataFromImage {get; set;} Public Property RetrieveDataFromImage As Boolean public bool RetrieveDataFromImage {get; set;} @property (nonatomic, assign) BOOL retrieveDataFromImage public boolean getRetrieveDataFromImage()public void setRetrieveDataFromImage(boolean value)
get_RetrieveDataFromImage();set_RetrieveDataFromImage(value);Object.defineProperty('RetrieveDataFromImage');
true to automatically populate the scanline buffers in CodecsSaveImageEventArgs when using the RasterCodecs.SaveImage event, or false to make the user responsible for populating the scanline buffers. Default value is false.
The Buffer property works as the input and output buffer containing the image data to save. If the value of RetrieveDataFromImage is set to false (the default), then the user is always responsible for providing the image data by setting in Buffer. If the value of RetrieveDataFromImage is set to true, then the RasterCodecs object will populate the Buffer prior to raising this event. The user can then inspect or modify the scanlines data or simple ignore it to save the original image data as is.
Notice that on either case, the user must provide the scanline data in the source image original format (stored in the Image property. The RasterCodecs object will then convert this data to the appropriate output format if needed, for example, if the user instructed the RasterCodecs object to save the image in a different file format than the original image.
The following example shows how to use RetrieveDataFromImage to:
using Leadtools;using Leadtools.Codecs;private int myMode;public void RetrieveDataFromImageExample(){using (RasterCodecs codecs = new RasterCodecs()){string srcFile = Path.Combine(LEAD_VARS.ImagesDir, "Sample1.cmp");string blankFile = Path.Combine(LEAD_VARS.ImagesDir, "Sample1_Blank.bmp");string defaultFile = Path.Combine(LEAD_VARS.ImagesDir, "Sample1_Default.bmp");string invertedFile = Path.Combine(LEAD_VARS.ImagesDir, "Sample1_Inverted.bmp");// Load the source imageusing (RasterImage image = codecs.Load(srcFile)){// Subscribe to the SaveImage eventcodecs.SaveImage += new EventHandler<CodecsSaveImageEventArgs>(codecs_SaveImage);// First, set RetrieveDataFromImage to false and save// This should generate a blank imagemyMode = 0;codecs.Options.Save.RetrieveDataFromImage = false;codecs.Save(image, blankFile, RasterImageFormat.Bmp, 24);// Next, set RetrieveDataFromImage to true but do not// change the data, this should generate the correct image and is the equivalant// to calling Save without subscribing to SaveImagemyMode = 1;codecs.Options.Save.RetrieveDataFromImage = true;codecs.Save(image, defaultFile, RasterImageFormat.Bmp, 24);// Finally, leave RetrieveDataFromImage as true but change the data by inverting// the scanlines, this should generate an inverted imagemyMode = 2;codecs.Save(image, invertedFile, RasterImageFormat.Bmp, 24);codecs.SaveImage -= new EventHandler<CodecsSaveImageEventArgs>(codecs_SaveImage);}}}private void codecs_SaveImage(object sender, CodecsSaveImageEventArgs e){// This example works with 24 bpp images onlyDebug.Assert(e.Image.BitsPerPixel == 24);switch (myMode){case 0:// Do not do anythingbreak;case 1:// Do not do anythingbreak;case 2:// Invert the image data{int scanlineLength = e.Image.BytesPerLine;byte[] scanline = new byte[scanlineLength];// Loop through all the scanlines in the datafor (int y = 0; y < e.Lines; y++){// Get this rowe.Buffer.GetData(y * scanlineLength, scanline, 0, scanlineLength);// Process it by inverting every pixel datafor (int x = 0; x < scanlineLength; x++){scanline[x] = (byte)(255 - scanline[x]);}// Copy it back to the event buffere.Buffer.SetData(y * scanlineLength, scanline, 0, scanlineLength);}}break;}}static class LEAD_VARS{public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images";}
Imports LeadtoolsImports Leadtools.CodecsPrivate myMode As IntegerPublic Sub RetrieveDataFromImageExample()Using codecs As New RasterCodecs()Dim srcFile As String = Path.Combine(LEAD_VARS.ImagesDir, "Sample1.cmp")Dim blankFile As String = Path.Combine(LEAD_VARS.ImagesDir, "Sample1_Blank.bmp")Dim defaultFile As String = Path.Combine(LEAD_VARS.ImagesDir, "Sample1_Default.bmp")Dim invertedFile As String = Path.Combine(LEAD_VARS.ImagesDir, "Sample1_Inverted.bmp")' Load the source imageUsing image As RasterImage = codecs.Load(srcFile)' Subscribe to the SaveImage eventAddHandler codecs.SaveImage, AddressOf codecs_SaveImage' First, set RetrieveDataFromImage to false and save' This should generate a blank imagemyMode = 0codecs.Options.Save.RetrieveDataFromImage = Falsecodecs.Save(image, blankFile, RasterImageFormat.Bmp, 24)' Next, set RetrieveDataFromImage to true but do not' change the data, this should generate the correct image and is the equivalant' to calling Save without subscribing to SaveImagemyMode = 1codecs.Options.Save.RetrieveDataFromImage = Truecodecs.Save(image, defaultFile, RasterImageFormat.Bmp, 24)' Finally, leave RetrieveDataFromImage as true but change the data by inverting' the scanlines, this should generate an inverted imagemyMode = 2codecs.Save(image, invertedFile, RasterImageFormat.Bmp, 24)RemoveHandler codecs.SaveImage, AddressOf codecs_SaveImageEnd UsingEnd UsingEnd SubPrivate Sub codecs_SaveImage(ByVal sender As Object, ByVal e As CodecsSaveImageEventArgs)' This example works with 24 bpp images onlyDebug.Assert(e.Image.BitsPerPixel = 24)Select Case myModeCase 0' Do not do anythingCase 1' Do not do anythingCase 2' Invert the image dataDim scanlineLength As Integer = e.Image.BytesPerLineDim scanline(scanlineLength - 1) As Byte' Loop through all the scanlines in the dataFor y As Integer = 0 To e.Lines - 1' Get this rowe.Buffer.GetData(y * scanlineLength, scanline, 0, scanlineLength)' Process it by inverting every pixel dataFor x As Integer = 0 To scanlineLength - 1scanline(x) = CByte(255 - scanline(x))Next' Copy it back to the event buffere.Buffer.SetData(y * scanlineLength, scanline, 0, scanlineLength)NextEnd SelectEnd SubPublic NotInheritable Class LEAD_VARSPublic Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images"End Class
|
Products |
Support |
Feedback: RetrieveDataFromImage Property - Leadtools.Codecs |
Introduction |
Help Version 19.0.2017.6.16
|

Raster .NET | C API | C++ Class Library | JavaScript HTML5
Document .NET | C API | C++ Class Library | JavaScript HTML5
Medical .NET | C API | C++ Class Library | JavaScript HTML5
Medical Web Viewer .NET
Your email has been sent to support! Someone should be in touch! If your matter is urgent please come back into chat.
Chat Hours:
Monday - Friday, 8:30am to 6pm ET
Thank you for your feedback!
Please fill out the form again to start a new chat.
All agents are currently offline.
Chat Hours:
Monday - Friday
8:30AM - 6PM EST
To contact us please fill out this form and we will contact you via email.