我在 Android 中有一个图片路径。这个图片存在于设备的 SD 卡上。我该如何找到它的资源 ID?我需要将其发送给 decodeResource 函数。我正在尝试检测用户从画廊中选择的图像上的面部。我编写的代码如下:
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);
}
我需要在decodeResource函数中使用ID。有什么提示吗?