如何在android中缩放图像

时间:2014-02-11 09:44:48

标签: android bitmap imageview scale

这是我的代码我想缩放我的可绘制图像并设置图像视图请帮助我 在我的代码中,我想缩放 bitmap1 ,请检查我的代码

         protected Bitmap murge() 
         { 
        Murge_Bitmap = null;
        Murge_Bitmap = Bitmap.createBitmap(600, 600, Bitmap.Config.ARGB_8888);
        Canvas c = new Canvas(Murge_Bitmap);
        Resources res = getResources(); 
        bitmap1 = BitmapFactory.decodeResource(res, R.drawable.sample_pic); 
        Bitmap bitmap2=Bitmap.createScaledBitmap(bitmap1, 600, 600, true);

        Drawable drawable1 = new BitmapDrawable(Bitmap_recieve);
        Drawable drawable2 = new BitmapDrawable(bitmap2);
         //   c.drawBitmap(Murge_Bitmap, 500,500, null);
        drawable1.setBounds(200, 200, 400, 400);
        drawable2.setBounds(200, 240, 400, 400);
        drawable1.draw(c);
        drawable2.draw(c);


        return Murge_Bitmap;
             }

1 个答案:

答案 0 :(得分:0)

你可以用这个: 解码资源并使用scalingfactor

将其传递给此函数
public static Bitmap ScaleBitmap(Bitmap bm, float scalingFactor) {
    int scaleHeight = (int) (bm.getHeight() * scalingFactor);
    int scaleWidth = (int) (bm.getWidth() * scalingFactor);
    return Bitmap.createScaledBitmap(bm, scaleWidth, scaleHeight, true);
}
缩放因子的

指的是这个 Scale factor for xxhdpi android?