Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/147.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 减小QPixmap的文件大小_C++_Qt_Qpixmap_Qbytearray - Fatal编程技术网

C++ 减小QPixmap的文件大小

C++ 减小QPixmap的文件大小,c++,qt,qpixmap,qbytearray,C++,Qt,Qpixmap,Qbytearray,当我使用scaledToHeight调整QPixmap的大小,然后将其转换为QByteArray时,此ByteArray的大小正好是未缩放QPixmap的ByteArray的大小。是否有可能缩小像素大小和文件大小的QPixmap 致以最诚挚的问候这是一个概念证明,它表明你所做的肯定是可能的。也许你能看出你在做什么不同 #include <QtGui> int main(int argc, char **argv) { QApplication app(argc, argv);

当我使用scaledToHeight调整QPixmap的大小,然后将其转换为QByteArray时,此ByteArray的大小正好是未缩放QPixmap的ByteArray的大小。是否有可能缩小像素大小和文件大小的QPixmap


致以最诚挚的问候

这是一个概念证明,它表明你所做的肯定是可能的。也许你能看出你在做什么不同

#include <QtGui>

int main(int argc, char **argv) {
  QApplication app(argc, argv);

  QPixmap pixmap("/path/to/image.jpg");
  QByteArray bytes1;
  QBuffer buffer1(&bytes1);
  buffer1.open(QIODevice::WriteOnly);
  pixmap.save(&buffer1, "png");
  qDebug() << bytes1.size();

  pixmap = pixmap.scaledToHeight(100);
  QByteArray bytes2;
  QBuffer buffer2(&bytes2);
  buffer2.open(QIODevice::WriteOnly);
  pixmap.save(&buffer2, "png");
  qDebug() << bytes2.size();

  return app.exec();
}
#包括
int main(int argc,字符**argv){
QApplication应用程序(argc、argv);
QPixmap pixmap(“/path/to/image.jpg”);
QByteArray字节1;
QBuffer-buffer1(&bytes1);
buffer1.open(QIODevice::WriteOnly);
pixmap.save(&buffer1,“png”);

qDebug()你能发布一些代码吗?我已经多次缩放了
QPixmap
,得到的字节数组肯定更小。