public RasterImage(
RasterMemoryFlags flags,
int width,
int height,
int bitsPerPixel,
RasterByteOrder order,
RasterViewPerspective viewPerspective,
RasterColor[] palette,
IntPtr userData,
long userDataLength
)
- (nullable instancetype)initWithUserData:(nullable unsigned char *)data
userDataLength:(unsigned long)dataLength
flags:(LTRasterMemoryFlags)flags
width:(NSInteger)width
height:(NSInteger)height
bitsPerPixel:(NSInteger)bitsPerPixel
order:(LTRasterByteOrder)order
viewPerspective:(LTRasterViewPerspective)viewPerspective
palette:(nullable NSArray<LTRasterColor *> *)palette
error:(NSError **)error
public:
RasterImage(
RasterMemoryFlags flags,
int width,
int height,
int bitsPerPixel,
RasterByteOrder order,
RasterViewPerspective viewPerspective,
array<RasterColor>^ palette,
IntPtr userData,
int64 userDataLength
)
__init__(self,flags,width,height,bitsPerPixel,order,viewPerspective,palette,userData,userDataLength) # Overloaded constructor
flags
A combination of the RasterMemoryFlags enumeration members indicating the type of memory to allocate for the image data.
width
Width of the image in pixels.
height
Height of the image in pixels.
bitsPerPixel
The number of bits per pixel.
Valid values are 0, 1, 2, 3, 4, 5, 6, 7, 8, 12, 16, 24, 32, 48, and 64.
Use 0 to create an 8-bit grayscale image. In that case, the method ignores the order and the palette parameters.
order
Color order for 16-bit, 24-bit, 32-bit, 48-bit and 64-bit images.
If the resultant image is less than 16 bits per pixel, this will have no effect since palletized images have no order.
viewPerspective
Specifies where the beginning of the image is stored.
Most file formats start in the lower left corner while some formats start in the upper left corner.
palette
The palette that the image will use. You can specify your own palette, or use null for LEAD's fixed palette. The palette member is used only when bitsPerPixel is less than or equal to 8.
userData
Unmanaged data pointer that will contain the image data when flags is RasterMemoryFlags.User.
This data must be aligned on a four byte boundary. If userData is IntPtr.Zero, the data pointer must be passed later, by calling the SetUserData method, before the image can be used.
userDataLength
Length in bytes of the data passed to userData. Only when used when userData is not IntPtr.Zero and flags is RasterMemoryFlags.User.
Support for 12 and 16-bit grayscale images is only available in the Document/Medical Imaging editions.
There is some speed penalty (loss) for accessing RasterMemoryFlags.Tiled images. Therefore, it is not recommended for use with all images.
The RasterMemoryFlags.Tiled images are not used by default. LEADTOOLS will create them only if it failed to create RasterMemoryFlags.Conventional images and RasterMemoryFlags.NoTiled was not specified.
The following lists the distinct types of bitmaps:
If you pass RasterMemoryFlags.User, you are responsible for freeing the image data.
Creating an image of type RasterMemoryFlags.User does not allocate memory for the image data. Instead, the data pointer userData is used. When you create a RasterImage with user data, the IsConventionalMemory and IsMirrored flags will both be set to true. Some image processing commands, such as RotateCommand, need to re-allocate the image data. If you create an image with RasterMemoryFlags.User, and pass it to these methods, the data will be re-allocated internally by LEADTOOLS and the image object will stop using the data in userData.
For more information, refer to Accounting for View Perspective.
For more information, refer to Grayscale Images.
using Leadtools;
using Leadtools.Codecs;
using Leadtools.ImageProcessing;
using Leadtools.ImageProcessing.Core;
using Leadtools.ImageProcessing.Color;
using Leadtools.Dicom;
using Leadtools.Drawing;
using Leadtools.Controls;
using Leadtools.Svg;
public void RasterImageExample()
{
RasterCodecs codecs = new RasterCodecs();
string srcFileName = Path.Combine(LEAD_VARS.ImagesDir, "Image1.cmp");
string destFileName1 = Path.Combine(LEAD_VARS.ImagesDir, "Image1_RasterImage1.bmp");
string destFileName2 = Path.Combine(LEAD_VARS.ImagesDir, "Image1_RasterImage2.bmp");
// Load the image
RasterImage srcImage = codecs.Load(srcFileName);
// Creates a new image in memory with same dimensions as the source image
RasterImage destImage = new RasterImage(
RasterMemoryFlags.Conventional,
srcImage.Width,
srcImage.Height,
srcImage.BitsPerPixel,
srcImage.Order,
srcImage.ViewPerspective,
srcImage.GetPalette(),
IntPtr.Zero,
0);
// Copy the data from the source image to the destination image
srcImage.Access();
destImage.Access();
byte[] buffer = new byte[srcImage.BytesPerLine];
for (int y = 0; y < srcImage.Height; y++)
{
srcImage.GetRow(y, buffer, 0, buffer.Length);
destImage.SetRow(y, buffer, 0, buffer.Length);
}
destImage.Release();
srcImage.Release();
// We do not need the source image anymore
srcImage.Dispose();
// save the destination image
codecs.Save(destImage, destFileName1, RasterImageFormat.Bmp, 24);
// perform image processing on the image
FlipCommand flipCmd = new FlipCommand();
flipCmd.Horizontal = false;
flipCmd.Run(destImage);
// save it
codecs.Save(destImage, destFileName2, RasterImageFormat.Bmp, 24);
// Clean up
destImage.Dispose();
codecs.Dispose();
}
static class LEAD_VARS
{
public const string ImagesDir = @"C:\LEADTOOLS23\Resources\Images";
}
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import org.junit.*;
import org.junit.runner.JUnitCore;
import org.junit.runner.Result;
import org.junit.runner.notification.Failure;
import static org.junit.Assert.*;
import leadtools.*;
import leadtools.codecs.*;
import leadtools.imageprocessing.core.*;
import leadtools.svg.*;
import leadtools.imageprocessing.CloneCommand;
import leadtools.imageprocessing.FillCommand;
import leadtools.imageprocessing.FlipCommand;
import leadtools.imageprocessing.GrayscaleCommand;
import leadtools.imageprocessing.color.InvertCommand;
import leadtools.imageprocessing.color.PosterizeCommand;
public void rasterImageExample() {
final String LEAD_VARS_IMAGES_DIR = "C:\\LEADTOOLS23\\Resources\\Images";
RasterCodecs codecs = new RasterCodecs();
String srcFileName = combine(LEAD_VARS_IMAGES_DIR, "Image1.cmp");
String destFileName1 = combine(LEAD_VARS_IMAGES_DIR, "Image1_RasterImage1.bmp");
String destFileName2 = combine(LEAD_VARS_IMAGES_DIR, "Image1_RasterImage2.bmp");
// Load the image
RasterImage srcImage = codecs.load(srcFileName);
// Creates a new image in memory with same dimensions as the source image
byte[] userData = new byte[0];
RasterImage destImage = new RasterImage(RasterMemoryFlags.CONVENTIONAL.getValue(), srcImage.getWidth(),
srcImage.getHeight(),
srcImage.getBitsPerPixel(), srcImage.getOrder(), srcImage.getViewPerspective(), srcImage.getPalette(),
userData, 0);
// Copy the data from the source image to the destination image
srcImage.access();
destImage.access();
byte[] buffer = new byte[srcImage.getBytesPerLine()];
for (int y = 0; y < srcImage.getHeight(); y++) {
srcImage.getRow(y, buffer, 0, buffer.length);
destImage.setRow(y, buffer, 0, buffer.length);
}
destImage.release();
srcImage.release();
// We do not need the source image anymore
srcImage.dispose();
// Save the destination image
codecs.save(destImage, destFileName1, RasterImageFormat.BMP, 24);
// Perform image processing on the image
FlipCommand flipCmd = new FlipCommand();
flipCmd.setHorizontal(false);
flipCmd.run(destImage);
// Save it
codecs.save(destImage, destFileName2, RasterImageFormat.BMP, 24);
// Clean up
destImage.dispose();
codecs.dispose();
assertTrue("file unsuccessfully saved to " + destFileName2, (new File(destFileName2)).exists());
System.out.printf("File saved successfully to %s%n", destFileName2);
}
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