Fasted way to display images? [message #531649] |
Wed, 05 May 2010 16:21 |
Eclipse User |
|
|
|
Originally posted by: txbarth.web.de
Hi,
I would like to display catched images of a webcam in my Java/SWT
Application. Today I simulated a webcam by loading 24 jpeg pictures per
second on canvas. But the cpu is beeing charged by 60-70%.
[...]
canvas.addPaintListener (new PaintListener () {
public void paintControl (PaintEvent event) {
if(null != imageData) {
Image image = new Image(getDisplay(), imageData);
[code to get sizes and position]
event.gc.drawImage (image, 0, 0, img_width, img_height,
destX, destY, scale_width, scale_height);
image.dispose();
}
}
});
[...]
// Method that calls canvas.redraw 41 times a second
private static void startTimer() {
if(null != timer) {
return;
}
timer = new Timer();
TimerTask timerTask = new TimerTask() {
public void run() {
String filename = files[pos];
imageData = loadImageData(filename);
Display.getDefault().asyncExec(new Runnable() {
public void run() {
if(canvas.isDisposed()) return;
canvas.redraw();
}
});
pos++;
if(pos >= files.length) {
pos = 0;
}
}
};
timer.schedule(timerTask, 0, 41);
}
Is this the fasted way to paint complete images on canvas?
Thomas B
|
|
|
|
Powered by
FUDForum. Page generated in 0.02927 seconds