0

我正在使用 QTJambi,我需要将BufferedImage转换为QPixmap

4

1 回答 1

0

我找到了一个解决方案:

public QPixmap convertBufferedImageToQPixmap(BufferedImage img){
    QPixmap result = new QPixmap(new QSize(img.getWidth(),img.getHeight()));
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    try {
        boolean foundWriter = ImageIO.write(img, "jpg", baos);
        result.loadFromData(baos.toByteArray());
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return result;
}
于 2017-06-24T19:40:44.933 回答