Android view转bitmap,byte[]转Bitmap
1、自定义marker布局文件即自定义view文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">
<TextView
android:id="@+id/tete"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/dw64"/>
</LinearLayout>
2、引入自定义view
LayoutInflater mInflater = LayoutInflater.from(this);
View view = mInflater.inflate(R.layout.zdyview, null);
TextView textView = view.findViewById(R.id.tete);
textView.setText("大象");
Bitmap bitmap =convertViewToBitmap(view);
view转bitmap方法
这个bitmap即可在Marker中使用
//view 转bitmap
public static Bitmap convertViewToBitmap(View view) {
view.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED), View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight());
view.buildDrawingCache();
Bitmap bitmap = view.getDrawingCache();
return bitmap;
}
//------------------------------------------------------------------------------------------ private void ShowFingerBitmap(byte[] image, int width, int height) { if (width==0) return; if (height==0) return; int[] RGBbits = new int[width * height]; viewFinger.invalidate(); for (int i = 0; i < width * height; i++ ) { int v; if (image != null) v = image[i] & 0xff; else v= 0; if(v<200) RGBbits[i] = Color.argb(255,255, v, v); else RGBbits[i] = Color.argb(0,v, v, v); } Bitmap bmp = Bitmap.createBitmap(RGBbits, width, height,Config.RGB_565); Log.e("获取成功","指纹图片成功==== "+bmp); viewFinger.setImageBitmap(bmp); }