1

My requirement is to load multiple Effect on bitmap. I am following apply-effects-on-image-using-effects for it. I got success for applying the effect but My requirements is to give brightness effect separately. That means user can able to give Brightness effect after applying any other effect without saving the file.

I know that after saving file and render that file again makes it possible. But i need it without saving image file.

Right now, if i apply Brightness on any applied effect the applied effect is gone and Brightness shows its effect. It because of the below code:

mEffect = effectFactory.createEffect(EffectFactory.EFFECT_BRIGHTNESS);

Here, mEffect is always initialize to give the new effect on texture. Without that i am not able to load the effect.

So, My question is, how to load multiple effect on same texture without saving it.

Shreyash Mahajan
  • 23,386
  • 35
  • 116
  • 188

1 Answers1

3

Create 3 textures, instead of 2:

private int[] mTextures = new int[3];

private void loadTextures() {
    // Generate textures
    GLES20.glGenTextures(3, mTextures, 0);
    ...

after that, you can apply sequentially two effects one after another, like that:

private void applyEffect() {
    if (mNeedSecondEffect) {
       mEffect.apply(mTextures[0], mImageWidth, mImageHeight, mTextures[2]);
       mSecondEffect.apply(mTextures[2], mImageWidth, mImageHeight, mTextures[1]);
    } else {
       mEffect.apply(mTextures[0], mImageWidth, mImageHeight, mTextures[1]);
    }
}

using 2 textures for effects you can apply a cascade of any amount of effects, changing source and destination textures.

EDIT For multiple effects try this:

Let's imagine you have an array of effects cascade

 Effect mEffectArray[] = ...; // the effect objects to be applied
 int mEffectCount = ... ; // number of effects used right now for output 

Then your applyEffect() method will be something like this:

private void applyEffect() {
    if (mEffectCount > 0) { // if there is any effect
        mEffectArray[0].apply(mTextures[0], mImageWidth, mImageHeight, mTextures[1]); // apply first effect
        for (int i = 1; i < mEffectCount; i++) { // if more that one effect
            int sourceTexture = mTextures[1]; 
            int destinationTexture = mTextures[2];
            mEffectArray[i].apply(sourceTexture, mImageWidth, mImageHeight, destinationTexture);
            mTextures[1] = destinationTexture; // changing the textures array, so 1 is always the texture for output, 
            mTextures[2] = sourceTexture; // 2 is always the sparse texture
        }
    }
}
AterLux
  • 4,566
  • 2
  • 10
  • 13
  • Thanks for the reply. let me try with this way. – Shreyash Mahajan Jun 05 '15 at 04:53
  • Nice, that works as i want. But can you please update it like have more two effect on same texture. Something like apply brightness, contrast and sharpness on sepia effect. – Shreyash Mahajan Jun 05 '15 at 05:51
  • Please update it and i will accept this answer. That might going to help others as well who are not very familiar to work with texture and OpenGL. Thanks. – Shreyash Mahajan Jun 05 '15 at 05:52
  • in this loop, i guess mSecondEffect should be mEffectArray[i]. Am I right? Please let me know. Because with given login i come to know that, it is only reflacting one effect that is mSecondEffect. Waiting for your reply. – Shreyash Mahajan Jun 05 '15 at 11:02
  • Sorry. That's my copypasting fault. Fixed. – AterLux Jun 05 '15 at 11:16
  • No problem. Thanks for reply. – Shreyash Mahajan Jun 05 '15 at 11:23
  • I haven't check for more effect yet. But as it is working for two different effect, it should also work for more effect. I will check it later. If is there any problem, i will let you know. – Shreyash Mahajan Jun 05 '15 at 11:25
  • I have another small problem with rendring more texture in same screen. Look at this code. http://pastebin.com/efZ2XU8k I am giving effect like this way for small individual images. There are total 8-9 small individual texture like this. All have their seperate context. Most of the time it works fine. But some of the time it gives me error like wrong context. Why is it so? Can you please explain me this in details. – Shreyash Mahajan Jun 05 '15 at 11:56
  • will wait for your reply on this. – Shreyash Mahajan Jun 05 '15 at 11:58
  • i just come to know that every Effect must have their own context. Isen't it. Should i need to update it in above code? – Shreyash Mahajan Jun 08 '15 at 04:34
  • i need your help. Can you please be here to help me – Shreyash Mahajan Jul 08 '15 at 06:24
  • I need your help. I got how to create and save the Image after applying effect on it. But there is one problem, Its saving whole texture. Instead I want to save the only bitmap with effect that is shown in to that texture. Can you please help me in that. – Shreyash Mahajan Sep 16 '15 at 04:47
  • Sorry, can't understand about the bitmap. – AterLux Sep 16 '15 at 05:01
  • I am loading bitmap on texture. Then I am giving effect on that as like above your answer. Then I am saving that image with multiple effect. Now, Assume that I have landscape image so there will be some top portion and bottom portion will remain as black. Now when I save such image, that is getting saved with that black portion as well. Instead i would like to save it with only bitmap portion. – Shreyash Mahajan Sep 16 '15 at 05:03
  • Can't figure out. Better create another question about that. – AterLux Sep 16 '15 at 05:06
  • can you please come here in chat http://chat.stackoverflow.com/rooms/89760/room-for-idroid-explorer-and-aterlux – Shreyash Mahajan Sep 16 '15 at 05:29
  • @AtexLux please check my this question on SO: http://stackoverflow.com/questions/32601187/how-to-save-bitmap-from-glsurfaceview-only-bitmap-not-whole-texture – Shreyash Mahajan Sep 16 '15 at 06:32
  • have you check my question on SO? – Shreyash Mahajan Sep 16 '15 at 06:45
  • Sorry, I don't know the answer. – AterLux Sep 16 '15 at 06:46
  • ok no problem. but do you have any idea for how to get bitmap x and y coordinate? – Shreyash Mahajan Sep 16 '15 at 06:54