-2
我从以下博客文章中获得效果工厂教程:http://grishma102.blogspot.in/2013/10/apply-effects-on-image-using-effects.html 在上面的帖子中,drawable是静态的,并且从drawable资源中挑选出来,我想从设备库中选择资源并应用对它的影响,我必须在上述博客文章代码中做出什么改变才能实现。从图库中选取图片并应用效果工厂效果
我从以下博客文章中获得效果工厂教程:http://grishma102.blogspot.in/2013/10/apply-effects-on-image-using-effects.html 在上面的帖子中,drawable是静态的,并且从drawable资源中挑选出来,我想从设备库中选择资源并应用对它的影响,我必须在上述博客文章代码中做出什么改变才能实现。从图库中选取图片并应用效果工厂效果
创建一个Intent挑选的图像从画廊这样
创建一个全局变量
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()
方法这样
private void loadTextures(Bitmap bm) {
// Generate textures
GLES20.glGenTextures(2, mTextures, 0);
// Load input bitmap
Bitmap bitmap = bm;
mImageWidth = bitmap.getWidth();
mImageHeight = bitmap.getHeight();
mTexRenderer.updateTextureSize(mImageWidth, mImageHeight);
// Upload to texture
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextures[0]);
GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, bitmap, 0);
// Set texture parameters
GLToolbox.initTexParams();
}
我能得到从画廊的位图,但在那之后没能将位图设置为博客文章代码。 –
抱歉,我没有注意到您正在使用GLSurfaceView。编辑我的答案。请检查一下。在'onActivityResult()'方法中调用'loadTextures(bm)'。 – SripadRaj
我做了,但它不会呈现位图。 –