我在android中有一个图像路径。此图像在设备的SD卡上退出。我如何找到它的resourceID?我需要将它发送到decodeResource函数。我试图检测用户从图库中选择的图像上的脸部。我写的代码是如何从图像路径获取资源ID?
Intent intent = new Intent(this, DetectFaces.class);
intent.putExtra(PICTURE_PATH,picturePath);//the path of the image
startActivity(intent);
在detectFaces类
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事件与
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);
}
相关的,我需要ID在decodeResource功能。任何提示?
但你在哪里找到其中的图像resourceID? – Ankuj
您不需要资源ID来解码文件。只有当这个特定的图像在您的资源文件夹中时,您才需要资源ID。但是你提到了SD卡上的图像。你不会得到任何资源ID,这在你的apk中不存在。 –
Durairaj P,你应该编辑你的评论作为答案'因为我认为这就是他正在做的。 – Raz