Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

JPEG image manipulation and streaming

Posted on 2003-12-07
5
Medium Priority
?
1,759 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 400 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

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…
Technology opened people to different means of presenting information, but PowerPoint remains to be above competition. Know why PPT still works today.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Learn how to use the remote presentation tool in Prezi to allow you to harness the power of this cloud based presentation platform. You can show your presentation with a remote audience using this free tool.
Suggested Courses

604 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