Windows平台OpenCV方法Jpg转Bmp
Jpg 转 Bmp 方法(jpg2Bmp),本示例中列出的彩色图像,即RGB888的方法。
mat2byte 函数参考以前博文。
bool ImgUtils::jpg2Mat(cv::Mat &matImage, std::vector<unsigned char> buff)
if (buff.empty()) {
return false;
if ((buff[0] == 0xFF && buff[1] == 0xD8))
matImage = cv::imdecode(buff, CV_LOAD_IMAGE_COLOR);
buff.insert(buff.begin(), 0xFF);
buff.insert(buff.begin() + 1, 0xD8);
matImage = cv::imdecode(buff, CV_LOAD_IMAGE_COLOR);
return true;
bool ImgUtils::jpg2Mat(cv::Mat &matImage, unsigned char *buff,int buffLen) {
std::vector<unsigned char> vector_buff;
for (int i = 0; i < buffLen; i++) {
vector_buff.push_back(buff[i]);
int ret = jpg2Mat(matImage,vector_buff);
return ret;
bool ImgUtils::jpg2Bmp(unsigned char *src, int srcLen, unsigned char *dst,int *w,int *h,int *bits) {
cv::Mat mat;