| | |
Help! Scanning through each image pixel...
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Feb 2005
Posts: 1
Reputation:
Solved Threads: 0
Hi,
I have a project where we need to scan each pixel from an image. Somewhere in the image there will be a 10x10 red pixel and we need to draw a circle around it. This is the code I have so far: (but I'm having trouble figureing out the code to scan each pixel?) Any help would be great! Thanks
public static void main(String[] args) {
TheMatrix picture = new TheMatrix(EasyInput.openFileDialog());
int width = picture.getWidth();
int height = picture.getHeight();
int[] pixels;
for (int x = 0; x < width; x++){
for (int y = 0; y < height; y++){
Color c = picture.getColor(x, y);
if (c == Color.RED){
for (int x = 0; x < 199; ++x) {
int y = (int) (Math.sqrt(200 * 200 - x * x));
picture.setColor(250 + x, 250 + y, Color.WHITE);
picture.setColor(250 - x, 250 + y, Color.WHITE);
picture.setColor(250 + x, 250 - y, Color.WHITE);
picture.setColor(250 - x, 250 - y, Color.WHITE);
picture.show();
}
Paula
I have a project where we need to scan each pixel from an image. Somewhere in the image there will be a 10x10 red pixel and we need to draw a circle around it. This is the code I have so far: (but I'm having trouble figureing out the code to scan each pixel?) Any help would be great! Thanks
public static void main(String[] args) {
TheMatrix picture = new TheMatrix(EasyInput.openFileDialog());
int width = picture.getWidth();
int height = picture.getHeight();
int[] pixels;
for (int x = 0; x < width; x++){
for (int y = 0; y < height; y++){
Color c = picture.getColor(x, y);
if (c == Color.RED){
for (int x = 0; x < 199; ++x) {
int y = (int) (Math.sqrt(200 * 200 - x * x));
picture.setColor(250 + x, 250 + y, Color.WHITE);
picture.setColor(250 - x, 250 + y, Color.WHITE);
picture.setColor(250 + x, 250 - y, Color.WHITE);
picture.setColor(250 - x, 250 - y, Color.WHITE);
picture.show();
}
Paula
i don't quite understand your question and your program, but i understand this :
these is a 10 pixel x 10 pixel sized red square in a picture, we need to find it and draw a circle around it.
well we can solved like this, we need an 10x10 array which will hold the color values... also we need another 2d array which is for the circle, for example a 15x15, we need to fill this array only for once at the beginning.
we start to get every 10x10 from the picture and check if all of the values are RED. then when we found red square we put the circle-array over the red square...
that is the algorithm i found...
i hope i understand correctly.
these is a 10 pixel x 10 pixel sized red square in a picture, we need to find it and draw a circle around it.
well we can solved like this, we need an 10x10 array which will hold the color values... also we need another 2d array which is for the circle, for example a 15x15, we need to fill this array only for once at the beginning.
we start to get every 10x10 from the picture and check if all of the values are RED. then when we found red square we put the circle-array over the red square...
that is the algorithm i found...
i hope i understand correctly.
•
•
Join Date: Jun 2004
Posts: 2,108
Reputation:
Solved Threads: 18
I think there is some method that takes an image, and creates an array of pixels out of it:
I think it's something like this:
I think it's something like this:
Java Syntax (Toggle Plain Text)
int x = getPixels(Image);
![]() |
Similar Threads
- to convert an image to its pixel matrix (VB.NET)
- how to convert image to pixel? (Visual Basic 4 / 5 / 6)
- Read image pixel values (C++)
- Something wrong with scanning of intesity value of pixel image (C#)
- pixel scanning (C++)
- Checking source codes of image, audio and video files (Graphics and Multimedia)
Other Threads in the Java Forum
- Previous Thread: Need help debugging program
- Next Thread: Breaking out of a Loop
| Thread Tools | Search this Thread |
android api applet application apps array arrays automation awt bidirectional binary birt bluetooth busy_handler(null) chat class classes client code columns component constructor database designadrawingapplicationusingjavajslider draw eclipse editor error errors event eventlistener exception expand fractal game givemetehcodez graphics gui guidancer html ide image inetaddress input integer intellij j2me java javamicroeditionuseofmotionsensor javaprojects jme jni jpanel jtree julia link linux list loop map method methods mobile mobiledevelopmentcreatejar myaggfun netbeans newbie oracle parsing plazmic print problem program programming project recursion scanner screen server set sharepoint size smart sms smsspam sort sortedmaps sql string subclass support swing textfield threads time tree unlimited utility webservices windows






