Ask a question
If you have a question regarding any aspect of Java and/or web related development that you need answered then post it here as a comment and we will endeavor to answer it for you.
How it works
- You simply post a reply/comment below containing your question (you’ll first need to register).
- We select questions from comments for answering.
- The answer to your question will then be posted on a new page and a link emailed to you.
It’s that easy
And if we are unable to answer your question then we’ll also notify you via email to discuss clarifying your question so we can better answer it.
3 Responses to “Ask a question”
Leave a Reply
You must be logged in to post a comment.
October 15th, 2008 at 4:35 am
Thanks for the help with displaying icons in my list.
Can you also tell me how I would do similar with a JComboBox?
Answered
December 2nd, 2008 at 9:35 pm
Hello
I have images stored in my database and before sending them out to display, I want to modify their height and width.
This is my current code which works fine. I load the image from the database, get the Blob from it and write it to the outputstream which displays it on the webpage
Image image = dao.get(Image.class, imageId);
Blob body = image.getBody();
ServletOutputStream outputStream = response.getOutputStream();
IOUtils.copy(body.getBinaryStream(), outputStream);
I want to modify it as follows. Get the current height and width of the image. If its greater than xx, then set the height and width to yy as shown below
Image image = dao.get(Image.class, imageId);
Blob body = image.getBody();
BufferedImage input = ImageIO.read(body.getBinaryStream());
int srcHeight = input.getHeight();
int srcWidth = input.getWidth();
if(srcHeight > 100)
srcHeight=100;
if(srcWidth > 100)
srcWidth=100;
ServletOutputStream outputStream = response.getOutputStream();
IOUtils.copy(body.getBinaryStream(), outputStream);
So basically, after modifying the new width and height, I want to write it to the output stream. But I’m not sure of the following:
1) How to create the new BufferedImage with the new width and height
2) How to send the BufferedImage to the outputStream - basically get an InputStream from the BufferedImage.
Any help will be really appreciated.
Thanks
December 3rd, 2008 at 12:38 am
gubloo,
Have broken your question down into two questions and have posted the answers at the links below, post comments there if you need clarification.
http://helpdesk.objects.com.au/java/how-do-i-scale-a-bufferedimage
http://helpdesk.objects.com.au/java/how-do-i-write-a-bufferedimage-to-an-output-stream
thanks