如何在bitmapfield上添加放大/缩小功能?

时间:2012-03-22 07:02:21

标签: user-interface blackberry bitmap blackberry-eclipse-plugin image-zoom

我想添加由位图字段显示的放大/缩小图像的功能 我已经搜索过这个,但是没有得到任何有用的提示,
任何人都可以告诉我如何为缩放图像添加UI和功能。

1 个答案:

答案 0 :(得分:2)

试试此代码

public final class ZoomScreenDemo extends UiApplication
{
    public static void main(final String[] args)
    {
        // Create a new instance of the application and make the currently
        // running thread the application's event dispatch thread.
        UiApplication app = new ZoomScreenDemo();
        app.enterEventDispatcher();
    }


/**
 * Creates a new ZoomScreenDemo object
 */
public ZoomScreenDemo()
{
    UiApplication.getUiApplication().invokeLater(new Runnable()
    {
        public void run()
        {  
            Dialog.alert("Click trackball or screen to zoom");
        }
    });

    pushScreen(new ZoomScreenDemoScreen());
}


public final static class ZoomScreenDemoScreen extends MainScreen
{    
    private EncodedImage _image;        

    /**
     * Creates a new ZoomScreenDemoScreen object
     */
    public ZoomScreenDemoScreen()
    {          
        setTitle("Zoom Screen Demo");          

        _image = EncodedImage.getEncodedImageResource("img/building.jpg");        
        BitmapField bitmapField = new BitmapField(_image.getBitmap(), FIELD_HCENTER | FOCUSABLE);
        add(bitmapField);            
    }       


   /**
    * @see Screen#navigationClick(int, int)
    */
    protected boolean navigationClick(int status, int time)
    {
        // Push a new ZoomScreen if track ball or screen is clicked
        UiApplication.getUiApplication().pushScreen(new ZoomScreen(_image));                            
        return true;
    }


    /**
    * @see Screen#touchEvent(TouchEvent)
    */
    protected boolean touchEvent(TouchEvent message)
    {     
        if(message.getEvent() == TouchEvent.CLICK)
        {
            UiApplication.getUiApplication().pushScreen(new ZoomScreen(_image));                            
        }
        return super.touchEvent(message);          
    }
}
}
相关问题