android listview点击ImageView调用图库换图片
Intentintent=newIntent(Intent.ACTION_PICK,MediaStore.Images.Media.INTERNAL_CONTENT_UR...
Intent intent =new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.INTERNAL_CONTENT_URI);
BitmapFactory.Options bmpFactoryOptions = new BitmapFactory.Options();
Bitmap bp;
try {
bp = BitmapFactory.decodeStream(getContentResolver().openInputStream(data.getData()), null, bmpFactoryOptions);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
用此方法如何把图库获取到的bp赋给相应的listview 展开
BitmapFactory.Options bmpFactoryOptions = new BitmapFactory.Options();
Bitmap bp;
try {
bp = BitmapFactory.decodeStream(getContentResolver().openInputStream(data.getData()), null, bmpFactoryOptions);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
用此方法如何把图库获取到的bp赋给相应的listview 展开
2个回答
展开全部
public class MainActivity extends Activity {
private static int RESULT_LOAD_IMAGE = 1;
ImageView imageView;
String picturePath;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
imageView = (ImageView) findViewById(R.id.imageView1);
Button buttonLoadImage = (Button) findViewById(R.id.button1);
buttonLoadImage.setOnClickListener(new Button.OnClickListener() {
@Override
public void onClick(View v) {
// TODO 自动生成的方法存根
Intent i = new Intent(
Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(i, RESULT_LOAD_IMAGE);
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
private void setBitmap(String myJpgPath) {
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 2;
Bitmap bm = BitmapFactory.decodeFile(myJpgPath, options);
//Bitmap bm1=BitmapFactory.decodeResource(iv.getResources(),iv.getId());
imageView.setImageBitmap(bm);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK && null != data) {
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]);
picturePath = cursor.getString(columnIndex);
cursor.close();
setBitmap(picturePath);
}
}
private static int RESULT_LOAD_IMAGE = 1;
ImageView imageView;
String picturePath;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
imageView = (ImageView) findViewById(R.id.imageView1);
Button buttonLoadImage = (Button) findViewById(R.id.button1);
buttonLoadImage.setOnClickListener(new Button.OnClickListener() {
@Override
public void onClick(View v) {
// TODO 自动生成的方法存根
Intent i = new Intent(
Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(i, RESULT_LOAD_IMAGE);
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
private void setBitmap(String myJpgPath) {
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 2;
Bitmap bm = BitmapFactory.decodeFile(myJpgPath, options);
//Bitmap bm1=BitmapFactory.decodeResource(iv.getResources(),iv.getId());
imageView.setImageBitmap(bm);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK && null != data) {
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]);
picturePath = cursor.getString(columnIndex);
cursor.close();
setBitmap(picturePath);
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询