Setting pixels make blur around pixel!!!

http://s7.postimg.org/lci54wn4b/HELP.png

method for setting pixel

	public void setPixel(int x,int y, int col){
		
		for(int xx = 0 ; xx < x ; xx++){
			for(int yy = 0; yy < y ; yy++){
				int pixel = image.getRGB(x, y);
				
				int allP = (pixel >>> 16) & 0xFF & (pixel >>> 8) & 0xFF & (pixel >>> 0) & 0xFF;
				
				allP = col;

				int result = (pixel << 16) & 0xFF & (pixel << 8) & 0xFF & (pixel << 0) & 0xFF;
				
				System.out.println(result+"");
				
				if(result != col){
					image.setRGB(x, y, allP);
					System.out.println("Pixel At ["+"X: "+x+" Y: "+y+"]" +" Was Changed!");
					break;
				}else{
					System.out.println("Pixel At ["+"X: "+x+" Y: "+y+"]" +" Was Overriden!");
				}
			}
				
		}
		
	}

how do i fix so it does not do that!??!?!

You forgot to ask a question!

fixed it xD question is up there now!

I’m still not sure what you’re asking. How do you fix it so it doesn’t do what? What are you expecting this code to do? What does it do instead?

When does the program’s execution differ from your expectations? Try to narrow it down to a single line, either by debugging your program or at least adding print statements to get a better understanding of what’s going on.

Line 7 and 11 show you don’t have a clue about bit logic. On line 7 you are basically ANDing RGB channels into 8 bits, which will contain something meaningless. On line 11 you do the same, but lose most of the relevant bits when left-shifting, and only retaining the least significant bits, effectively ending up with Zero. Luckily the operations on line 7 are disregarded on line 9.

Why would you possibly perform X*Y times the exact same operation if you want to set the color of (X, Y) ??

That you get a nice blurry blob is nothing short of a miracle.

What you are looking for is:

public void setPixel(int x,int y, int col){
   image.setRGB(x,y,col);
}

::slight_smile:

… and that the majority of the code is dead/pointless…

Assuming this isn’t an excerpt, why is all of that in a loop? The induction variables are unused… you’re just printing the same things over and over again…

UGH , this clearly shows you firstly dont understand how your own code works. Which means you either copied it or posted on stack overflow first. I really would try to figure out how logic works before you attempt anything like this. ESPECIALLY IF YOU ARE USING JAVA2D **grumbles off