Raster Image Questions

  1. FAQ

How to open a dwg file and combine it with the image file on the drawing being drawn? I want to combine .dwg and .tif files on the screen and draw them like a combine .png file. (I don't want to save it as a file, but I want to draw it on screen).

Simplest way is to attach image background to a .dwg file. Image background can be stretched to fill entire viewport background, or you can use image tiling. If you need more exact control for raster positioning, you can attach raster image entity to a .dwg file, but you will need erase it before file saving if you don't like to save raster inside drawing. Alternatively, you can create addition OdGsView and attach transient raster image entity to it. In this case you will be able to control positioning of your raster image.

Does ODA have the ability to vectorize raster images?

No, we haven't functionality that allows conversion of raster scan into CAD drawing (lines, arcs, ...)

How to read a pdf and convert it to an image (bmp, jpeg, png) and then save it?

Example of converting a pdf - document page into an image you can look in function getThumbnail in PdfiumWrapperImpl.cpp.

Example of saving OdGiRasterImage - object in a file you can look in the function createRasterImage in DbDeviceDriver.cpp.

How to generate a .png file with a transparent background?

To generate a .png file with a transparent background, use the GLES2 device as it is the only device that supports transparency. For details, see the SimpleExportToRaster example.

Why is the raster image that is exported from a drawing blank?

There are three possible reasons:

  • The raster file cannot be located. Set a break point to your OdDbHostAppServices inheritor findFile() method and see if the file can be found.
  • The raster image format is not supported by the RasterServices module. Check all the supported raster formats in the OdRxRasterServices::ImageType enumeration.
  • Missing RasterServices module, which is responsible for handling raster files.
    • If you are using a static libraries configuration, you must link the RxRasterServices and FreeImage libraries. Better to link the RasterProcessor library also to enable raster format conversion. Raster services must be registered into the static modules map:
      #if !defined(_TOOLKIT_IN_DLL_) || defined(__MWERKS__)
      ODRX_DECLARE_STATIC_MODULE_ENTRY_POINT(ExRasterModule);
      ODRX_DECLARE_STATIC_MODULE_ENTRY_POINT(OdRasterProcessingServicesImpl);
      ODRX_BEGIN_STATIC_MODULE_MAP()
      ODRX_DEFINE_STATIC_APPLICATION(RX_RASTER_SERVICES_APPNAME, ExRasterModule)
      ODRX_DEFINE_STATIC_APPLICATION(OdRasterProcessorModuleName,  OdRasterProcessingServicesImpl)
      ODRX_END_STATIC_MODULE_MAP()
      #endif // !defined(_TOOLKIT_IN_DLL_) || defined(__MWERKS__)
    • If you are using a dynamic libraries configuration, all described .tx modules must be simply available in your application directory.

How to embed a raster image in a drawing?

It is possible to create an OLE object with an embedded raster image. For details, see the Drawing/Examples/ExCommands/ExInsertRaster.cpp file, which implements a command for creating an OLE entity.

How to set the resolution of a rendered bitmap image?

You can set the resolution of a bitmap rendering device using OdGsDevice::onSize Method(). For more information, please refer to the OdVectorizeEx sample application (Drawing/Examples/OdVectorizeEx/OdVectorizeEx.cpp).

How to specify the file format of a raster image when exporting a drawing?

You can specify the raster image format using the Type parameter of the RxRasterServices::saveRasterImage() method. Or, if Type is not specified, the file extension is used.

For more information, please refer to the RasterExport sample application (Kernel/Exports/RasterExport/Source/RasterExportCmd.cpp).

Which raster formats are supported by ODA framework for import/export?

All the supported raster formats are listed in the OdRxRasterServices::ImageType enumeration.

How to set the JPEG quality when exporting a .dwg file to a raster image?

You can control JPEG compression quality in the OdRxRasterServices::convertRasterImage() method:

const OdUInt32 flagsChain[3] = { OdRxRasterServices::kJpegQuality, 85, 0 };
if (pRasSvcs->convertRasterImage( pRaster, OdRxRasterServices::kJPEG, pStreamBuf, flagsChain))
{
...
}

Quality is set as a percentage:

  • < 20 : poor quality
  • 20 < 40 : average quality
  • 40 < 60 : normal quality
  • 60 < 80 : good quality (default)
  • >= 80 : best quality

How do I get the raster image file name loaded in a drawing?

To access the file name of a raster file loaded in a drawing, use the OdGiRasterImage::sourceFileName() method or OdDbRasterImageDef::sourceFileName() method depending on the database access level.

How to add a raster image to a drawing?

To learn how to add raster images to a drawing, please refer to the DbFiller::addImage() method in the OdWriteEx sample application (Drawing/Examples/OdWriteEx/DbFiller.cpp).

How to hide the border of a raster image added to a drawing?

To hide the border frame of added images, use one the following code fragments:

OdDbRasterVariablesPtr pRVars = OdDbRasterVariables::openRasterVariables(pDb->database(), OdDb::kForWrite);
pRVars->setImageFrame(OdDbRasterVariables::kImageFrameOff);

or

OdResBufPtr val = OdResBuf::createObject();
val->setRestype(OdResBuf::kRtInt16);
val->setInt16(0);
pDb->setSysVar(OD_T("IMAGEFRAME"), val);

How to set the position, height and width of a raster image added to a drawing?

You can set the position, image height, width using the OdDbRasterImage::setOrientation() method. For more information, please refer to the DbFiller::addImage() method in the OdWriteEx sample application (Drawing/Examples/OdWriteEx/DbFiller.cpp).