drawImage method is not working

151 views Asked by At

I do not know if this is the right place to ask, but I hope it is.

I am building Fusion web application with ADF using Jdeveloper 12c. in this application I am getting an image object dynamically from external machine for digital signature. the user will sign using this machine then I am calling some method that return the signature as an Image object. my task is to display this image to the user in the browser. The problem is :

My approach to achieve this task is to use the method drawImage but nothing appears in the browser. I am sure that the image is not null. here is a part of the code:

Image bi=this.sigObj.sigImage();   //this.sigObj.sigImage() will return an object of type BufferedImage
Graphics g= bi.getGraphics();
g.drawImage(bi, 300, 300, null);

Note: when I call getWidth(null) and get getHeight(null) both of them return 1. I do not know if that's helps.

Thank You

1

There are 1 answers

3
JB Nizet On

This really doesn't make any sense. You have an image in an in-memory buffer on your web server, you get its graphics, and redraw the image on it (which already doesn't make sense), and you're hoping that this will magically render the image on some browser somewhere else?

To have a dynamically generated image displayed in a web page, this web page must have an

<img src="/somUrl" />

tag, and the servlet or action mapped to /someUrl must return an HTTP response telling the format of the image (in its content-type header, like for example image/png), and contain the bytes of the image, encoded in this format (by writing the BufferedImage to the servlet response output stream using ImageIO, for example).