如何设置适合黑莓应用程序的背景图像

时间:2012-12-21 06:33:29

标签: blackberry blackberry-eclipse-plugin blackberry-jde

我在这里编写了以下代码,背景图片正在显示,但图片并未覆盖整个背景

private Bitmap background;
    int mWidth = Display.getWidth();
    int mHeight = Display.getHeight();

    public MyScreen()
    {        
        // Set the displayed title of the screen  
        //backgroundBitmap = Bitmap.getBitmapResource("slidimage.png");
        final Bitmap background = Bitmap.getBitmapResource("slidimage.png");

        HorizontalFieldManager vfm = new HorizontalFieldManager(USE_ALL_HEIGHT | USE_ALL_WIDTH) {
               public void paint(Graphics g) {
                    g.drawBitmap(0, 0,mWidth, mHeight, background, 0, 0);
                    super.paint(g);
               }
        };

        add(vfm);

1 个答案:

答案 0 :(得分:0)

public static Bitmap resizeBitmap(Bitmap image, int width, int height)
    {   
        int rgb[] = new int[image.getWidth()*image.getHeight()];
        image.getARGB(rgb, 0, image.getWidth(), 0, 0, image.getWidth(), image.getHeight());        
        int rgb2[] = rescaleArray(rgb, image.getWidth(), image.getHeight(), width, height);
        Bitmap temp2 = new Bitmap(width, height);        
        temp2.setARGB(rgb2, 0, width, 0, 0, width, height);        
        return temp2;
    }

您可以使用上述方法调整图像大小 只需传递要调整大小的图像及其宽度和高度。 并且该函数将返回已调整大小的图像。

其中rescale Array是以下方法

private static int[] rescaleArray(int[] ini, int x, int y, int x2, int y2)
    {
        int out[] = new int[x2*y2];
        for (int yy = 0; yy < y2; yy++)
        {
            int dy = yy * y / y2;
            for (int xx = 0; xx < x2; xx++)
            {
                int dx = xx * x / x2;
                out[(x2 * yy) + xx] = ini[(x * dy) + dx];
            }
        }
        return out;
    }
相关问题