Android view转bitmap,byte[]转Bitmap

本文详细介绍如何在Android中自定义Marker布局,并通过LayoutInflater将自定义的View转换为Bitmap,以便在Marker中使用。同时,提供了具体的代码实现,包括自定义view的XML布局和view转bitmap的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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);
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值