将指定位置的图像合并到另一个图像上并将其另存为新图像?

发布于 2024-08-29 16:13:33 字数 138 浏览 5 评论 0原文

保存通过将一个图像合并到另一个图像上生成的图像吗?

我首先有一个图像,我想在给定的指定位置在此图像上插入一些文本....我得到了正确的..bt 新任务是将最后生成的图像放置在给定位置的另一个图像模板上将其另存为我的工作目录中的新 jpg 图像..

save an image that is generated by merging an image over another image?

i have an image first and i want to insert some text over this image in a specified position given....that i got coorectly..bt the new task is to place this last generated image over another image template in the location given and save it as a new jpg image in my work directory..

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

沫离伤花 2024-09-05 16:13:33

以下是如何使用 java2D 使用图像叠加的示例。由于您还使用 [jquery] 标记,我不确定您是否想使用 jquery 还是 java 来执行此操作。

我的意思是第二个片段,已修复并运行

import java.awt.AlphaComposite;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.net.URL;

import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;

public class WaterMark {
    public static void main(String[] args) throws IOException {
        URL url = new URL("http://sstatic.net/so/img/logo.png");
        BufferedImage im = ImageIO.read(url);
        URL url2 = new URL("http://sstatic.net/sf/img/logo.png");
        BufferedImage im2 = ImageIO.read(url2);
        Graphics2D g = im.createGraphics();
        g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.4f));
        g.drawImage(im2, (im.getWidth()-im2.getWidth())/2, (im.getHeight()-im2.getHeight())/2, null);
        g.dispose();

        display(im);
        ImageIO.write(im, "jpeg", new File("sample_output.jpeg"));
    }

    public static void display(BufferedImage image) {
        JFrame f = new JFrame("WaterMark");
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.getContentPane().add(new JLabel(new ImageIcon(image)));
        f.pack();
        f.setLocationRelativeTo(null);
        f.setVisible(true);
    }
}

Here is an example of how to use Image Overlay using java2D. Since you tagged also with [jquery] I'm not sure if you want to do this using jquery or java.

I meant the 2nd Snippet, repaired and runs

import java.awt.AlphaComposite;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.net.URL;

import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;

public class WaterMark {
    public static void main(String[] args) throws IOException {
        URL url = new URL("http://sstatic.net/so/img/logo.png");
        BufferedImage im = ImageIO.read(url);
        URL url2 = new URL("http://sstatic.net/sf/img/logo.png");
        BufferedImage im2 = ImageIO.read(url2);
        Graphics2D g = im.createGraphics();
        g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.4f));
        g.drawImage(im2, (im.getWidth()-im2.getWidth())/2, (im.getHeight()-im2.getHeight())/2, null);
        g.dispose();

        display(im);
        ImageIO.write(im, "jpeg", new File("sample_output.jpeg"));
    }

    public static void display(BufferedImage image) {
        JFrame f = new JFrame("WaterMark");
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.getContentPane().add(new JLabel(new ImageIcon(image)));
        f.pack();
        f.setLocationRelativeTo(null);
        f.setVisible(true);
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文