0

I am using QTJambi and I need to convert BufferedImage into QPixmap.

kahonmlg
  • 3,839
  • 3
  • 17
  • 21

1 Answers1

0

I have found a solution:

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;
}
kahonmlg
  • 3,839
  • 3
  • 17
  • 21