从imageview获取图像路径? [英] getting an image path from a imageview?

查看:83
本文介绍了从imageview获取图像路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ImageView,我想获取图像的路径并添加一个String.我想要这样做是因为我需要像默认图片一样将其发送到我的网络服务

I have an ImageView and I want get the path of image and add in a String. I want do this because I need send this to my webservice like a default image

我该怎么办?

ImageView

<ImageView
    android:id="@+id/ivPerfil"
    android:padding="5dp"
    android:layout_width="120dp"
    android:layout_height="120dp"
    android:src="@drawable/icon_usuario"
    android:scaleType="fitXY"
    />

获取路径

ivPerfil = (ImageView)findViewById(R.id.ivPerfil);
Drawable img = getResources().getDrawable(R.drawable.icon_usuario);
String pathImage = img.toString();

推荐答案

您可以尝试以下操作:

    Uri path = Uri.parse("android.resource://your.package.name/" + R.drawable.icon_usuario);
    String imgPath = path.toString();

您的包名称"是您的包的名称(即com.example.mypackage)

"your.package.name" is the name of your package (i.e: com.example.mypackage)

您可以在android中使用此路径,如下所示:

You can use this path in android like this:

ivPerfil = (ImageView)findViewById(R.id.ivPerfil);
ivPerfil.setImageURI(path);

这篇关于从imageview获取图像路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆