问题
I have asked a question about taking a photo and returning that image to the point on the map where the users has tapped. Previously the camera intent would crash got it now to work without crashing the app but have the problem now of placing the image back into the map. Here is my updated code:
@Override
public void onMapLongClick(LatLng point) {
Intent getCameraImage = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File cameraFolder;
if (android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED))
cameraFolder = new File(android.os.Environment.getExternalStorageDirectory(),"myfolder/");
else
cameraFolder= context.getCacheDir();
if(!cameraFolder.exists())
cameraFolder.mkdirs();
String imageFileName = imagename;
photo = new File(cameraFolder, "myfolder/" + imageFileName);
getCameraImage.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photo));
Uri.fromFile(photo);
startActivityForResult(getCameraImage, TAKE_PICTURE);
}
protected void onActivityResult(int requestCode, int resultCode, LatLng point) {
if(resultCode == RESULT_OK) {
// This code here i think is wrong?
googleMap.addMarker(new MarkerOptions().position(point)
.icon(BitmapDescriptorFactory.fromFile("photo")));
}
}
when i take the photo and return to maps, then this is what i get from the log:
11-23 09:32:31.837: D/skia(12895): GFXPNG PNG bitmap created width:256 height:256 bitmap id is 486
So in my mind it seems to be working, but not placing the image in the maps. Could anyone please help?
回答1:
I do not think that the message you see in the log relates to the photo image - size 256x256 px is too small for camera, unless you specified it somehow when taking picture. It is unlikely.
The problem in your code is with BitmapDescriptorFactory.fromFile("photo")
, you should use something like BitmapDescriptorFactory.fromPath(photo.getAbsolutePath())
.
来源:https://stackoverflow.com/questions/27086649/how-to-place-taken-photo-from-camera-intent-and-place-in-maps-where-users-has-ta