Solved

JPEG image manipulation and streaming

Posted on 2003-12-07
5
1,745 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Many programs have tried to outwit PowerPoint in terms of technology and skill. These programs, however, still lack several characteristics that PowerPoint has possessed from the start. Here's why PowerPoint replacements won't entirely work for desi…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Learn how to set up basic frames and paths in Prezi and understand the open space that Prezi allows you to create presentations in.
It’s easy to embed any of your public Prezi presentations on your website or social network to share with others. Learn how simple it is in this tutorial.
Suggested Courses

737 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