Solved

JPEG image manipulation and streaming

Posted on 2003-12-07
5
1,737 Views
Last Modified: 2013-11-19


I've got to do the following -

1. load an image from a jpeg source
2. plot some points on it, circles; maybe boxes and text later
3. stream the result to file and/or a HTTP response for a servlet


Now, I should really work it out for myself, and the streaming part I've done before. It's the loading and drawing on that has me stumped. I've not done too much image work before and I'm not sure of the best approach.

all tips, pointers etc welcome. thanks.
0
Comment
Question by:matt_law
5 Comments
 
LVL 4

Expert Comment

by:vk33
ID: 9894764
Hi!

I would suggest using Java Advanced Imaging API. Have a look here for tutorial and samples code:

http://java.sun.com/developer/releases/jai/

Hope it helps! Good luck!
0
 
LVL 92

Expert Comment

by:objects
ID: 9894863
> 1. load an image from a jpeg source

Load the jpeg file into an Image using getImage().

> 2. plot some points on it, circles; maybe boxes and text later

Graphics g = image.getGraphics();
g.drawRect(10, 10, 30, 30);
g.drawString("Some text", 20, 20);
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 100 total points
ID: 9896048
For 1.,2. and 3. ImageIO makes this easier:

(import javax.imageio.ImageIO)
...

    try {
      BufferedImage bi = getImage("something.jpg");
      draw(bi);
      stream(bi, new FileOutputStream(response.getOutputStream());
    } catch (Exception e) {
      e.printStackTrace();
    }

...


  public BufferedImage getImage(String fileName) throws IOException {
    return ImageIO.read(new File(fileName));
  }


  public void draw(Image image) {
    // Draw some circles
    Graphics g = image.getGraphics();
    g.setColor(Color.red);
    g.fillOval(20, 20, 20, 20);
  }

  public void stream(BufferedImage image, OutputStream out) throws IOException {
    // Set headers first
    ImageIO.write(image, "jpg", out);
  }
0
 
LVL 1

Author Comment

by:matt_law
ID: 9899480
thanks CEHJ - just what I was looking for, and as I suspected quite simple in the end.

Its for a GPS mapping project - interesting stuff but with an 'tough' deadline so I hadn't really got the time to play around and learn another API in my own time, needed a little boost in the right direction ;)
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 9900163
8-)
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question