Please enable JavaScript to view this site.

IDS peak 2.8.0 / uEye+ firmware 3.33

Saving an image with a type specification in file extension

To save an image, you must pass the image itself as a parameter in the path to the output file. The function recognizes which image type it is based on the specified file extension. The following image types are possible:

File extension

Standard quality

JPG

75 %

PNG

100 %

BMP

always 100 %, no compression

The following call uses the default quality parameters. The higher the compression for PNG and JPG, the lower the quality. A BMP (bitmap) file is not compressed.

genericC++

std::string file = "c:/entwicklung/test.jpg";
peak::ipl::ImageWriter::Write(file, image);

Saving a special image type with quality specification

There are additional functions for all image types. You can also specify the quality for PNG and JPG. The file extension must match the image type, otherwise the function returns an error. Additionally, you can save an image as a RAW image.

genericC++

std::string file = "c:/entwicklung/test.bmp";
peak::ipl::ImageWriter::WriteAsBMP(file, image);

genericC++

std::string file = "c:/entwicklung/test.jpg";
 
// Default Quality
peak::ipl::ImageWriter::WriteAsJPG(file, image);
 
// Quality set to 50%
peak::ipl::ImageWriter::JPEGParameter jpgParams;
jpgParams.Quality = 50;
peak::ipl::ImageWriter::WriteAsJPG(file, image, jpgParams);

genericC++

std::string file = "c:/entwicklung/test.png";
 
// Default Quality
peak::ipl::ImageWriter::WriteAsPNG(file, image);
 
// Quality set to 50%
peak::ipl::ImageWriter::PNGParameter pngParams;
pngParams.Quality = 50;
peak::ipl::ImageWriter::WriteAsPNG(file, image, pngParams);

genericC++

std::string file = "c:/entwicklung/test";
peak::ipl::ImageWriter::WriteAsRAW(file, image);

Complete example: Image acquisition loop with image saving

Example: Saving an image and loading it afterwards

An image file can be loaded into a peak::ipl::Image. When specifying the pixel format, the peak::ipl::Image must match the image file exactly, otherwise the call will fail.

genericC++

try
{
  QImage qImage(m_imageWidth, m_imageHeight, QImage::Format_RGB32);
 
  // Get buffer from device's DataStream
  const auto buffer = m_dataStream->WaitForFinishedBuffer(5000);
 
  // Create IDS peak IPL image for debayering and convert it to BGRa8 format
  auto image = peak::BufferTo<peak::ipl::Image>(buffer).ConvertTo(
          peak::ipl::PixelFormatName::BGRa8, qImage.bits(), static_cast<size_t>(qImage.byteCount()));
 
  // Queue buffer so that it can be used again
  m_dataStream->QueueBuffer(buffer);
 
  // Save as BMP
  std::string file = "c:/entwicklung/test.bmp";
  peak::ipl::ImageWriter::Write(file, image);
 
  // Load from BMP file and create new image
  auto image2 = peak::ipl::ImageReader::Read(file, peak::ipl::PixelFormatName::BGRa8);
 
  // Copy into QImage
  memcpy(qImage.bits(), image2.Data(), image2.ByteCount());
}
catch (const std::exception& e)
{
  // ...
}

© 2024 IDS Imaging Development Systems GmbH