I want to image file containing polygon with given coordinates with white color inside the polygon and black color outside of given size. Size of the image and co-ordinates of the polygon are given. How can I write java code to output the image file. Will there be any inbuilt functions? Thank you in advance.
Asked
Active
Viewed 35 times
-2
-
3Welcome to Stack Overflow! Please turn to the [help] to learn how/what to ask here. Just dropping requirements "this is what I want" isn't appreciated. When you try something yourself, and you get stuck with a specific problem, we will gladly help. But please understand that this place is not intended to give guidance with the possibly many steps required to get you from your vision to a working program. – GhostCat Jun 04 '19 at 18:17
-
1Also see https://meta.stackoverflow.com/questions/284236/why-is-can-someone-help-me-not-an-actual-question to understand why we really can't help with such vague input. – GhostCat Jun 04 '19 at 18:17
1 Answers
0
Create a Polygon and use the contains(int x, int y)
inside a loop to figure out which pixels should be white and which should be black. Create a BufferedImage, and use createGraphics()
to draw the correct colors to the image. Finally, check How to save a BufferedImage as a File for help with outputting the image file.

gambinaattori
- 49
- 3