BlackBerry Forums Support Community

BlackBerry Forums Support Community (http://www.blackberryforums.com/index.php)
-   Developer Forum (http://www.blackberryforums.com/forumdisplay.php?f=15)
-   -   How to use bitmap. (http://www.blackberryforums.com/showthread.php?t=91079)

crazystar 08-18-2007 05:40 AM

How to use bitmap.
 
hi all,


how to add the bitmap. give some basic code to understand.

thanks

arifzaman 08-18-2007 10:23 PM

Hi crazystar,

Add the following code in your MainScreen class.
Code:

Bitmap HELLO_LOGO = Bitmap.getBitmapResource("hello.gif");
BitmapField helloBmpField = new BitmapField(HELLO_LOGO);
add(helloBmpField);

Hope this will meet your requirements! :smile:

Cheers,
ARIF

crazystar 08-19-2007 10:40 PM

thanks Arif,

crazystar 08-19-2007 11:33 PM

thanks Arif, In your example gif images is loaded but if we use gif moving pictures it is not working. it is added but that motion is not in the pictures.help me

arifzaman 08-19-2007 11:48 PM

Welcome crazystar!

actually i didn't check it before. hope, i'll get back to you very soon with your interest.

Thanks,
ARIF

crazystar 08-20-2007 04:14 AM

thanks Arif,After u try that bitmap using gif image tell me ....

jfisher 08-20-2007 10:49 AM

this won't be possible - the blackberry doesn't support animated gifs. the jde converts any gifs in a project to png when you compile. if you want to use an animated gif you should save the seperate layers, the simplest way to achieve the same effect is to update the bitmap displayed in a bitmap field using a timer and timertask

arifzaman 08-20-2007 11:56 PM

Ya, I've the same experience!

The BlackBerry devices support graphics in PNG format. Images in GIF or JPG (JPEG) format can also be added to application projects in the BlackBerry JDE. The BlackBerry JDE converts GIF or JPG images into PNG format automatically when it compiles a project. If an application accesses raw image data on the device, it retrieves PNG image data.

Quote:

Originally Posted by jfisher (Post 638958)
if you want to use an animated gif you should save the seperate layers, the simplest way to achieve the same effect is to update the bitmap displayed in a bitmap field using a timer and timertask

jfisher, A Code snippet would help.

Thanks,
ARIF

jfisher 08-21-2007 03:14 AM

not tested it but something like this should work:

Code:

Bitmap image000 = Bitmap.getBitmapResource("image000.png");
Bitmap image001 = Bitmap.getBitmapResource("image001.png");
Bitmap image002 = Bitmap.getBitmapResource("image002.png");
Bitmap image003 = Bitmap.getBitmapResource("image003.png");
Bitmap image004 = Bitmap.getBitmapResource("image004.png");

BitmapField animationField = new BitmapField(image000);
   
Timer animationTimer = new Timer();
TimerTask animationTask;

int counter = 0;

animationTask = new TimerTask() {
        public void run() {
                if(counter == 0){
                        animationField.setBitmap(image000);
                }
                if(counter == 1){
                        animationField.setBitmap(image001);
                }
                if(counter == 2){
                        animationField.setBitmap(image002);
                }
                if(counter == 3){
                        animationField.setBitmap(image003);
                }
                if(counter == 4){
                        animationField.setBitmap(image004);
                        counter = -1;
                }
                counter++;
        }
};
       
animationTimer.scheduleAtFixedRate(animationTask, 1000, 1000);
       
add(animationField);


arifzaman 08-21-2007 06:02 AM

Thanks jfisher!

All time we need to save seperate layer for animated gif.

:shock:
ARIF

Rose 08-21-2007 11:13 PM

Hi,
Only through replacing Images (ie) moving different frames of Images only we can provide animation .

pa4o85 01-09-2008 07:48 AM

Does the BlackBerry JDE 4.2.0 have API for getting the layers of the animated gif image? What is it?

simon.hain 01-09-2008 08:10 AM

the JDE is not intended to manipulate gif-images. try a google with 'gif animation extract' or something along this line.

hth,
simon

pa4o85 01-10-2008 02:38 AM

I am trying to resolve this problem using EncodedImage and its child GIFEncodedImage classes from the standard RIM library. How do you think about that?

simon.hain 01-10-2008 05:11 AM

Quote:

Originally Posted by pa4o85 (Post 796415)
I am trying to resolve this problem using EncodedImage and its child GIFEncodedImage classes from the standard RIM library. How do you think about that?

Quote:

the blackberry doesn't support animated gifs
qft

pa4o85 01-14-2008 03:18 AM

Animated Gif Problem !
 
I have a class like this that pushes to the stack a new screen that is a picture (jpeg, gif or something). In the case i have an animated gif I have a problem with displaying the frames of the gif. Here is my class:

Code:

public class FullScreenBanner extends MainScreen {
  private int bannerWidth;
  private int bannerHeight;
 
  private int wFrame;
  private int hFrame;
  private int lOffset = 0;
  private int tOffset = 0;
 
  private EncodedImage encodedImage;
  private Bitmap fullScreen;
 
  private int index = 0;
  private int backgroundColor;
  /**
  * Constructor
  *
  * @param fullScreenBanner - byte array
  */
  public FullScreenBanner(byte[] fullScreenBanner, int color) {
    super(Manager.NO_VERTICAL_SCROLL);
    encodedImage = EncodedImage.createEncodedImage(fullScreenBanner, 0, fullScreenBanner.length);
    wFrame = bannerWidth = encodedImage.getWidth();
    hFrame = bannerHeight = encodedImage.getHeight();
    if (encodedImage.getImageType() == EncodedImage.IMAGE_TYPE_GIF) {
      getNextFrame();
    } else {
      fullScreen = Bitmap.createBitmapFromBytes(fullScreenBanner, 0, -1, 1);
    }
    this.backgroundColor = color;
  }
   
  protected void paint(Graphics g) {
    g.setBackgroundColor(backgroundColor);
    int wp = (Display.getWidth() + bannerWidth) / 2;
    int wm = (Display.getWidth() - bannerWidth) / 2;
    int hp = (Display.getHeight() + bannerHeight) / 2;
    int hm = (Display.getHeight() - bannerHeight) / 2;
    g.clear(0, 0, wp, hm);
    g.clear(wp, 0, wm, hp);
    g.clear(0, hm, wm, hp);
    g.clear(wm, hp, wp, hm);
    g.drawBitmap(wm + lOffset, hm + tOffset, wFrame, hFrame, fullScreen, 0, 0);
  }
 
  private void getNextFrame() {
    index = 0;
    TimerTask ttask = new TimerTask() {
      public void run() {
        fullScreen = encodedImage.getBitmap(index);
        GIFEncodedImage gif = (GIFEncodedImage) encodedImage;
        lOffset = gif.getScaledFrameLeft(index);
        tOffset = gif.getScaledFrameTop(index);
        wFrame = gif.getFrameWidth(index);
        hFrame = gif.getFrameHeight(index);
        if (index == (gif.getFrameCount() - 1)) {
          index = -1;
        }
        index++;
        UiApplication.getUiApplication().getActiveScreen().invalidate();
      }
    };
    GIFEncodedImage gif = (GIFEncodedImage) encodedImage;
    new Timer().scheduleAtFixedRate(ttask, gif.getFrameTransition(index) * 100,
        gif.getFrameDelay(index) * 10);
  }
 
  protected void onFocus(int direction) {
    super.onFocus(direction);
  }
 
  protected boolean trackwheelClick(int status, int time) {
    return true;
  }
 
}

I have a timer task that gets the next frame and its offsets and a timer that execute the task. When I have a frame smaller than the gif size the frame under is gone out. I mean that every time when the area is repainting itself the old content is missing but i need it because the old frame of the gif is a part of the new one. Do u understand what i mean ?

pa4o85 01-15-2008 03:41 AM

Hi ! Is there anybody make an animated gif image suport ? I just don't know how to display the frames! :oops:

Al3x2003 02-29-2008 09:20 AM

HELP ME!

I want play a gif animate into my midlet for Blackberry. Exist an method to it?

An example?

Thanks to yours help!

jfisher 02-29-2008 10:41 AM

Quote:

Originally Posted by Al3x2003 (Post 854431)
HELP ME!

I want play a gif animate into my midlet for Blackberry. Exist an method to it?

An example?

Thanks to yours help!

read the thread you just posted in.

CELITE 02-29-2008 12:17 PM

If you want to create an animation in the same way as a gif, create a tiled image using the frames in your animation as the tiles. Then use the Sprite class to animate it.


All times are GMT -5. The time now is 04:34 AM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.