Results 1 to 3 of 3
  1. #1
    satanfx55 is offline Member
    Join Date
    May 2011
    Posts
    7
    Rep Power
    0

    Default creating an image from scratch

    Here is what I have:
    2 dimensional array of colors with RGB values. (like pixels)

    Here is what I need:
    an image reflecting the contents of that 2d array.

    I have researched this a bit and read about images, bufferedImages, rasters, writableRasters, and the like but I dont quite understand how to use them. My ultimate goal is to create an image from scratch using the RGB values stored in the array and write them to a bitmap file or something.

    Any easy way to do this?

    thanks!

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,763
    Blog Entries
    7
    Rep Power
    21

    Default

    Create a BufferedImage, use the getGraphics() method to get its Graphics2D object. Draw on the Graphics2D object and use the ImageIO class to save the BufferedImage.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

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

    Default

    For your problem, perhaps what you want to do is create a BufferedImage as Jos states above, but call getRaster() on it to extract the BufferedImage's WritableRaster object. Then you can draw via one of the many setPixel(s) method overloads to your heart's content.

Similar Threads

  1. java from scratch
    By waqar100 in forum New To Java
    Replies: 2
    Last Post: 10-06-2010, 09:05 AM
  2. gui builder vs from scratch
    By dinosoep in forum New To Java
    Replies: 5
    Last Post: 08-08-2010, 12:12 PM
  3. Replies: 1
    Last Post: 08-10-2009, 12:51 PM
  4. Creating a label with an image
    By Java Tip in forum SWT Tips
    Replies: 0
    Last Post: 07-11-2008, 05:40 PM
  5. Creating a caret (using an image) in SWT
    By Java Tip in forum SWT Tips
    Replies: 0
    Last Post: 07-02-2008, 08:51 PM

Tags for this Thread

Posting Permissions

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