Operator Reference

image_to_memory_blockT_image_to_memory_blockImageToMemoryBlockImageToMemoryBlockimage_to_memory_block (Operator)

image_to_memory_blockT_image_to_memory_blockImageToMemoryBlockImageToMemoryBlockimage_to_memory_block — Write an image to a memory block in various graphic formats.

Signature

image_to_memory_block(Image : : Format, FillColor : MemoryBlockHandle)

Herror T_image_to_memory_block(const Hobject Image, const Htuple Format, const Htuple FillColor, Htuple* MemoryBlockHandle)

void ImageToMemoryBlock(const HObject& Image, const HTuple& Format, const HTuple& FillColor, HTuple* MemoryBlockHandle)

HMemoryBlock HImage::ImageToMemoryBlock(const HString& Format, const HTuple& FillColor) const

HMemoryBlock HImage::ImageToMemoryBlock(const HString& Format, Hlong FillColor) const

HMemoryBlock HImage::ImageToMemoryBlock(const char* Format, Hlong FillColor) const

HMemoryBlock HImage::ImageToMemoryBlock(const wchar_t* Format, Hlong FillColor) const   ( Windows only)

static void HOperatorSet.ImageToMemoryBlock(HObject image, HTuple format, HTuple fillColor, out HTuple memoryBlockHandle)

HMemoryBlock HImage.ImageToMemoryBlock(string format, HTuple fillColor)

HMemoryBlock HImage.ImageToMemoryBlock(string format, int fillColor)

def image_to_memory_block(image: HObject, format: str, fill_color: Union[int, float]) -> HHandle

Description

The operator image_to_memory_blockimage_to_memory_blockImageToMemoryBlockImageToMemoryBlockimage_to_memory_block saves the input image ImageImageImageimageimage to the memory block MemoryBlockHandleMemoryBlockHandleMemoryBlockHandlememoryBlockHandlememory_block_handle in the format FormatFormatFormatformatformat. If the domain (region) cannot be saved in the specified FormatFormatFormatformatformat (this is the case for 'jpeg'), all pixels outside the region receive the color defined by FillColorFillColorFillColorfillColorfill_color. For gray value images a value between 0 (black) and 255 (white) must be passed. For RGB color images the RGB values can be passed directly as a hexadecimal value: e.g., 0xffff00 for a yellow background (red=255, green=255, blue=0).

The following formats can be set in FormatFormatFormatformatformat:

'jpeg': JPEG format (lossy compression), file extension *.jpg

This format can only store images with one channel (gray value image) or three channels (RGB image).

Only images with the pixel type byte are supported for this file format.

Together with the format string the quality value determining the compression rate can be provided. Large values (maximum 100) create a large memory block with high image quality. Small values significantly decrease the image quality and the size of the memory block.

Possible values: 'jpeg'"jpeg""jpeg""jpeg""jpeg", 'jpeg 30'"jpeg 30""jpeg 30""jpeg 30""jpeg 30", 'jpeg 60'"jpeg 60""jpeg 60""jpeg 60""jpeg 60".

Attention: Images stored for being processed later should not be stored in this format due to the loss of information during compression.

'png': PNG format (lossless compression), file extension *.png

This format can only store images with one channel (gray value image) or three channels (RGB image). The maximal supported image size (width x height) for PNG is , also in HALCON XL.

Images of type byte and uint2 can be stored in PNG format.

Together with the format string, a compression level between 0 and 9 can be specified, where 0 corresponds to no compression and 9 to the best possible compression. Alternatively, the compression can be selected by using string constants.

Possible values: 'png'"png""png""png""png", 'png 7'"png 7""png 7""png 7""png 7", 'png none'"png none""png none""png none""png none", 'png best'"png best""png best""png best""png best", 'png fastest'"png fastest""png fastest""png fastest""png fastest".

If an image with a reduced domain is written, the region is stored as the alpha channel, where the points within the domain are stored as the maximum gray value of the image type and the points outside the domain are stored as the gray value 0. If an image with a full domain is written, no alpha channel is stored.

Execution Information

  • Multithreading type: reentrant (runs in parallel with non-exclusive operators).
  • Multithreading scope: global (may be called from any thread).
  • Processed without parallelization.

This operator returns a handle. Note that the state of an instance of this handle type may be changed by specific operators even though the handle is used as an input parameter by those operators.

Parameters

ImageImageImageimageimage (input_object)  (multichannel-)image objectHImageHObjectHObjectHobject (byte / direction / cyclic / int1 / complex / int2 / uint2 / vector_field / int4 / int8 / real)

Input image.

FormatFormatFormatformatformat (input_control)  string HTuplestrHTupleHtuple (string) (string) (HString) (char*)

Graphic format.

Default: 'jpeg' "jpeg" "jpeg" "jpeg" "jpeg"

Suggested values: 'jpeg'"jpeg""jpeg""jpeg""jpeg", 'png'"png""png""png""png"

FillColorFillColorFillColorfillColorfill_color (input_control)  number HTupleUnion[int, float]HTupleHtuple (integer / real) (int / long / double) (Hlong / double) (Hlong / double)

Gray value for pixels not belonging to the image domain (region).

Default: 0

Suggested values: -1, 0, 255, 65280, 16711680

MemoryBlockHandleMemoryBlockHandleMemoryBlockHandlememoryBlockHandlememory_block_handle (output_control)  memory_block HMemoryBlock, HTupleHHandleHTupleHtuple (handle) (IntPtr) (HHandle) (handle)

Memory block handle.

Result

If the parameter values are correct the operator image_to_memory_blockimage_to_memory_blockImageToMemoryBlockImageToMemoryBlockimage_to_memory_block returns the value 2 ( H_MSG_TRUE) . Otherwise an exception is raised.

Possible Predecessors

read_imageread_imageReadImageReadImageread_image

Possible Successors

get_memory_block_ptrget_memory_block_ptrGetMemoryBlockPtrGetMemoryBlockPtrget_memory_block_ptr, write_memory_blockwrite_memory_blockWriteMemoryBlockWriteMemoryBlockwrite_memory_block, serialize_tupleserialize_tupleSerializeTupleSerializeTupleserialize_tuple

See also

memory_block_to_imagememory_block_to_imageMemoryBlockToImageMemoryBlockToImagememory_block_to_image

Module

Foundation