This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Drawing a circle  RSS feed

 
Chris Chua
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello How does one draw a circle, using the MemoryImageSource class, What is the formula for creating that circle?(w/o using the drawOval() of Graphics class) could somebody pls help me with some code.
Thanks
Chris
 
John Zukowski
Author
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Create an Image from a MemoryImageSource (Image img = createImage(new MemoryImageSource(w, h, pix, 0, w))), get its graphics context, and use it to draw on the image.
------------------
John Zukowski Author of "Definitive Guide to Swing for Java 2" and "Java Collections"
 
Chris Chua
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Mr Zukowski for your reply, however the when you run it it says that using what you suggested img = createImage(new MemoryImageSource(w,h, pix,0, w)) then get a graphic context to draw can only be done with createImage(w, h). However what i really wanted to do is there is an image then on top of this would be another image to cover the picture then this top layer image would have a circle shape which is transparent for you to see just a portion of the picture, I think they call it mask.
could you pls help me on this?
Thanks
Chris
 
Amit Agarwal
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Chris,
if i understand what u intend to do, u can simply use a setClip(Shape) on the graphics surface to get the mask effect.
---------------
Amit
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!