2011-09-30 3 views
0

내 앱을 열 때 비트 맵 필드에 스플래시 화면 이미지를 추가했습니다. 스레드 메서드에서 나는 httpconnection에서 로고를 얻을.위의 비트 맵 필드에 블랙 베리의 GIF 이미지로드 중

스레드 실행이 완료되면 bitmap 필드를 삭제합니다. 해당 화면에 로고를로드하십시오.

스레드를 실행할 때 비트 맵 위에 gif 이미지를로드하고 싶습니다.

Pls 도움.

안녕하세요, 이미 비트 맵 필드를 사용하여 전체 화면에 이미지를 표시합니다. 위의 비트 맵 필드에서 어떻게로드 GIF 이미지를 보여줍니다. 그게 내 질문이야. 이 링크에

+0

비트 맵 필드를 BackgroundFieldManager (페인트 메서드 graphics.setBitmap();) 백그라운드에 추가하고 아래 코드를 작성합니다. – alishaik786

답변

4

이동 :

http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800332/800505/800345/How_To_-_Display_an_animated_GIF.html?nodeid=1405903&vernum=0

당신은 AnimatedGIFField.java 파일을 얻을 것이다. 적절한 이름으로 저장하십시오. 당신이 그것을 exceptoin을 제공합니다> 6.0 버전이 "loading.gif"를 사용하는 경우 :와 .... 같은

GIFEncodedImage bitmapImage=(GIFEncodedImage)GIFEncodedImage.getEncodedImageResource("loading.gif"); 
AnimatedGIFField image_field=new AnimatedGIFField(bitmapImage); 
add(image_field); 

주 물품. 이를 위해 파일의 이름을 "loading.agif"으로 바꿔야합니다. 7.0 버전의 의미는 "loading.agif"이 아닌 "loading.gif"을 사용해야합니다. 해당 파일의 이름을 변경하고, 고해상도의 폴더에 저장하고 파일 이름을 변경 :

GIFEncodedImage.getEncodedImageResource ("loading.agif")

이있는 경우 의심에 유래 대화방 이름 에 와서 "Life for Blackberry" 당신과 우리의 의심을 명확히합니다.

+0

안녕하세요, 이미 비트 맵 필드를 사용하여 전체 화면에 이미지를 표시합니다. 위의 비트 맵 필드에서 어떻게로드 GIF 이미지를 보여줍니다. 그게 내 질문이야. – RVG

1

BitmapFieldGIF 파일을로드하기 위해 다음과 같은 클래스를 사용하여, 는 전화를하고 아래의 코드를 사용 표시하려면 :

GIFEncodedImage yourImage =(GIFEncodedImage)GIFEncodedImage.getEncodedImageResource("picture.gif"); 
AnimatedGIFField yourImageField =new AnimatedGIFField(yourImage); 
add(yourImageField); 

**

  • 등급 :

**

import net.rim.device.api.ui.UiApplication; 
import net.rim.device.api.system.GIFEncodedImage; 
import net.rim.device.api.ui.Graphics; 
import net.rim.device.api.ui.component.BitmapField; 
import net.rim.device.api.ui.Color; 
//A field that displays an animated GIF. 

public class AnimatedGIFField extends BitmapField 
{ 
    private GIFEncodedImage _image;  //The image to draw. 
    private int _currentFrame;   //The current frame in the animation sequence. 
    private int _width;     //The width of the image (background frame). 
    private int _height;    //The height of the image (background frame). 
    private AnimatorThread _animatorThread; 

    public AnimatedGIFField(GIFEncodedImage image) 
    { 
     this(image, 0); 
    } 

    public AnimatedGIFField(GIFEncodedImage image, long style) 
    { 
     //Call super to setup the field with the specified style. 
     //The image is passed in as well for the field to configure its required size. 
     super(image.getBitmap(), style); 

     //Store the image and it's dimensions. 
     _image = image; 
     _width = image.getWidth(); 
     _height = image.getHeight(); 

     //Start the animation thread. 
     _animatorThread = new AnimatorThread(this); 
     _animatorThread.start(); 
    } 

    protected void paint(Graphics graphics) 
    { 
     //Call super.paint. This will draw the first background frame and handle any required focus drawing. 

     super.paint(graphics); 

     //Don't redraw the background if this is the first frame. 
     if (_currentFrame != 0) 
     { 
      //Draw the animation frame. 
      graphics.drawImage(_image.getFrameLeft(_currentFrame), _image.getFrameTop(_currentFrame), 
       _image.getFrameWidth(_currentFrame), _image.getFrameHeight(_currentFrame), _image, _currentFrame, 0, 0); 
     } 
    } 

    //Stop the animation thread when the screen the field is on is 
    //popped off of the display stack. 
    protected void onUndisplay() 
    { 
     _animatorThread.stop(); 
     super.onUndisplay(); 
    } 


    //A thread to handle the animation. 
    private class AnimatorThread extends Thread 
    { 
     private AnimatedGIFField _theField; 
     private boolean _keepGoing = true;  
     private int _totalFrames;    //The total number of frames in the image. 
     private int _loopCount;     //The number of times the animation has looped (completed). 
     private int _totalLoops;    //The number of times the animation should loop (set in the image). 

     public AnimatorThread(AnimatedGIFField theField) 
     { 
      _theField = theField; 
      _totalFrames = _image.getFrameCount(); 
      _totalLoops = _image.getIterations(); 

     } 

     public synchronized void stop() 
     { 
      _keepGoing = false; 
     } 

     public void run() 
     { 
      while(_keepGoing) 
      { 
       //Invalidate the field so that it is redrawn. 
       UiApplication.getUiApplication().invokeAndWait(new Runnable() 
       { 
        public void run() 
        { 
         _theField.invalidate();      
        } 
       });     

       try 
       { 
        //Sleep for the current frame delay before the next frame is drawn. 
        sleep(_image.getFrameDelay(_currentFrame) * 10); 
       } 
       catch (InterruptedException iex) 
       {} //Couldn't sleep. 

       //Increment the frame. 
       ++_currentFrame;  

       if (_currentFrame == _totalFrames) 
       { 
        //Reset back to frame 0 if we have reached the end. 
        _currentFrame = 0; 

        ++_loopCount; 

        //Check if the animation should continue. 
        if (_loopCount == _totalLoops) 
        { 
         _keepGoing = false; 
        } 
       } 
      } 
     } 
    } 
} 
관련 문제