首页 > 解决方案 > how do I load a pure blackwhite image as qimage?

问题描述

QImage qimg;
qimg.load('blackWhite.jpg')

This method changes pixels. I'm getting pixels like(1,1,1) or (3,3,3). But I expected only (0,0,0) and (255, 255, 255). I have also tried the following method:

QImage image(bin.data, bin.cols, bin.rows, 
                 static_cast<int>(bin.step),
                 QImage::Format_Mono);

Here bin is a Mat image(binary).This method is showing an image with half full black and half full white image.

Simply, I just want to load a binary image with QImage as a binary image with no change of any pixels.

标签: c++qtimage-processing

解决方案


You are loading a jpeg image, that format is a lossy compression format, meaning the pixels will be approximated but not necessary equal to the originals. So if you are in need to load the image from file, you should use a format like png, bmp, etc. (Any lossless format will do)


推荐阅读