我怎么能扩展我的Andr​​oid的位图基础上的宽度和高度的像素? [英] How can I scale my bitmap in Android based on the width and height pixels?

查看:179
本文介绍了我怎么能扩展我的Andr​​oid的位图基础上的宽度和高度的像素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够根据屏幕大小缩放我的形象。在一个正常的Java小程序,我会做类似如下....

  INT WINDOWWIDTH = 1280;
INT WINDOWHEIGHT = 720;形象画像;公共无效漆(图形G)
{
    g.drawImage(图像,X,Y,WINDOWWIDTH / 4,WINDOWHEIGHT / 16,空);
}

我一直在寻找了一段时间,我都找到答案似乎打开了一些奇怪的结果。从我读我可能需要做独立分辨率像素的东西,但我不是100%肯定。

我试图避免被不必创建一套全新的图像和图标只是针对不同屏幕密度的事情。我上面表明,该方法适用于调整桌面应用程序没有问题。

编辑:

这是我一直在用绘制在android系统的图像内容。

 矩阵矩阵=新的Matrix();
位图图像;Constuctor ....()
{
图像= BitmapFactory.de codeResource(context.getResources(),R.drawable.play);
}公共无效渲染(帆布C)
{
    c.drawBitmap(图像,矩阵,零);
}


解决方案

喜见我已经发布thsi问题<一href=\"http://stackoverflow.com/questions/14399089/how-to-scale-the-images-so-that-they-should-occupy-the-entire-screen\">scale位图

如果您使用的是帆布得到画布的宽度和高度。或者,如果你想拥有它正式的正常布局,然后得到通过的宽度和高度

  DisplayMetrics指标=新DisplayMetrics();
 。getWindowManager()getDefaultDisplay()getMetrics(指标)。
 dispWidth = metrics.widthPixels;
 dispheight = metrics.heightPixels;

,然后根据您的要求喜欢这个规模我们的位图。在此我必须有8砖头所以我用列数

取分的宽度

 字符串strwidth =将String.valueOf(((浮点)(bmp.getWidth())/ NO_COLUMNS));
        如果(strwidth.contains(。))
        {
            scalebit = Bitmap.createScaledBitmap(BMP,(INT)(Math.ceil(((浮点)bmp.getWidth())/ NO_COLUMNS))* NO_COLUMNS,bmp.getHeight(),TRUE);
        }
        其他
        {
            scalebit = BMP;
        }

I want to be able to scale my image based on the screen size. In a normal java applet I would do something like the following....

int windowWidth = 1280;
int windowHeight = 720;

Image image;

public void paint(Graphics g)
{
    g.drawImage(image, x, y, windowWidth / 4, windowHeight / 16, null);
}

I've been searching for an answer for a while and everything I find seems to turn up some weird result. From what I read I might need to do something with Resolution Independent Pixels but I'm not %100 sure.

The thing I am trying to avoid is having to create a whole new set of images and icons just for different screen densities. The method I showed above works for resizing desktop apps without a problem.

Edit:

This is what I have been using to draw an image in android.

Matrix matrix = new Matrix();
Bitmap image;

Constuctor....()
{
image = BitmapFactory.decodeResource(context.getResources(), R.drawable.play);
}

public void render(Canvas c)
{
    c.drawBitmap(image, matrix, null);
}

解决方案

Hi see thsi question I have posted scale bitmap

If you are using canvas get the width and height of the canvas. or if you want to have it formal normal layouts then get the width and height by using

DisplayMetrics metrics = new DisplayMetrics();
 getWindowManager().getDefaultDisplay().getMetrics(metrics);
 dispWidth=metrics.widthPixels;
 dispheight=metrics.heightPixels;

and then scale our bitmap according to your requirement like this. In this I Have to have 8 bricks so I have taken the width by dividing with the Number of columns

      String strwidth=String.valueOf(((float)(bmp.getWidth())/NO_COLUMNS));
        if(strwidth.contains("."))
        {
            scalebit=Bitmap.createScaledBitmap(bmp, (int)(Math.ceil(((float)bmp.getWidth())/NO_COLUMNS))*NO_COLUMNS, bmp.getHeight(), true);
        }
        else
        {
            scalebit=bmp;
        }

这篇关于我怎么能扩展我的Andr​​oid的位图基础上的宽度和高度的像素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆