如何在 spring 控制器中创建 jwt 图像

发布于 2024-10-20 18:38:53 字数 1492 浏览 0 评论 0原文

嘿, 我有一个如下所示的弹簧控制器,用于创建某些图像。

public class ImageMapController extends AbstractController {


protected ModelAndView handleRequestInternal( HttpServletRequest request,
        HttpServletResponse response ) throws Exception
        {
            File file = new File("C:/Users/Rahul/Pictures/EmptyParkingLot.jpg");

            BufferedImage image= javax.imageio.ImageIO.read(file);
            int width = image.getWidth();
            int height = image.getHeight();
            BufferedImage buffer =
                new BufferedImage(width*2,
                                  height,
                                  BufferedImage.TYPE_INT_RGB);
            Graphics g=buffer.getGraphics();
            Graphics2D g2 = (Graphics2D)g;
            g2.setBackground(Color.white);
            g2.setColor(Color.red);
            g2.drawString("Item 1",0,0);

            g2.drawImage(image, 40, 40, null);
            g2.drawString("Item 2",width,0);
            g2.drawImage(image, 40 + width, 40, null);

            ServletOutputStream out1 = response.getOutputStream();
            JPEGImageEncoder encoder= JPEGCodec.createJPEGEncoder(out1);
            encoder.encode(buffer);

            return new ModelAndView("parkingimage");
        }

上面

的代码工作得很好,它在 parkingimage.jsp 中显示了我想要的图像。但与将其作为 jsp 刷新相反,我只想将其用作带有 标签的 jsp 中的图像,或者除了显示图像之外,如何将此 jsp 包含在另一个 jsp 中我有一些文本想要在显示图像的同一个 jsp 中显示。

任何帮助表示赞赏。提前致谢。 问候, 血清素追逐

Hey,
I have a spring controller as shown below which is there to create certain image.

public class ImageMapController extends AbstractController {


protected ModelAndView handleRequestInternal( HttpServletRequest request,
        HttpServletResponse response ) throws Exception
        {
            File file = new File("C:/Users/Rahul/Pictures/EmptyParkingLot.jpg");

            BufferedImage image= javax.imageio.ImageIO.read(file);
            int width = image.getWidth();
            int height = image.getHeight();
            BufferedImage buffer =
                new BufferedImage(width*2,
                                  height,
                                  BufferedImage.TYPE_INT_RGB);
            Graphics g=buffer.getGraphics();
            Graphics2D g2 = (Graphics2D)g;
            g2.setBackground(Color.white);
            g2.setColor(Color.red);
            g2.drawString("Item 1",0,0);

            g2.drawImage(image, 40, 40, null);
            g2.drawString("Item 2",width,0);
            g2.drawImage(image, 40 + width, 40, null);

            ServletOutputStream out1 = response.getOutputStream();
            JPEGImageEncoder encoder= JPEGCodec.createJPEGEncoder(out1);
            encoder.encode(buffer);

            return new ModelAndView("parkingimage");
        }

}

The above code works really fine and it displays the image I want in parkingimage.jsp. But as opposed to flushing it out as jsp I just want to use it as an image within my jsp with <img>tag OR how do I include this jsp within another jsp as apart from displaying the image I have some text that I want to display in the same jsp I'm displaying the image.

Any help is appreciated. Thanks in advance.
Regards,
Serotonin Chase

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

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

发布评论

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

评论(1

陌若浮生 2024-10-27 18:38:53

您需要创建另一个控制器来生成页面,并且该页面中的 应指向生成图像的控制器(如果需要,这些 URL 可以包含参数)。

另一种选择是使用数据 URI,但它的大小和浏览器支持有限。

You need to create another controller to generate a page, and <img src = "..."> in that page should point to the controller that generates images (these URLs can contain parameters if needed).

Another option is to use Data URI, but it has limited size and browser support.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文