Solved

JPEG image manipulation and streaming

Posted on 2003-12-07
5
1,724 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
Comment Utility
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
Comment Utility
> 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
Comment Utility
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
Comment Utility
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
Comment Utility
8-)
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

I've been using this technique since Adobe CS2, and it should work with any version of Illustrator that includes the appearance panel. In this tutorial we'll create a button using the appearance panel in Adobe Illustrator, and then save it as a r…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
This video teaches viewers about errors in exception handling.

743 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now