Solved

JPEG image manipulation and streaming

Posted on 2003-12-07
5
1,742 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

Technology Partners: 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

Title # Comments Views Activity
ejb wildfly example 2 69
login form jsp example 2 47
spring maven example issues 3 37
batch vs regular insert in spring DAO 2 20
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…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Add visuals to your Prezi to keep your audience engaged. Learn how to embed images, edit them, and more in this video micro tutorial. Select "Insert" from the top menu in your Prezi editor: Select "Image": A toolbar will pop in from the right …

679 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