【发布时间】:2016-11-11 05:00:18
【问题描述】:
我是 Android 应用开发的新手。我想在地图上的信息窗口触发的谷歌地图中实现快照,然后我需要返回图像并裁剪它。 这是我的代码,但每次我触摸信息窗口时它都不起作用。
这里是快照的代码。调试的时候发现它跳过了snapshot方法,所以我想可能是我对snakshotReadyCallback的使用是错误的。
public void takeSnapShot(){
mMap.setOnInfoWindowClickListener(new GoogleMap.OnInfoWindowClickListener() {
@Override
public void onInfoWindowClick(Marker marker) {
//final ImageView snapshotHolder = (ImageView) findViewById(R.id.picture);
final GoogleMap.SnapshotReadyCallback callback = new GoogleMap.SnapshotReadyCallback() {
@Override
public void onSnapshotReady(Bitmap snapshot) {
//snapshotHolder.setImageBitmap(snapshot);
try {
FileOutputStream out = new FileOutputStream("test.png");
snapshot.compress(Bitmap.CompressFormat.PNG, 90, out);
Toast.makeText(MapsActivity.this, "Capture OK", Toast.LENGTH_LONG).show();
} catch (Exception e) {
e.printStackTrace();
}
}
};
mMap.snapshot(callback);
}
});
}
这里是crop的代码。
//crop the image
public void performCrop(){
try{
Intent cropIntent= new Intent("com.android.camera.action.CROP");
cropIntent.setDataAndType(picUri,"map/*");
cropIntent.putExtra("crop", "true");
cropIntent.putExtra("aspectX", 2);
cropIntent.putExtra("aspectY", 1);
cropIntent.putExtra("outputX", 256);
cropIntent.putExtra("outputY", 256);
cropIntent.putExtra("return-data", true);
startActivityForResult(cropIntent, CROP_PIC);
}catch (ActivityNotFoundException anfe){
Toast.makeText(this, "this device doesn't support crop", Toast.LENGTH_SHORT).show();
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == CROP_PIC) {
Bundle extras = data.getExtras();
Bitmap thePic = extras.getParcelable("data");
ImageView picView = (ImageView) findViewById(R.id.picture);
picView.setImageBitmap(thePic);
}
}
【问题讨论】:
-
你找到解决办法了吗
标签: android google-maps android-studio crop snapshot