Skip to main content

Displaying images on the screen problem

2 replies [Last post]
nikkizeng
Offline
Joined: 2009-05-27

Hi,

I need help to display images on the screen. I have tried many ways. I can use the DVBBufferedImage class to create an image, then replace the image in the hdcookbook disc and show OTS. But I don't know, in the helloWorld Xlet, why the paint method couldn't show the image created from DVBBufferedImage. Where is the problem? Also, I am trying to use IFAA class, but no matter how I call it, there is no effect OTS. I can't figure out the correct way to show the effect. Do I need to use GRIN? Looking forward to any suggestion. Thank you very much!

Best regards,
Nikki

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
ryanbertiwork
Offline
Joined: 2009-06-04

Nikki,

I am in the same position and hoping that if I post some code someone will help. I have been using the cookbook build files to compile and construct the disc image and Scenarist QC to debug. I can draw a rectangle through graphics in paint function with no problems, but when I try to open an image and draw it I get this error.

Output: Exception caught in SonicFileImageSource.startProduction()

Heres code. (squirrel png is in src folder so it should be in the jar)

package animationtester;

import javax.tv.xlet.XletContext;
import java.awt.Color;
import java.awt.Container;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.BorderLayout;
import java.awt.Rectangle;
import java.awt.event.KeyEvent;

import org.havi.ui.HScene;
import org.havi.ui.HSceneFactory;
import org.havi.ui.*;
import org.havi.ui.event.*;

import java.awt.event.KeyListener;
import java.lang.Thread;
import java.awt.*;

public class animationtest extends Container implements javax.tv.xlet.Xlet,
KeyListener {

private boolean stop = false;
private int xpos,ypos;
private Rectangle rect;
private Image img;
private HScene scene;
private XletContext cntxt;

public animationtest() {
super();
}

public void initXlet(XletContext content) {
cntxt = content;

HSceneFactory hsfactory = HSceneFactory.getInstance();
HSceneTemplate hstemplate = new HSceneTemplate();
hstemplate
.setPreference(HSceneTemplate.SCENE_SCREEN_DIMENSION,
new org.havi.ui.HScreenDimension(1, 1),
HSceneTemplate.REQUIRED);
hstemplate.setPreference(HSceneTemplate.SCENE_SCREEN_LOCATION,
new org.havi.ui.HScreenPoint(0, 0), HSceneTemplate.REQUIRED);
scene = hsfactory.getBestScene(hstemplate);

setVisible(true);
setBackground(Color.black);
rect = scene.getBounds();
setBounds(rect);

img = Toolkit.getDefaultToolkit().createImage("squirrel-400.png");

scene.setVisible(false);
scene.add(this, BorderLayout.CENTER);
addKeyListener(this);

}

public void startXlet() {
scene.setVisible(true);
this.requestFocus();
}

public void pauseXlet() {
scene.setVisible(false);
}

public void destroyXlet(boolean yorn) {
removeKeyListener(this);
if (scene != null) {
scene.remove(this);
scene.setVisible(false);
HSceneFactory.getInstance().dispose(scene);
scene = null;
}
}

public void paint(Graphics g) {
g.drawImage(img, rect.height, 20, null);
g.draw3DRect(0, 0, 100, 100, true);
}

public void keyPressed(KeyEvent e) {
switch (e.getKeyCode()) {
case HRcEvent.VK_COLORED_KEY_0:
case HRcEvent.VK_COLORED_KEY_1:
stop = false;
break;
case HRcEvent.VK_COLORED_KEY_2:
case HRcEvent.VK_COLORED_KEY_3:
stop = true;
break;
default:
stop = false;
}
repaint();
}

public void keyTyped(KeyEvent e) {

}

public void keyReleased(KeyEvent e) {

}

class animationthread extends Thread{
public void run(){

}
}
}

Gunnar Adler

Please have a look at your application jar file to verify the image is
really in there. You can do this by opening it with some zip tool and
browse the contents.
If so you could try to load the image via
Toolkit.getDefaultToolkit().getImage(getClass().getClassLoader().getResource("squirrel-400.png"))
alternatively.

---------------------------------------------------------------------
To unsubscribe, e-mail: bd-j-dev-unsubscribe@hdcookbook.dev.java.net
For additional commands, e-mail: bd-j-dev-help@hdcookbook.dev.java.net