简体   繁体   English

如何将具有16位整数的图像转换为QPixmap

[英]How to convert an image with 16 bit integers into a QPixmap

I am working with software that has a proprietary image format. 我正在使用具有专有图像格式的软件。 I need to be able to display a modified version of these images in a QT GUI. 我需要能够在QT GUI中显示这些图像的修改后的版本。 There is a method (Image->getpixel(x,y)) that returns a 16 bit integer (16 bits per pixel). 有一种方法(Image-> getpixel(x,y))返回16位整数(每个像素16位)。 To be clear, the 16 bit number does not represent an RGB color format. 需要清楚的是,16位数字不代表RGB颜色格式。 It literally represents a measurement or dimension to that particular point (height map) on the part that is being photographed. 它从字面上表示到被拍摄零件上特定点(高度图)的尺寸或尺寸。 I need to take the range of dimensions (integers) in the image and apply a scale to be represented in colors. 我需要在图像中使用尺寸范围(整数),并应用比例尺以颜色表示。 Then, I need to use that information to build an image for a QPixmap that can be displayed in a Qlabel. 然后,我需要使用该信息来为可以在Qlabel中显示的QPixmap构建图像。 Here is the general gist... 这是一般要点...

QByteArray Arr;
unsigned int Temp;
for (int N = 0; N < Image->GetWidth(); N++) {
    for (int M = 0; M < Image->GetHeight(); M++) {
        Temp = Image.GetPixel(N,M);
        bytes[0] = (Temp >> 8) & 0xFF;
        bytes[1] = Temp & 0xFF;
        Arr.push_back(bytes[0]);
        Arr.push_back(bytes[1]);
    }
}

// Take the range of 16 bit integers.  Example (14,982 to 16,010)
// Apply a color scheme to the values
// Display the image
QPixmap Image2;
Image2.loadFromData(Arr);
ui->LabelPic->setPixmap(Image2);

Thoughts? 有什么想法吗?

This screenshot is an example of what I am trying to replicate. 此屏幕快照是我要复制的示例。 It is important to note that the coloration of the image is not inherent to the underlying data in the image. 重要的是要注意,图像的颜色不是图像中基础数据固有的。 It is the result of an application scaling the height values and applying a color scheme to the range of integers. 这是应用程序缩放高度值并将颜色方案应用于整数范围的结果。 在此处输入图片说明

The information on proprietary image format is limited so the below is guess or thought (as requested) according to explanation above: 专有图像格式的信息有限,因此根据上面的解释,以下是猜测或思考(根据要求):

QImage img(/*raw image data*/ (const uchar*) qbyteArr.data(),
   /*columns*/ width, /*height*/ rows,
   /*bytes per line*/ width * sizeof(uint16),
   /*format*/ QImage::Format_RGB16); // the format is likely matching the request

QPixpam pixmap(img);                 // if the pixmap is needed

I found pieces of the answer here. 我在这里找到了答案。

Algorithm to convert any positive integer to an RGB value 将任何正整数转换为RGB值的算法

As for the actual format, I chose to convert the 16 bit integer into a QImage::Format_RGB888 to create a heat map. 至于实际格式,我选择将16位整数转换为QImage :: Format_RGB888以创建热图。 This was accomplished by applying a scale to the range of integers and using the scale to plot different color equations. 这是通过对整数范围应用比例尺并使用该比例尺绘制不同的颜色方程式来实现的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM