【已解决】c++ qt bmp转jpg函数

本博文源于笔者正在写的代码,想要将bmp转成jpg,里面用到的库函数是QImage,大致函数的含义是将image进行rgb转换,最后保存成JPEG

函数书写

第一个参数是bmp图片路径比如d://a.bmp,第二个参数是要转换的jpg路径,比如d://b.jpg

bool convertBmpToJpg(const QString& bmpFilePath, const QString& jpgFilePath)
{
	QImage bmpImage(bmpFilePath);
	if (bmpImage.isNull()) {
		return false;
	}

	QImage jpgImage = bmpImage.convertToFormat(QImage::Format_RGB888);
	if (jpgImage.isNull()) {
		return false;
	}

	if (!jpgImage.save(jpgFilePath, "JPEG", 75)) {
		return false;
	}
	QFile::remove(bmpFilePath);
	return true;
}

用过直接调用即可,亲测可行,别忘记声明哦。

你可能感兴趣的:(QT,c++,qt,开发语言)