09-19-2008 01:52 AM
Hi,
loading bitmap image but I can obtain only "Failed to load image" any one tellme how to access the image in to our application.
private class ScrollingImageScreen extends MainScreen {
private static final int HORZ_SCROLL_FACTOR = 10;
private static final int VERT_SCROLL_FACTOR = 10;
Bitmap bitmap = Bitmap.getBitmapResource("image.png");
int left = 0;
int top = 0;
int maxLeft = 0;
int maxTop = 0;
public ScrollingImageScreen() {
if (bitmap == null) {
UiApplication.getUiApplication().invokeLater(new Runnable() {
public void run() {
Dialog.alert("Failed to load image");
System.exit(0);
}
});
return;
}
if (bitmap.getWidth() > Graphics.getScreenWidth()) {
maxLeft = bitmap.getWidth() - Graphics.getScreenWidth();
}
if (bitmap.getHeight() > Graphics.getScreenHeight()) {
maxTop = bitmap.getHeight() - Graphics.getScreenHeight();
}
}
protected void paint(Graphics graphics) {
if (bitmap != null) {
graphics.drawBitmap(0, 0, Graphics.getScreenWidth(), Graphics.getScreenHeight(),bitmap, left, top);
}
}
protected boolean navigationMovement(int dx, int dy, int status, int time) {
left += (dx * HORZ_SCROLL_FACTOR);
top += (dy * VERT_SCROLL_FACTOR);
if (left < 0) left = 0;
if (top < 0) top = 0;
if (left > maxLeft) left = maxLeft;
if (top > maxTop) top = maxTop;
invalidate();
return true;
}
}
ScrollingImageRecipe() {
pushScreen(new ScrollingImageScreen());
}
public static void main(String[] args){
ScrollingImageRecipe app = new ScrollingImageRecipe();
app.enterEventDispatcher();
}
09-19-2008 02:34 AM
Hey, that code looks familiar. ![]()
It looks ok; are you sure that "image.png" is being built into your application?
09-19-2008 03:21 AM
Yes the image is in the location but the image loading fail
09-19-2008 04:49 AM
I agree with Richard that the most likely problem is the location of the image. I suggest that you look at the *.jdp (project) file associated witht he project your are using (you can open it with notepad). In there, you should chec the
[Files
section you should see your image and the ScrollingImageScreen.java class. Here is an example:
[Files
..
com\mycompany\UI\BoldIcon.png
..
com\mycompany\UI\LoginScreen.java
..
]
In this case, the image file and the screen that uses it are both in the com/mycompany/UI directory.