选择相册中的照片并获得缩略图

case R.id.thumbnail_pic://缩略图
Intent ins = new Intent(Intent.ACTION_PICK);
ins.setType("image/*");
startActivityForResult(ins, 0);

break;



@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK) {
if (requestCode == PICK_PIC) {
if (data == null) {
Toast.makeText(this, "failed", Toast.LENGTH_SHORT).show();
} else {
Uri uri = data.getData();
String[] projection = { MediaStore.Images.ImageColumns.DATA };


ContentResolver resolver = getContentResolver();


Cursor cursor = resolver.query(uri, projection, null, null, MediaStore.Images.Media.DATE_MODIFIED);


cursor.moveToFirst();


int idx = cursor.getColumnIndexOrThrow(MediaStore.Images.ImageColumns.DATA);
String photoPath = cursor.getString(idx);
// String iconName =
// photoPath.substring(photoPath.lastIndexOf("/")+1,
// photoPath.length());
Log.d("photoPath", "photoPath=" + photoPath);
articPicUrlList.add(photoPath);
Log.d("CreateEntry", "photoPath=" + photoPath + " size = " + articPicUrlList.size());
tagPath = "<img src=\"" + photoPath + "\"/>";// 为图片路径加上<img>标签
Bitmap bitmap = BitmapFactory.decodeFile(photoPath);
if (bitmap != null) {
SpannableString ss = getBitmapMime(photoPath, tagPath);
insertIntoEditText(ss);
}


}
}else if(requestCode==0){
if (data == null) {
Toast.makeText(this, "failed", Toast.LENGTH_SHORT).show();
} else{
Uri uri = data.getData();
String[] projection = { MediaStore.Images.ImageColumns.DATA };


ContentResolver resolver = getContentResolver();


Cursor cursor = resolver.query(uri, projection, null, null, MediaStore.Images.Media.DATE_MODIFIED);


cursor.moveToFirst();


int idx = cursor.getColumnIndexOrThrow(MediaStore.Images.ImageColumns.DATA);
String path = cursor.getString(idx);
bitmap= BitmapFactory.decodeFile(path);
bitmap=ThumbnailUtils.extractThumbnail(bitmap, 50, 50);
thumbnail_pic.setImageBitmap(bitmap);

}
}
}
}

你可能感兴趣的:(图文混排)