Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

drawing to the file with GDC

 
Johny Wyenski
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear all,

I'd like to create a picture in a memory, then save it to the file and show preview (after creating in memory) on the screen.

I have started in such a way that from Oracle documentation I gave fragment of the code to my menu:



As far as I understand, now I have got the picture created in the memory. Then I need to show in in the window or to save to the file (I'm interested in both). How can I do it?

I also wonder how to e.g. draw rectangle or write text. I was doing it in such a way:



but I don't know how to apply it to pix[].

Regards!
 
Rob Spoor
Sheriff
Pie
Posts: 20529
54
Chrome Eclipse IDE Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First issue, the saving. You can use JFileChooser to show a save dialog for you. After the user hits Save, the showSaveDialog method will return JFileChooser.APPROVE_OPTION. If this is the return value, get the selected File, and use ImageIO.write to save the image to a file.

As for the second issue, that's going to be tricky with direct image manipulation. Fortunately, BufferedImage can help you out:
Although I drew your original image, you can also use BufferedImage's setRGB method to set each pixel directly. That way you don't need the original image at all.
 
Johny Wyenski
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you!

I have the following code (this is one of menu options):



The difficulty for me is range of variables parent (and, in analogical way, width and height):

parent is not public in java.awt.Component; cannot be accessed from outside package


and using drawRect and drawString in the context of the code above.

Regards!
 
Darryl Burke
Bartender
Posts: 5126
11
Java Netbeans IDE Opera
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Johny, please BeForthrightWhenCrossPostingToOtherSites.
http://www.java-forums.org/new-java/52121-draw-file-gdc.html
 
Johny Wyenski
Greenhorn
Posts: 21
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, so I'm going to post a new message on the other forum. And thank you again Rob Spoor for your very useful answer. In the future I'm going to write links to the other forum in case of crossposting or even avoid crossposting at all.
Regards!
 
Rob Spoor
Sheriff
Pie
Posts: 20529
54
Chrome Eclipse IDE Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic