【问题标题】:How i cn set Backgroungd image in Blackberry?如何在黑莓中设置背景图像?
【发布时间】:2012-07-16 22:01:38
【问题描述】:

我想在垂直字段管理器中设置背景图像。我试过了,但它没有填满你可以在我的屏幕上看到的高度。并在我的代码中执行我正在做的错误,请帮助我。

 vfmCenter = new VerticalFieldManager(FIELD_HCENTER)
   {            
    public void paint(Graphics graphics)
         {

         graphics.clear();
         graphics.drawBitmap(0, 0,deviceWidth,deviceHeight,newimg,0,0);               
         super.paint(graphics);
          }      

          protected void sublayout( int maxWidth, int maxHeight)
          {
             int width = Display.getWidth();
             int height = Display.getHeight();
             super.sublayout( width, height);
             setExtent( width, height);
          }         
          };        

vfmMain.add(vfmCenter);             
        this.add(vfmMain);

【问题讨论】:

  • 仅绘制位图不会增加或减少图像的大小..这是您的verticalfieldmanager中的问题

标签: blackberry


【解决方案1】:

我之前也遇到过同样的问题..我用这个解决了我的问题..

class MyClass extends MainScreen
{
    // function for scaling your image to fit the screen

    public EncodedImage scaleImage(EncodedImage source, int requiredWidth, int requiredHeight) 
    {  
        int currentWidthFixed32 = Fixed32.toFP(source.getWidth());  
        int requiredWidthFixed32 = Fixed32.toFP(requiredWidth);  
        int scaleXFixed32 = Fixed32.div(currentWidthFixed32, requiredWidthFixed32);  
        int currentHeightFixed32 = Fixed32.toFP(source.getHeight());  
        int requiredHeightFixed32 = Fixed32.toFP(requiredHeight);  
        int scaleYFixed32 = Fixed32.div(currentHeightFixed32, requiredHeightFixed32);  
        return source.scaleImage32(scaleXFixed32, scaleYFixed32);  
    } 
   public MyClass
   {
       ei = EncodedImage.getEncodedImageResource("res/background_image");   
       ei1= scaleImage(ei,requires_width,required_height);
       vfm= new VerticalFieldManager(VerticalFieldManager.USE_ALL_HEIGHT|VerticalFieldManager.USE_ALL_WIDTH);
       vfm.setBackground(BackgroundFactory.createBitmapBackground(ei1.getBitmap()));
       vfm.add(new LabelField("hello notice the background behind me");
       add(vfm);
   }
}

试试这个。我认为它会为你工作!

【讨论】:

    【解决方案2】:

    试试这样:

    VerticalFieldManager vertical=new VerticalFieldManager()
    {
        protected void paint(Graphics g) 
        {
            g.drawBitmap(0, 0,Display.getWidth(), Display.getHeight(), bitmap, 0, 0);
            super.paint(g);
        }
        protected void sublayout(int maxWidth, int maxHeight) 
        {
            super.sublayout(Display.getWidth(),Display.getHeight());
            setExtent(Display.getWidth(),Display.getHeight());
        }
    };      
    add(vertical);
    

    你可以得到。

    【讨论】:

      【解决方案3】:

      这是使用 getMainManager 的简单方法,但整个背景不是特定的字段管理器

      getMainManager().setBackground(BackgroundFactory.createBitmapBackground(Bitmap.getBitmapResource("sample.png")));
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2010-11-18
        • 1970-01-01
        • 1970-01-01
        • 2011-11-16
        相关资源
        最近更新 更多