Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (741)
Games in Android Showcase (225)
games submitted by our members
Games in WIP (823)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Setting pixels make blur around pixel!!!  (Read 1776 times)
0 Members and 1 Guest are viewing this topic.
Offline VIrtueeL
« Posted 2015-05-05 15:08:56 »




method for setting pixel
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
   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!??!?!

i do devlogs and i do tutorials check em out
https://www.youtube.com/user/InidDevo
Offline KevinWorkman

« JGO Plugged Duke »


Medals: 270
Projects: 12
Exp: 12 years


HappyCoding.io - Coding Tutorials!


« Reply #1 - Posted 2015-05-05 15:11:15 »

You forgot to ask a question!

HappyCoding.io - Coding Tutorials!
Happy Coding forum - Come say hello!
Offline VIrtueeL
« Reply #2 - Posted 2015-05-05 15:21:51 »

You forgot to ask a question!

fixed it xD question is up there now!

i do devlogs and i do tutorials check em out
https://www.youtube.com/user/InidDevo
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline KevinWorkman

« JGO Plugged Duke »


Medals: 270
Projects: 12
Exp: 12 years


HappyCoding.io - Coding Tutorials!


« Reply #3 - Posted 2015-05-05 15:27:45 »

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.

HappyCoding.io - Coding Tutorials!
Happy Coding forum - Come say hello!
Offline Riven
Administrator

« JGO Overlord »


Medals: 1324
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #4 - Posted 2015-05-05 19:59:47 »

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:
1  
2  
3  
public void setPixel(int x,int y, int col){
   image.setRGB(x,y,col);
}

 Roll Eyes

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings!
Offline BurntPizza

« JGO Bitwise Duke »


Medals: 485
Exp: 7 years



« Reply #5 - Posted 2015-05-05 20:04:42 »

... 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...
Offline lcass
« Reply #6 - Posted 2015-05-05 20:07:37 »

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
Pages: [1]
  ignore  |  Print  
 
 

 
xxMrPHDxx (17 views)
2017-11-21 16:21:00

xxMrPHDxx (11 views)
2017-11-21 16:14:31

xxMrPHDxx (14 views)
2017-11-21 16:10:57

Ecumene (114 views)
2017-09-30 02:57:34

theagentd (148 views)
2017-09-26 18:23:31

cybrmynd (248 views)
2017-08-02 12:28:51

cybrmynd (247 views)
2017-08-02 12:19:43

cybrmynd (244 views)
2017-08-02 12:18:09

Sralse (258 views)
2017-07-25 17:13:48

Archive (878 views)
2017-04-27 17:45:51
List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05

SF/X Libraries
by SkyAphid
2017-03-02 06:38:56

SF/X Libraries
by SkyAphid
2017-03-02 06:38:32

SF/X Libraries
by SkyAphid
2017-03-02 06:38:05

SF/X Libraries
by SkyAphid
2017-03-02 06:37:51
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!