本文介绍了如何从图像路径中获取资源 ID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在 android 中有一个图像路径.该图像存在于设备的 sdcard 上.我怎样才能找到它的resourceID?我需要将它发送到 decodeResource 函数.我正在尝试检测用户从图库中选择的图像上的面孔.我写的代码是
I have an imagepath in android .This image exits on the sdcard of the device. How can i find resourceID of it ? I need to send it to decodeResource function. I am trying to detect faces on the image user selects from the gallery. The code that I have written is
Intent intent = new Intent(this, DetectFaces.class);
intent.putExtra(PICTURE_PATH,picturePath);//the path of the image
startActivity(intent);
在detectFaces类中
In detectFaces class
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_detect_faces);
// getActionBar().setDisplayHomeAsUpEnabled(true);
Intent intent = getIntent();
ImageView imageView = (ImageView) findViewById(R.id.imgView);
picturePath = intent.getStringExtra(GetFaceActivity.PICTURE_PATH);
imageView.setImageBitmap(BitmapFactory.decodeFile(picturePath));
//imageView.setOnTouchListener(this);
}
有一个按钮,其onClick事件关联
There is a button whose onClick event is associated with
public void DetectFacesInImage(View view)
{
BitmapFactory.Options bitmapFactoryOptions=new BitmapFactory.Options();
bitmapFactoryOptions.inPreferredConfig= Bitmap.Config.RGB_565;
myBitmap=BitmapFactory.decodeResource(getResources(),R.drawable.faceswapping,bitmapFactoryOptions);
int width=myBitmap.getWidth();
int height=myBitmap.getHeight();
detectedFaces=new FaceDetector.Face[number_of_faces];
FaceDetector faceDetector=new FaceDetector(width,height,number_of_faces);
number_of_faces_detected = faceDetector.findFaces(myBitmap, detectedFaces);
}
我需要 decodeResource 函数中的 ID.有什么提示吗?
I need ID in the decodeResource function. Any hints ?
推荐答案
试试这个,也许对你有帮助
Try this, it may help you
File fileObj = new File("/sdcard/Images/test_image.jpg");
if(fileObj .exists()){
Bitmap bitMapObj= BitmapFactory.decodeFile(fileObj .getAbsolutePath());
ImageView imgView= (ImageView) findViewById(R.id.imageviewTest);
imgView.setImageBitmap(bitMapObj);
}
这篇关于如何从图像路径中获取资源 ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!