我正在关注此博客文章中的效果工厂教程:http://grishma102.blogspot.in/2013/10/apply-effects-on-image-using-effects.html 在上面的帖子中,drawable是静态的,并且是从drawable资源中选取的,我想从设备库中选择资源并对其应用效果,我需要在上面的博客文章代码中进行哪些更改才能实现。
答案 0 :(得分:0)
创建一个Intent来从图库中选择图像
创建全局变量
middle
点击按钮或其他内容,调用以下意图。
private int OPEN_GALLERY = 101
使用Intent intent = new Intent(
Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
intent.setType("image/*");
startActivityForResult(
Intent.createChooser(intent, "Select Picture"),
OPEN_GALLERY);
onActivityResult()
将位图传递给@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case OPEN_GALLERY:
if (data != null) {
try {
Uri selectedImage = data.getData();
String[] filePath = {MediaStore.Images.Media.DATA};
Cursor c = getApplicationContext().getContentResolver().query(
selectedImage, filePath, null, null, null);
c.moveToFirst();
int columnIndex = c.getColumnIndex(filePath[0]);
String picturePath = c.getString(columnIndex);
c.close();
BitmapFactory.Options options = new BitmapFactory.Options();
Bitmap bm = BitmapFactory.decodeFile(picturePath,options);
//Pass bitmap to loadtextures method
loadTextures(bm);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
break;
}
}
}
方法,如下所示
loadTextures()