Enables or disables allocating memory for storing image data.
public bool AllocateImage { get; set; } Public Property AllocateImage As Boolean @property (nonatomic, assign) BOOL allocateImage public boolean getAllocateImage()public void setAllocateImage(boolean value)
true to have LEADTOOLS do the necessary allocation, false to disable it.
If you do not allow LEADTOOLS to allocate the memory for the storage of the image data, then you should process the data manually using the RasterCodecs.LoadImage event.
using Leadtools;using Leadtools.Codecs;RasterImage image;private void Codecs_LoadImage(object sender, CodecsLoadImageEventArgs e){//copy each row of data into our manually allocated RasterImageimage.SetRow(e.Row, e.Buffer.Data, image.BytesPerLine * e.Lines);}public void AllocateImageExample(){string fileName = Path.Combine(LEAD_VARS.ImagesDir, "Image1.cmp");RasterCodecs codecs = new RasterCodecs();CodecsImageInfo info = codecs.GetInformation(fileName, false);int size = info.Width * info.Height * info.BitsPerPixel;IntPtr data = Marshal.AllocHGlobal(size);image = new RasterImage(RasterMemoryFlags.User, info.Width, info.Height, info.BitsPerPixel, RasterByteOrder.Bgr, info.ViewPerspective, null, data, size);image.Access();//Setting the loading options.//Do NOT allow LEADTOOLS to allocate the image datacodecs.Options.Load.AllocateImage = false;codecs.Options.Load.StoreDataInImage = false;//keeping the loaded image data compressed in memory.codecs.Options.Load.Compressed = true;codecs.Options.Load.DiskMemory = false;//force a palletized image to be dithered to the LEAD fixed palette.codecs.Options.Load.FixedPalette = true;//we know the format of the filecodecs.Options.Load.Format = RasterImageFormat.Cmp;//disable loading metadata markers if present in the file, false to ignore them.codecs.Options.Load.Markers = false;codecs.Options.Load.NoDiskMemory = true;codecs.Options.Load.NoInterlace = false;codecs.Options.Load.NoTiledMemory = true;codecs.Options.Load.Passes = 0;//ignore the view perspective stored in the file.codecs.Options.Load.Rotated = false;//set negative pixel values to 0.codecs.Options.Load.Signed = false;codecs.Options.Load.InitAlpha = true;//load super-compressed in memorycodecs.Options.Load.SuperCompressed = true;codecs.Options.Load.TiledMemory = false;codecs.Options.Load.XResolution = 350;codecs.Options.Load.YResolution = 350;//allow loading corrupted imagescodecs.Options.Load.LoadCorrupted = true;codecs.LoadImage += Codecs_LoadImage;codecs.Load(fileName);codecs.LoadImage -= Codecs_LoadImage;image.Release();//Meta file's comments will be saved.codecs.Options.Save.Comments = true;codecs.Options.Save.FixedPalette = true;codecs.Options.Save.GeoKeys = false;//Tiff file output will be gray.codecs.Options.Save.GrayOutput = true;//Meta file's markers will be saved.codecs.Options.Save.Markers = true;codecs.Options.Save.MotorolaOrder = false;codecs.Options.Save.OptimizedPalette = true;codecs.Options.Save.Password = "LEADTOOLS";LeadSize[] resolutions = new LeadSize[1];resolutions[0].Width = 350;resolutions[0].Height = 350;codecs.Options.Save.SetResolutions(resolutions);//Meta file's tags will be saved.codecs.Options.Save.Tags = true;codecs.Options.Save.UseImageDitheringMethod = true;codecs.Save(image, Path.Combine(LEAD_VARS.ImagesDir, "allocate_image.tif"), RasterImageFormat.Tif, 8, 1, image.PageCount, 1, CodecsSavePageMode.Overwrite);// Clean upimage.Dispose();Marshal.FreeHGlobal(data);codecs.Dispose();}static class LEAD_VARS{public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images";}
Imports LeadtoolsImports Leadtools.CodecsPrivate image As RasterImagePrivate Sub Codecs_LoadImage(sender As Object, e As CodecsLoadImageEventArgs)'copy each row of data into our manually allocated RasterImageimage.SetRow(e.Row, e.Buffer.Data, image.BytesPerLine * e.Lines)End SubPublic Sub AllocateImageExample()Dim fileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Image1.cmp")Dim codecs As New RasterCodecs()Dim info As CodecsImageInfo = codecs.GetInformation(fileName, False)Dim size As Integer = info.Width * info.Height * info.BitsPerPixelDim data As IntPtr = Marshal.AllocHGlobal(size)image = New RasterImage(RasterMemoryFlags.User, info.Width, info.Height, info.BitsPerPixel, RasterByteOrder.Bgr, info.ViewPerspective,Nothing, data, size)image.Access()'Setting the loading options.'Do NOT allow LEADTOOLS to allocate the image datacodecs.Options.Load.AllocateImage = Falsecodecs.Options.Load.StoreDataInImage = False'keeping the loaded image data compressed in memory.codecs.Options.Load.Compressed = Truecodecs.Options.Load.DiskMemory = False'force a palletized image to be dithered to the LEAD fixed palette.codecs.Options.Load.FixedPalette = True'we know the format of the filecodecs.Options.Load.Format = RasterImageFormat.Cmp'disable loading metadata markers if present in the file, false to ignore them.codecs.Options.Load.Markers = Falsecodecs.Options.Load.NoDiskMemory = Truecodecs.Options.Load.NoInterlace = Falsecodecs.Options.Load.NoTiledMemory = Truecodecs.Options.Load.Passes = 0'ignore the view perspective stored in the file.codecs.Options.Load.Rotated = False'set negative pixel values to 0.codecs.Options.Load.Signed = Falsecodecs.Options.Load.InitAlpha = True'load super-compressed in memorycodecs.Options.Load.SuperCompressed = Truecodecs.Options.Load.TiledMemory = Falsecodecs.Options.Load.XResolution = 350codecs.Options.Load.YResolution = 350'allow loading corrupted imagescodecs.Options.Load.LoadCorrupted = TrueAddHandler codecs.LoadImage, AddressOf Codecs_LoadImagecodecs.Load(fileName)RemoveHandler codecs.LoadImage, AddressOf Codecs_LoadImageimage.Release()'Meta file's comments will be saved.codecs.Options.Save.Comments = Truecodecs.Options.Save.FixedPalette = Truecodecs.Options.Save.GeoKeys = False'Tiff file output will be gray.codecs.Options.Save.GrayOutput = True'Meta file's markers will be saved.codecs.Options.Save.Markers = Truecodecs.Options.Save.MotorolaOrder = Falsecodecs.Options.Save.OptimizedPalette = Truecodecs.Options.Save.Password = "LEADTOOLS"Dim resolutions As LeadSize() = New LeadSize(0) {}resolutions(0).Width = 350resolutions(0).Height = 350codecs.Options.Save.SetResolutions(resolutions)'Meta file's tags will be saved.codecs.Options.Save.Tags = Truecodecs.Options.Save.UseImageDitheringMethod = Truecodecs.Save(image, Path.Combine(LEAD_VARS.ImagesDir, "allocate_image.tif"), RasterImageFormat.Tif, 8, 1, image.PageCount, 1, CodecsSavePageMode.Overwrite)' Clean upimage.Dispose()Marshal.FreeHGlobal(data)codecs.Dispose()End SubPublic NotInheritable Class LEAD_VARSPublic Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images"End Class
c#[Silverlight C# Example]using Leadtools;using Leadtools.Codecs;using Leadtools.Examples;using Leadtools.ImageProcessing;public void AllocateImageExample(Stream inStreamCmp, Stream outStreamTif){RasterCodecs codecs = new RasterCodecs();//Setting the loading options.//allow LEADTOOLS to allocate the image datacodecs.Options.Load.AllocateImage = true;//force a palletized image to be dithered to the LEAD fixed palette.codecs.Options.Load.FixedPalette = true;//we know the format of the filecodecs.Options.Load.Format = RasterImageFormat.Cmp;//disable loading metadata markers if present in the file, false to ignore them.codecs.Options.Load.Markers = false;codecs.Options.Load.NoInterlace = false;codecs.Options.Load.Passes = 0;//ignore the view perspective stored in the file.codecs.Options.Load.Rotated = false;//set negative pixel values to 0.codecs.Options.Load.Signed = false;codecs.Options.Load.InitAlpha = true;codecs.Options.Load.StoreDataInImage = true;//load super-compressed in memorycodecs.Options.Load.XResolution = 350;codecs.Options.Load.YResolution = 350;//allow loading corrupted imagescodecs.Options.Load.LoadCorrupted = true;RasterImage image = codecs.Load(inStreamCmp);//Meta file's comments will be saved.codecs.Options.Save.Comments = true;codecs.Options.Save.FixedPalette = true;codecs.Options.Save.GeoKeys = false;//Tiff file output will be gray.codecs.Options.Save.GrayOutput = true;//Meta file's markers will be saved.codecs.Options.Save.Markers = true;codecs.Options.Save.MotorolaOrder = false;codecs.Options.Save.OptimizedPalette = true;codecs.Options.Save.Password = "LEADTOOLS";LeadSize[] resolutions = new LeadSize[1];resolutions[0].Width = 350;resolutions[0].Height = 350;codecs.Options.Save.SetResolutions(resolutions);//Meta file's tags will be saved.codecs.Options.Save.Tags = true;codecs.Options.Save.UseImageDitheringMethod = true;codecs.Save(image, outStreamTif, RasterImageFormat.Tif, 8, 1, image.PageCount, 1, CodecsSavePageMode.Overwrite);// Clean upimage.Dispose();}vb[Silverlight VB Example]Imports LeadtoolsImports Leadtools.CodecsImports Leadtools.ImageProcessingPublic Sub AllocateImageExample(ByVal inStreamCmp As Stream, ByVal outStreamTif As Stream)Dim codecs As RasterCodecs = New RasterCodecs()'Setting the loading options.'allow LEADTOOLS to allocate the image datacodecs.Options.Load.AllocateImage = True'force a palletized image to be dithered to the LEAD fixed palette.codecs.Options.Load.FixedPalette = True'we know the format of the filecodecs.Options.Load.Format = RasterImageFormat.Cmp'disable loading metadata markers if present in the file, false to ignore them.codecs.Options.Load.Markers = Falsecodecs.Options.Load.NoInterlace = Falsecodecs.Options.Load.Passes = 0'ignore the view perspective stored in the file.codecs.Options.Load.Rotated = False'set negative pixel values to 0.codecs.Options.Load.Signed = Falsecodecs.Options.Load.InitAlpha = Truecodecs.Options.Load.StoreDataInImage = True'load super-compressed in memorycodecs.Options.Load.XResolution = 350codecs.Options.Load.YResolution = 350'allow loading corrupted imagescodecs.Options.Load.LoadCorrupted = TrueDim image As RasterImage = codecs.Load(inStreamCmp)'Meta file's comments will be saved.codecs.Options.Save.Comments = Truecodecs.Options.Save.FixedPalette = Truecodecs.Options.Save.GeoKeys = False'Tiff file output will be gray.codecs.Options.Save.GrayOutput = True'Meta file's markers will be saved.codecs.Options.Save.Markers = Truecodecs.Options.Save.MotorolaOrder = Falsecodecs.Options.Save.OptimizedPalette = Truecodecs.Options.Save.Password = "LEADTOOLS"Dim resolutions As LeadSize() = New LeadSize(0) {}resolutions(0).Width = 350resolutions(0).Height = 350codecs.Options.Save.SetResolutions(resolutions)'Meta file's tags will be saved.codecs.Options.Save.Tags = Truecodecs.Options.Save.UseImageDitheringMethod = Truecodecs.Save(image, outStreamTif, RasterImageFormat.Tif, 8, 1, image.PageCount, 1, CodecsSavePageMode.Overwrite)' Clean upimage.Dispose()End Sub
Help Collections
Raster .NET | C API | C++ Class Library | HTML5 JavaScript
Document .NET | C API | C++ Class Library | HTML5 JavaScript
Medical .NET | C API | C++ Class Library | HTML5 JavaScript
Medical Web Viewer .NET
Multimedia
Direct Show .NET | C API | Filters
Media Foundation .NET | C API | Transforms
Supported Platforms
.NET, Java, Android, and iOS/macOS Assemblies
Imaging, Medical, and Document
C API/C++ Class Libraries
Imaging, Medical, and Document
HTML5 JavaScript Libraries
Imaging, Medical, and Document
