ImageGear Professional DLL for Windows
Raster Data

ImageGear allows storage of raster entities with vector data. Some vector formats, such as CGM, allow embedding raster data in the vector image. Other formats, such as DWG and DXF, allow adding a reference to a raster image. SVG format allows both file reference and embedded raster data.

Use IG_vect_drwng_create_entity function to create a raster entity. Use IG_vect_raster_init function to initialize dimensions of the raster and allocate pixel data. Alternatively, you can initialize raster data from a HIGEAR image, using IG_vect_raster_init_from_HIGEAR.

Use IG_vect_raster_get_lefttop, IG_vect_raster_get_righttop, IG_vect_raster_get_leftbottom and IG_vect_raster_get_rightbottom functions to access world coordinates of the raster entity corners. The image can be stretched or skewed according to these coordinates.

The following example creates a new raster entity and adds it to a drawing:

 
Copy Code
HIG_VECT_DRWNG hDrwng;
HIG_ENTITY hRaster;
HIG_VECT_VIEW hView;
HIG_VECT_ENTYTY hContent;
HIG_VECT_ENTYTYCONT hEntityCont;
IGVectPoint3D* lpLeftTop;
IGVectPoint3D* lpLeftBottom;
IGVectPoint3D* lpRightTop;
IGVectPoint3D* lpRightBottom;
// Create vector data and configure views, or load a vector image
...
// Create raster entity
IG_vect_drwng_create_entity(hDrwng, IG_VECT_ENT_RASTER, "", & hRaster);
IG_vect_raster_init(hRaster, imageWidth, imageHeight);
// Set world coordinates for the raster entity
IG_vect_raster_get_lefttop(hRaster, & lpLeftTop);
IG_vect_raster_get_righttop(hRaster, & lpRightTop);
IG_vect_raster_get_leftbottom(hRaster, & lpLeftBottom);
IG_vect_raster_get_rightbottom(hRaster, & lpRightBottom);
lpLeftTop->m_x = 0;
lpLeftTop->m_y = 0;
lpLeftTop->m_z = 0;
lpRightTop->m_x = 100;
lpRightTop->m_y = 0;
lpRightTop->m_z = 0;
lpLeftBottom->m_x = 0;
lpLeftBottom->m_y = 100;
lpLeftBottom->m_z = 0;
lpRightBottom->m_x = 100;
lpRightBottom->m_y = 100;
lpRightBottom->m_z = 0;

The following example initializes raster data from a HIGEAR handle:

 
Copy Code
HIG_VECT_DRWNG hDrwng;
HIG_ENTITY hRaster;
HIG_VECT_VIEW hView;
HIG_VECT_ENTYTY hContent;
HIG_VECT_ENTYTYCONT hEntityCont;
// Create vector data and configure views, or load a vector image
...
// Create raster entity
IG_vect_drwng_create_entity(hDrwng, IG_VECT_ENT_RASTER, "", & hRaster);
// Initialize raster entity from a HIGEAR handle
IG_vect_raster_init_from_HIGEAR(hRaster, hIGear);
// Set world coordinates for the image
...
// Add entity to the view to make it visible
IG_vect_drwng_get_view(hDrwng, 0, &hView);
IG_vect_view_get_content(hView, &hContent);
IG_vect_block_get_entitycont(hContent, &hEntityCont);
IG_vect_entcont_add_entity(hEntityCont, hRaster);

Use IG_vect_raster_save_to_HIGEAR to save raster data to a new HIGEAR image.

Raster data is stored in 32 bpp RGBA format, and can be accessed as an array of IGVectColor structures. Use IG_vect_raster_get_data function to obtain the pointer to the raster data. Raster data does not have padding bytes at the end of raster, so it can be accessed as two-dimensional array of IGVectColor with size equal to width * height, where width and height are raster image dimensions.

If vector file format allows embedding raster data into an image (to CGM or SVG formats), saving raster data to a file, together with the rest of the vector entities, does not require extra steps.

In order to save raster data as a reference (to DWG, DXF or SVG format), save raster data to a separate image file, and add file reference to the raster entity, using IG_vect_raster_set_filename function.

The following example demonstrates saving raster data to DXF format.

 
Copy Code
HIGEAR hVectorIGear; // Vector image
HIGEAR hIGear; // Raster image handle to export raster data to 
HIG_ENTITY hRaster; // Raster entity within hVectorIGear
CHAR RasterFileName[256];
// Create or load a vector image
...
// Save raster entity as a separate raster file
IG_vect_raster_save_to_HIGEAR(hRaster, &hIGear);
IG_save_file(hIGear, RasterFileName, IG_SAVE_JPG);
IG_vect_raster_set_filename(hRaster, RasterFileName);
// Save vector image
IG_save_file(hVectorIGear, IG_FORMAT_DXF);

 

 


©2014. Accusoft Corporation. All Rights Reserved.

Send Feedback