Results 1 to 5 of 5
  1. #1
    Josh_FL is offline Member
    Join Date
    Dec 2008
    Posts
    2
    Rep Power
    0

    Default Image Processing

    Hello there,

    I want to use Java to produce an image file (BMP, JPEG, GIF, PNG...) from my code, through the console, not the GUI.

    For example, I want my code to produce an image to draw a line from point A to point B, and create a box at the end of Point B, and then output the results to the image file, without displaying the image on the screen to do so.

    This is not what I actually want to do with the problem. I want to draw more complex images, but if someone can point me to an example of the above, or point me in the direction, I should be able to figure out the rest.

    Thanks ahead of time.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Have you looked into using a BufferedImage object here? I'm no pro at this, but that would be a possible avenue of attack that I'd explore early on.

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    Just for pointing you, look at the following code segment.

    Java Code:
                byte[] utf8 = stringToDraw.getBytes("utf-8");
                stringToDraw = new String(utf8);
    
                BufferedImage bufferedImage =
                        new BufferedImage(400, 400, BufferedImage.TYPE_INT_BGR);
    
                Graphics2D imageGraphic = bufferedImage.createGraphics();
                imageGraphic.setColor(Color.white);
                imageGraphic.fillRect(0, 0, 400, 400);
                imageGraphic.setColor(Color.GREEN);
                imageGraphic.drawString("String to draw", 20, 20);
                imageGraphic.dispose();
    
                ImageIO.write(bufferedImage, "JPEG", 
                        new File("images/draw_image.jpeg"));

  4. #4
    Josh_FL is offline Member
    Join Date
    Dec 2008
    Posts
    2
    Rep Power
    0

    Default

    Thank you both, this is very helpful. I began using the Processing library to extend Java and make it easier to save images, but I will try this. Thanks!

  5. #5
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    In the above code segment what I've done is, draw a string and colored the background and save it as an image. You have to think that how to replace your image with that string and save it. Try it out. Good luck.

Similar Threads

  1. image processing
    By sathish natrajan in forum Java 2D
    Replies: 2
    Last Post: 11-06-2008, 06:13 PM
  2. Replies: 1
    Last Post: 01-15-2008, 08:12 PM
  3. Replies: 0
    Last Post: 01-08-2008, 06:29 PM
  4. Image Processing in J2ME
    By mobeenkhan in forum CLDC and MIDP
    Replies: 1
    Last Post: 08-02-2007, 06:30 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •