在我的应用程序中,我从相机或图库中获取图像并保存在imageview中。现在如何将此imageview图像保存为我的联系人图片。
detail.java
camera.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, CAMERA_REQUEST);
}
});
//gallery picture
galary.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent photoPickerIntent = new Intent(Intent.ACTION_GET_CONTENT);
photoPickerIntent.setType("image/*");
startActivityForResult(photoPickerIntent, 1);
}
});
save.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent image= new Intent(Intent.)
}
});
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == CAMERA_REQUEST && resultCode == RESULT_OK) {
Bitmap photo = (Bitmap) data.getExtras().get("data");
photo1.setImageBitmap(photo);
}
else
{
if (data != null && resultCode == RESULT_OK)
{
Uri selectedImage = data.getData();
String[] filePathColumn = {MediaStore.Images.Media.DATA};
Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String filePath = cursor.getString(columnIndex);
cursor.close();
if(photo != null && !photo.isRecycled())
{
photo = null;
}
photo = BitmapFactory.decodeFile(filePath);
photo1.setBackgroundResource(0);
photo1.setImageBitmap(photo);
}
else
{
Log.d("Status:", "Photopicker canceled");
}
}
}
}
答案 0 :(得分:0)
setimage.setOnClickListener(new View.OnClickListener() {
public void onClick(View v){
Context context= getApplicationContext();
Bitmap icon= BitmapFactory.decodeResource(context.getResources(),
R.id.your_img_view);
try {
Intent myIntent = new Intent(); myIntent.setAction(Intent.ACTION_ATTACH_DATA);
myIntent.setType("image/jpeg");
myIntent.putExtra(Intent.EXTRA_STREAM, icon);
startActivity(myIntent);
} catch (ActivityNotFoundException e) {
e.printStackTrace();
}
}
});
添加:
<uses-permission android:name="android.permission.WRITE_CONTACTS" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
在你的清单中。