Android 零碎知识点

Java byte数组转hex

public String byteArrToHex(byte[] data){
  StringBuilder sb = new StringBuilder();
  for(byte b : data){
    sb.append(String.format("%02x", b&0xff));
  }
  return sb.toString();
}

重要代码:String.format("%02x", b&0xff)

Jetpack Compose

和Flutter一样摆脱了xml,通过代码来实现界面
https://developer.android.google.cn/jetpack/compose/tutorial?hl=zh-cn
https://developer.android.com/jetpack/compose

Java 中Bitmap变为灰色

原因:最近做摄像头相关的,再列表中当设备离线之后变为灰色,让用户看起来更加直观明了

public Bitmap grey(Bitmap bitmap) {
        int width = bitmap.getWidth();
        int height = bitmap.getHeight();
        Bitmap faceIconGreyBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(faceIconGreyBitmap);
        Paint paint = new Paint();
        ColorMatrix colorMatrix = new ColorMatrix();
        colorMatrix.setSaturation(0);
        ColorMatrixColorFilter colorMatrixFilter = new ColorMatrixColorFilter(colorMatrix);
        paint.setColorFilter(colorMatrixFilter);
        canvas.drawBitmap(bitmap, 0, 0, paint);
        return faceIconGreyBitmap;
    }

你可能感兴趣的:(Android 零碎知识点)