图片打标签之获取图片在ImageView中的坐标

android matrix 最全方法详解与进阶(完整篇)

imageView = findViewById(R.id.imageview);
        
        imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Drawable drawable = imageView.getDrawable();
                Matrix matrix = imageView.getImageMatrix();
                if (drawable != null) {
                    RectF rectf = new RectF();
                    rectf.set(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
                    matrix.mapRect(rectf);     //最关键的一句
                    Log.i("lcf", "left  " + rectf.left + "  " + rectf.top + "  " + rectf.right + "  " + rectf.bottom);

                }
            }
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是安卓从相册获取图片ImageView的示例代码: 1. 添加相册读取权限到AndroidManifest.xml文件: ``` <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> ``` 2. 在布局文件添加一个ImageView: ``` <ImageView android:id="@+id/imageView" android:layout_width="match_parent" android:layout_height="match_parent" android:scaleType="centerCrop" /> ``` 3. 在Activity实现从相册获取图片的逻辑: ``` private static final int REQUEST_CODE_PICK_IMAGE = 1; // 点击按钮选择图片 public void pickImage(View view) { Intent intent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI); startActivityForResult(intent, REQUEST_CODE_PICK_IMAGE); } // 处理选择图片的结果 @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == REQUEST_CODE_PICK_IMAGE && resultCode == RESULT_OK && data != null) { // 获取选择的图片URI Uri imageUri = data.getData(); if (imageUri != null) { try { // 将图片URI转换为Bitmap对象 Bitmap bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), imageUri); // 将Bitmap对象设置到ImageView ImageView imageView = findViewById(R.id.imageView); imageView.setImageBitmap(bitmap); } catch (IOException e) { e.printStackTrace(); } } } } ``` 4. 运行程序并点击按钮选择图片,选择完后图片将会显示在ImageView
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值