WCM Forum

WCM Forum (http://www.wcm.at/forum/index.php)
-   Programmierung (http://www.wcm.at/forum/forumdisplay.php?f=17)
-   -   java: farbe eines applet-pixels auslesen?? (http://www.wcm.at/forum/showthread.php?t=121614)

heli2sky 10.01.2004 18:58

java: farbe eines applet-pixels auslesen??
 
hallo!

wie die überschrift schon sagt, will ich die farbe eines pixels vom applet per koordinaten (x,y) auslesen!!!

wie mach ich das?

ich bitte um eure hilfe!!!!!!!!!!!!

jak 11.01.2004 14:04

In der Robot Klasse gibt es ein getPixelColor():
getPixelColor(int x, int y)

Code:

import java.awt.*;

private Color getPixColor(int x, int y){
 Color col;
 GraphicsDevice screen;
 try{screen=getDefaultScreenDevice();}
 catch (HeadlessException e){throw new IllegalArgumentException("No  defaultScreenDevice");}
 try{
  Robot myRobbie=new Robot(screen);
  col=myRobbie.getPixelColor(x,y)
 }
 catch(RuntimeException e){throw new IllegalArgumentException(e.getMessage());}
 return col;
}


jak 11.01.2004 14:08

Aufgerufen wird das ganze dann so:
public static void main(String[] args){
int x=1,y=1;
try{Color c=getPixColor(x,y);/*irgendetwas mit c machen*/}
catch (IllegalArgumentException e){/*Ein Fehler ist aufgetreten*/}
}

Jak

heli2sky 11.01.2004 17:07

hallo!

danke für die antwort!!! leider schaff ich es nicht, das einzubauen... :(

könntest du mir vielleicht helfen, das in dieses applet einzubauen:

PHP-Code:

import java.awt.*;
import java.applet.*;
import java.awt.event.*;

public class 
testspiel extends java.applet.Applet implements Runnable {
    
    public 
void init() {
    }
    
    public 
void start() {
    }
    
    public 
void stop() {
    }
    [...]
    
    public 
void run() {

        [...]
    }
    
    public 
void paint(Graphics g) {
        
        [...]
    }



jak 12.01.2004 17:41

Kommt drauf an wo und wann die Farbe überprüft werden soll.

Ich würde mal folgendes probieren:
Code:

import java.awt.*;
import java.applet.*;
import java.awt.event.*;

public class testspiel extends java.applet.Applet implements Runnable {
   
    public void init() {
    }
   
    public void start() {
    }
   
    public void stop() {
    }
    [...]
   
    public void run() {
    int x=1,y=1;
    try{
      Color c=getPixColor(x,y);
      /*irgendetwas mit c machen*/
    }
    catch (IllegalArgumentException e){
      /*Ein Fehler ist aufgetreten*/
    }
        [...]
    }
   
    public void paint(Graphics g) {
       
        [...]
    }
   
    private Color getPixColor(int x, int y){
    Color col;
    GraphicsDevice screen;
    try{screen=getDefaultScreenDevice();}
    catch (HeadlessException e){throw new IllegalArgumentException    ("No  defaultScreenDevice");}
    try{
      Robot myRobbie=new Robot(screen);
      col=myRobbie.getPixelColor(x,y)
    }
    catch(RuntimeException e){throw new IllegalArgumentException(e.getMessage());}
    return col;
    }

}

Jak


Alle Zeitangaben in WEZ +2. Es ist jetzt 22:15 Uhr.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
© 2009 FSL Verlag