• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

drawing to the file with GDC

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Sheriff
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're welcome
 
The City calls upon her steadfast protectors. Now for a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic