【问题标题】:Drawing buffered image on another? [duplicate]在另一个上绘制缓冲图像? [复制]
【发布时间】:2018-02-12 01:25:11
【问题描述】:

我正在尝试使用 java 将两个图像放在一起。所以我尝试在另一个缓冲图像上绘制一个缓冲图像,但它破坏了图像的颜色,最终图像有点绿色 这是我的代码:

  try
{
BufferedImage source = ImageIO.read(new File("marker.png"));
BufferedImage logo = ImageIO.read(new File("pic.png"));

Graphics2D g = (Graphics2D) source.getGraphics();
g.drawImage(logo, 20, 50, null);
File outputfile = new File("image.jpg");
ImageIO.write(source, "jpg", outputfile);
}
catch (Exception e)
{
e.printStackTrace();
}

【问题讨论】:

    标签: java image-processing bufferedimage


    【解决方案1】:

    jpg 在压缩过程中可能会弄乱您的数据 - 您可以尝试将 png 作为输出格式。

    为确保您拥有所需的所有颜色,我建议使用具有所需颜色深度的专用目标图像,而不是覆盖源图像。像这样:

    BufferedImage target = new BufferedImage(source.getWidth(), source.getHeight(), BufferedImage.TYPE_INT_ARGB);
    Graphics2D g = (Graphics2D) target.getGraphics();
    g.drawImage(source, 0, 0, null);
    g.drawImage(logo, 20, 50, null);
    File outputfile = new File("targetimage.png");
    ImageIO.write(target, "png", outputfile);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-12-19
      • 2012-06-15
      • 2014-02-26
      • 1970-01-01
      • 1970-01-01
      • 2012-04-20
      • 2015-02-08
      相关资源
      最近更新 更多