android.graphics.Bitmap.setDensity()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(6.5k)|赞(0)|评价(0)|浏览(179)

本文整理了Java中android.graphics.Bitmap.setDensity()方法的一些代码示例,展示了Bitmap.setDensity()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Bitmap.setDensity()方法的具体详情如下:
包路径:android.graphics.Bitmap
类名称:Bitmap
方法名:setDensity

Bitmap.setDensity介绍

暂无

代码示例

代码示例来源:origin: stackoverflow.com

BitmapDrawable flip(BitmapDrawable d)
{
  Matrix m = new Matrix();
  m.preScale(-1, 1);
  Bitmap src = d.getBitmap();
  Bitmap dst = Bitmap.createBitmap(src, 0, 0, src.getWidth(), src.getHeight(), m, false);
  dst.setDensity(DisplayMetrics.DENSITY_DEFAULT);
  return new BitmapDrawable(dst);
}

代码示例来源:origin: gzu-liyujiang/AndroidPicker

public static Bitmap toBitmap(byte[] bytes, int width, int height) {
  Bitmap bitmap = null;
  if (bytes.length != 0) {
    try {
      BitmapFactory.Options options = new BitmapFactory.Options();
      // 不进行图片抖动处理
      options.inDither = false;
      // 设置让解码器以最佳方式解码
      options.inPreferredConfig = null;
      if (width > 0 && height > 0) {
        options.outWidth = width;
        options.outHeight = height;
      }
      bitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.length, options);
      bitmap.setDensity(96);// 96 dpi
    } catch (Exception e) {
      LogUtils.error(e);
    }
  }
  return bitmap;
}

代码示例来源:origin: Bilibili/DanmakuFlameMaster

averageWidth, averageHeight, Bitmap.Config.ARGB_8888);
if (mDensity > 0) {
  bmp.setDensity(mDensity);

代码示例来源:origin: robolectric/robolectric

@Test
@Config(minSdk = JELLY_BEAN_MR1)
public void shouldSetDensity() {
 final Bitmap bitmap = Bitmap.createBitmap(new DisplayMetrics(), 100, 100, Bitmap.Config.ARGB_8888);
 bitmap.setDensity(1000);
 assertThat(bitmap.getDensity()).isEqualTo(1000);
}

代码示例来源:origin: bumptech/glide

downsampled.setDensity(displayMetrics.densityDpi);

代码示例来源:origin: Bilibili/DanmakuFlameMaster

if (density > 0) {
  mDensity = density;
  bitmap.setDensity(density);

代码示例来源:origin: stackoverflow.com

RelativeLayout rl = (RelativeLayout) findViewById(R.id.rl1);

final Options bitmapOptions=new Options();
DisplayMetrics matrix = getResources().getDisplayMetrics();
bitmapOptions.inDensity = matrix.densityDpi;
bitmapOptions.inTargetDensity=1;

/*`final` modifier might be necessary for the Bitmap*/
Bitmap bmp= BitmapFactory.decodeResource(getResources(), R.drawable.ver_bottom_panel_tiled_long, bitmapOptions);
bmp.setDensity(Bitmap.DENSITY_NONE);
bmp = Bitmap.createBitmap(bmp, 0, 0, rl.getWidth(), bmp.getHeight());

代码示例来源:origin: stackoverflow.com

Bitmap myBitmap = ... 
   // S3 and S4 get confused about displaying bitmaps without a specific density,
   // and fail to scale them properly. Setting the density to this value helps (is possible ANY density helps, but haven't tested this)
   myBitmap.setDensity(DisplayMetrics.DENSITY_HIGH);
   myImageView.setImageBitmap(myBitmap);

代码示例来源:origin: stackoverflow.com

private Bitmap downscaleBitmapUsingDensities(final int sampleSize,final int imageResId)
{
final Options bitmapOptions=new Options();
bitmapOptions.inDensity=sampleSize;
bitmapOptions.inTargetDensity=1;
final Bitmap scaledBitmap=BitmapFactory.decodeResource(getResources(),imageResId,bitmapOptions);
scaledBitmap.setDensity(Bitmap.DENSITY_NONE);
return scaledBitmap;
}

代码示例来源:origin: stackoverflow.com

private Bitmap downscaleBitmapUsingDensities(final int sampleSize,final int imageResId)
{
final Options bitmapOptions=new Options();
bitmapOptions.inDensity=sampleSize;
bitmapOptions.inTargetDensity=1;
final Bitmap scaledBitmap=BitmapFactory.decodeResource(getResources(),imageResId,bitmapOptions);
scaledBitmap.setDensity(Bitmap.DENSITY_NONE);
return scaledBitmap;
}

代码示例来源:origin: stackoverflow.com

private Bitmap downscaleBitmapUsingDensities(final int sampleSize,final int imageResId)
{
final Options bitmapOptions=new Options();
bitmapOptions.inDensity=sampleSize;
bitmapOptions.inTargetDensity=1;
final Bitmap scaledBitmap=BitmapFactory.decodeResource(getResources(),imageResId,bitmapOptions);
scaledBitmap.setDensity(Bitmap.DENSITY_NONE);
return scaledBitmap;
}

代码示例来源:origin: stackoverflow.com

InputStream inputStream = mContext.getResources().openRawResource(R.drawable.your_id);
 Bitmap b = BitmapFactory.decodeStream(inputStream);
 b.setDensity(Bitmap.DENSITY_NONE);
 Drawable d = new BitmapDrawable(b);
 holder.mImageView.setImageDrawable(d);

代码示例来源:origin: stackoverflow.com

Bitmap bmp = BitmapFactory.decodeFile(path);
DisplayMetrics dm = context.getResources().getDisplayMetrics();
bmp.setDensity(dm.densityDpi);
drawable = new BitmapDrawable(bmp, context.getResources());

代码示例来源:origin: stackoverflow.com

int TARGET_DENSITY = 300;
float PHYSICAL_WIDTH_IN_INCH = 5;
float PHYSICAL_HEIGHT_IN_INCH = 7;
Bitmap bitmap = Bitmap.createBitmap(PHYSICAL_WIDTH_IN_INCH * TARGET_DENSITY, PHYSICAL_HEIGHT_IN_INCH * TARGET_DENSITY, Bitmap.Config.ARGB_8888);
bitmap.setDensity(TARGET_DENSITY);
Canvas canvas = new Canvas(bitmap);
... draw something ...
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, outfile);

代码示例来源:origin: stackoverflow.com

final Bitmap output = Bitmap.createBitmap(44, 65, Bitmap.Config.ARGB_8888);
/*NEW -> */ output.setDensity(320);
final Canvas canvas = new Canvas(output);
final int color = Color.RED;
final Paint paint = new Paint();
// BitmapDrawable bmd = new BitmapDrawable(output);
/*Change into*/
BitmapDrawable bmd = new BitmapDrawable(Resources.getSystem(),output);

代码示例来源:origin: stackoverflow.com

BitmapFactory.Options options = new BitmapFactory.Options();    

options.inScaled = false; // Prevents scaling at decode time.

Bitmap bitmap = BitmapFactory.decodeResource(

          context.getResources(),

          R.raw.my_image,

          options
        );

bitmap.setDensity(Bitmap.DENSITY_NONE); // Prevents scaling at draw time.

代码示例来源:origin: stackoverflow.com

BitmapDrawable flip(BitmapDrawable d)
{
  Matrix m = new Matrix();
  m.preScale(-1, 1);
  Bitmap src = d.getBitmap();
  Bitmap dst = Bitmap.createBitmap(src, 0, 0, src.getWidth(), src.getHeight(), m, false);
  dst.setDensity(DisplayMetrics.DENSITY_DEFAULT);
  return new BitmapDrawable(dst);
}

代码示例来源:origin: stackoverflow.com

BitmapDrawable flip(BitmapDrawable d)
{
  Matrix m = new Matrix();
  m.preScale(-1, 1);
  Bitmap src = d.getBitmap();
  Bitmap dst = Bitmap.createBitmap(src, 0, 0, src.getWidth(), src.getHeight(), m, false);
  dst.setDensity(DisplayMetrics.DENSITY_DEFAULT);
  return new BitmapDrawable(dst);
}

代码示例来源:origin: iQueSoft/iQuePhoto

public void flipImageHorizontal(Bitmap bitmap) {
  Matrix matrix = new Matrix();
  matrix.preScale(-1, 1);
  Bitmap flippedBitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, false);
  if (flippedBitmap != null) {
    flippedBitmap.setDensity(DisplayMetrics.DENSITY_DEFAULT);
    Drawable drawable = new BitmapDrawable(flippedBitmap);
    getViewState().flipImage(drawable);
  }
}

代码示例来源:origin: iQueSoft/iQuePhoto

public void flipImageVertical(Bitmap bitmap) {
    Matrix matrix = new Matrix();
    matrix.preScale(1, -1);

    Bitmap flippedBitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, false);
    if (flippedBitmap != null) {
      flippedBitmap.setDensity(DisplayMetrics.DENSITY_DEFAULT);
      Drawable drawable = new BitmapDrawable(flippedBitmap);
      getViewState().flipImage(drawable);
    }
  }
}

相关文章