简体   繁体   English

黑莓:WebBitmapField中心图像

[英]Blackberry: WebBitmapField center image

http://www.coderholic.com/blackberry-webbitmapfield/ http://www.coderholic.com/blackberry-webbitmapfield/

This is a great script for grabbing an image from the web for a Blackberry App. 这是从Web上为Blackberry App捕获图像的绝佳脚本。 Now I would like to know how to center the returned image. 现在,我想知道如何居中返回的图像。 I have tried everything. 我已经尝试了一切。

This portion of code seems to return the image: 这部分代码似乎返回了图像:

byte[] dataArray = data.getBytes(); byte [] dataArray = data.getBytes();
bitmap = EncodedImage.createEncodedImage(dataArray, 0, 位图= EncodedImage.createEncodedImage(dataArray,0,
dataArray.length); dataArray.length);
setImage(bitmap); setImage(bitmap);

This displays the image: 这将显示图像:

getimage = new WebBitmapField("http://"); getimage = new WebBitmapField(“ http://”); add (getimage); 添加(getimage);

Where can I put FIELD_HCENTER to center this thing. 我在哪里可以将FIELD_HCENTER放在此内容的中心。 Please show sample code. 请显示示例代码。 Thanks!! 谢谢!!

If you insist on using this WebBitmapField, then you'll need to add a new constructor so that style bits can be passed to the BitmapField: 如果您坚持使用此WebBitmapField,则需要添加一个新的构造函数,以便可以将样式位传递给BitmapField:

public class WebBitmapField extends BitmapField implements WebDataCallback  
{  
    ...
    public WebBitmapField(String url, long style)  
    {  
        super(style);
        try  
        {  
            Util.getWebData(url, this);  
        }  
        catch (Exception e) {}  
    }  

    public WebBitmapField(String url) 
    {
        this(url, 0L);
    }
    ...
}

If you place your WebBitmapField in a custom manager and set the position of the field then u can possibly achieve the center location like: 如果将WebBitmapField放在自定义管理器中并设置字段的位置,则您可能会获得中心位置,例如:

class CustomManager extends Manager
{
    CustomManager()
     {
        super(Manager.USE_ALL_WIDTH);
     } 
    sublayout(int width , int height)
     {
       Field field = getField(0);
       layoutChild(field , Display.getWidth(), Display.getHeight());
       setPositionChild(field, (Display.getWidth()- field.getWidth())/2,
           Display.getHeight());

      setExtent( Display.getWidth(), Display.getHeight());
     }
}


In MainScreen use it as:
CustomManager  obj = new CustomManager();
getimage = new WebBitmapField("http://");
obj.add(getimage );
add(obj);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM