Android scaling of images to screen density

前端 未结 3 2003
执念已碎
执念已碎 2020-12-05 08:18

I have an application with an embedded drawable 48x48 pixel at 71,12 pixels/inch I load the same image via a stream to a webserver, then load that stream

re         


        
3条回答
  •  余生分开走
    2020-12-05 09:17

    you can trigger android bitmapfactory to scale bitmap automatically, codes for this:

    BitmapFactory.Options options = new BitmapFactory.Options();
    DisplayMetrics metrics = context.getApplicationContext().getResources().getDisplayMetrics();
    options.inScreenDensity = metrics.densityDpi;
    options.inTargetDensity =  metrics.densityDpi;
    options.inDensity = DisplayMetrics.DENSITY_DEFAULT;
    
    Bitmap bm = BitmapFactory.decodeStream(in, null, options);
    in.close();
    BitmapDrawable bitmapDrawable = new BitmapDrawable(context.getResources(), bm);
    

提交回复
热议问题