nomad
14-02-2002, 14:53
huubs da ist was mit dem anhaengsl was passiert
hier nochmals von neuem.
hi leute,
hab ein kleines problemchen
mit java.
das programm kann mit hilfe der maus,
im bild pro prixel die farbe (rgb) erkennen.
da die bilder von einer webcam kommen (win & logitech),
hab ich nur die jpgfiles.
klappt auch alles prima.
nur moechte ich nicht nur ein bild testen sondern
sondern, mehrere bilder.
in der form
" armImg=new Image[10];
MediaTracker mt = new MediaTracker(this);
Toolkit tk = getToolkit();
int i = 1;
do
{
armImg[i-1] = tk.getImage("c:/Dokumente/QuickCam/AutoCapture/arm"+1+".jpg");
mt.addImage(armImg[i-1],0);
actimage = -i;
++i;
repaint();
}(while.....
"
/**
// test.java -achtung- pgm ist lauffaehig mit javac test.java , run java test
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import java.util.*;
public class test
extends Frame
{
public static void main(String Args[])
{
test wnd = new test();
wnd.setSize(600,600);
wnd.show();
}
public test()
{
super("PixelGrabber vers. 0.0.4.1.4.8.");
Label label = new Label();
add("North", label);
add("Center", new ImageCanvas(getToolkit().getImage("armbild1.jpg"),label));
boolean DONE; // for notclear the right scanning pic
DONE = false; // after scanning
//WindowListener
addWindowListener(
new WindowAdapter()
{
public void windowClosing(WindowEvent event)
{
setVisible(false);
dispose();
System.exit(0);
}
}
);
}
}
class ImageCanvas extends Canvas
{
Image image;
Label label;
int[] pixels;
int targetPixelValue;
Color col;
Color picCol;
Color picCol_1;
int antx,anty,b_antx,b_anty;
int count, clicked;
int bc;
boolean InClicked;
boolean OutClicked;
boolean paintTargetPixels;
boolean doneCalibrate;
boolean DONE;
boolean timeout;
boolean targetFound;
ImageCanvas(Image image, Label label)
{
this.image = image;
this.label = label;
}
void paintPixels(Graphics g, int w, int h)
{
g.setColor(Color.red);
for(int y=0; y<h; y++)
{
for(int x=0; x<w; x++)
{
antx = x;
anty = y;
int p = pixels[anty * w + antx];
if(p == targetPixelValue)
{
b_antx = x+w+10;
b_anty = y;
g.fillRect(b_antx,b_anty,1,1);
}
}
}
}
public void update(Graphics g)
{
paint(g);
}
public void paint(Graphics g)
{
g.setColor(Color.black);
g.drawRect(45,145,10,10); // scanfeld
g.drawRect(45,170,100,20); // pseudoButton
g.drawString("Calibrate",50,184);
if(image != null)
{
g.drawImage(image,0,0,this);
int w = image.getWidth(this);
int h = image.getHeight(this);
if(DONE == false)
{
// do something
}
if(DONE == true)
{
// do nothing
}
if(w < 0 || h < 0) return;
if(paintTargetPixels)
{
// ist verantwortlich fuer picCol in Scannfeld
g.setColor(picCol);
paintPixels(g, w, h);
}
if(pixels == null)
{
// Create a pixel grabber and retrieve the pixels.
pixels = new int[w * h];
try
{
PixelGrabber pg = new PixelGrabber(image, 0, 0, w, h, pixels, 0, w);
pg.grabPixels();
// Check for errors.
if((pg.status() & ImageObserver.ABORT) != 0)
{
System.err.println("Error while fetching image");
System.exit(1);
}
} catch (Exception e)
{
e.printStackTrace();
System.exit(1);
}
}
}
}
public boolean mouseMove(Event evt, int x, int y)
{
Graphics g = getGraphics();
if(pixels == null || x >= image.getWidth(this) || y >= image.getHeight(this))
{
// do something
return false;
}
ColorModel cm = ColorModel.getRGBdefault();
int p = pixels[y * image.getWidth(this) + x];
// The pixel value is translated into a color using
// the default color model.
label.setText(x + "," + y + ": " + cm.getRed(p) + " "
+ cm.getGreen(p) + " " + cm.getBlue(p)
+ " a("+cm.getAlpha(p) + ")"); return true;
}
public boolean mouseDown(Event evt, int x, int y)
{
Graphics g = getGraphics();
if(pixels == null || x >= image.getWidth(this) || y >= image.getHeight(this))
{
if(x >=45 || x <= 145 || y >=170 || y<= 190)
{
if(count == 1)
{
// do something
}
}
return false;
}
targetPixelValue = pixels[y * image.getWidth(this) + x];
paintTargetPixels = true;
if(doneCalibrate && clicked == 1)
{
if(x <= image.getWidth(this) || y <= image.getHeight(this))
{
if(count == 2)
{
// do something
}
}
}
int w = image.getWidth(this);
int h = image.getHeight(this);
// do something
if(doneCalibrate && count == 2 && InClicked)
{
// do something
}
// hopping from Sim.java
do
{
ColorModel cm = ColorModel.getRGBdefault();
int p = pixels[anty * image.getWidth(this) + antx];
// do something
}while(!DONE);
// repaint();
return true;
}
public boolean mouseUp(Event evt, int x, int y)
{
//paintTargetPixels = false;
//repaint();
return true;
}
}
**/
da dass ganze pgm fast 3000 zeilen umfasst, ist das pgm als geruest
gedacht.
wer koennte mir da helfen
mfg nomad
hier nochmals von neuem.
hi leute,
hab ein kleines problemchen
mit java.
das programm kann mit hilfe der maus,
im bild pro prixel die farbe (rgb) erkennen.
da die bilder von einer webcam kommen (win & logitech),
hab ich nur die jpgfiles.
klappt auch alles prima.
nur moechte ich nicht nur ein bild testen sondern
sondern, mehrere bilder.
in der form
" armImg=new Image[10];
MediaTracker mt = new MediaTracker(this);
Toolkit tk = getToolkit();
int i = 1;
do
{
armImg[i-1] = tk.getImage("c:/Dokumente/QuickCam/AutoCapture/arm"+1+".jpg");
mt.addImage(armImg[i-1],0);
actimage = -i;
++i;
repaint();
}(while.....
"
/**
// test.java -achtung- pgm ist lauffaehig mit javac test.java , run java test
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import java.util.*;
public class test
extends Frame
{
public static void main(String Args[])
{
test wnd = new test();
wnd.setSize(600,600);
wnd.show();
}
public test()
{
super("PixelGrabber vers. 0.0.4.1.4.8.");
Label label = new Label();
add("North", label);
add("Center", new ImageCanvas(getToolkit().getImage("armbild1.jpg"),label));
boolean DONE; // for notclear the right scanning pic
DONE = false; // after scanning
//WindowListener
addWindowListener(
new WindowAdapter()
{
public void windowClosing(WindowEvent event)
{
setVisible(false);
dispose();
System.exit(0);
}
}
);
}
}
class ImageCanvas extends Canvas
{
Image image;
Label label;
int[] pixels;
int targetPixelValue;
Color col;
Color picCol;
Color picCol_1;
int antx,anty,b_antx,b_anty;
int count, clicked;
int bc;
boolean InClicked;
boolean OutClicked;
boolean paintTargetPixels;
boolean doneCalibrate;
boolean DONE;
boolean timeout;
boolean targetFound;
ImageCanvas(Image image, Label label)
{
this.image = image;
this.label = label;
}
void paintPixels(Graphics g, int w, int h)
{
g.setColor(Color.red);
for(int y=0; y<h; y++)
{
for(int x=0; x<w; x++)
{
antx = x;
anty = y;
int p = pixels[anty * w + antx];
if(p == targetPixelValue)
{
b_antx = x+w+10;
b_anty = y;
g.fillRect(b_antx,b_anty,1,1);
}
}
}
}
public void update(Graphics g)
{
paint(g);
}
public void paint(Graphics g)
{
g.setColor(Color.black);
g.drawRect(45,145,10,10); // scanfeld
g.drawRect(45,170,100,20); // pseudoButton
g.drawString("Calibrate",50,184);
if(image != null)
{
g.drawImage(image,0,0,this);
int w = image.getWidth(this);
int h = image.getHeight(this);
if(DONE == false)
{
// do something
}
if(DONE == true)
{
// do nothing
}
if(w < 0 || h < 0) return;
if(paintTargetPixels)
{
// ist verantwortlich fuer picCol in Scannfeld
g.setColor(picCol);
paintPixels(g, w, h);
}
if(pixels == null)
{
// Create a pixel grabber and retrieve the pixels.
pixels = new int[w * h];
try
{
PixelGrabber pg = new PixelGrabber(image, 0, 0, w, h, pixels, 0, w);
pg.grabPixels();
// Check for errors.
if((pg.status() & ImageObserver.ABORT) != 0)
{
System.err.println("Error while fetching image");
System.exit(1);
}
} catch (Exception e)
{
e.printStackTrace();
System.exit(1);
}
}
}
}
public boolean mouseMove(Event evt, int x, int y)
{
Graphics g = getGraphics();
if(pixels == null || x >= image.getWidth(this) || y >= image.getHeight(this))
{
// do something
return false;
}
ColorModel cm = ColorModel.getRGBdefault();
int p = pixels[y * image.getWidth(this) + x];
// The pixel value is translated into a color using
// the default color model.
label.setText(x + "," + y + ": " + cm.getRed(p) + " "
+ cm.getGreen(p) + " " + cm.getBlue(p)
+ " a("+cm.getAlpha(p) + ")"); return true;
}
public boolean mouseDown(Event evt, int x, int y)
{
Graphics g = getGraphics();
if(pixels == null || x >= image.getWidth(this) || y >= image.getHeight(this))
{
if(x >=45 || x <= 145 || y >=170 || y<= 190)
{
if(count == 1)
{
// do something
}
}
return false;
}
targetPixelValue = pixels[y * image.getWidth(this) + x];
paintTargetPixels = true;
if(doneCalibrate && clicked == 1)
{
if(x <= image.getWidth(this) || y <= image.getHeight(this))
{
if(count == 2)
{
// do something
}
}
}
int w = image.getWidth(this);
int h = image.getHeight(this);
// do something
if(doneCalibrate && count == 2 && InClicked)
{
// do something
}
// hopping from Sim.java
do
{
ColorModel cm = ColorModel.getRGBdefault();
int p = pixels[anty * image.getWidth(this) + antx];
// do something
}while(!DONE);
// repaint();
return true;
}
public boolean mouseUp(Event evt, int x, int y)
{
//paintTargetPixels = false;
//repaint();
return true;
}
}
**/
da dass ganze pgm fast 3000 zeilen umfasst, ist das pgm als geruest
gedacht.
wer koennte mir da helfen
mfg nomad