filipst
filipst

Reputation: 1573

Android GLSurfaceView several images in activity

I am trying to make photo collage with 9 images (3x3), and apply different effects on all of them.
Currently, I am trying to edit this demo project:
https://github.com/Grishu/ImageEffects
But I don't know how to set 9 images on the screen. When I set several GLSurfaceViews in Layout, error shows:

03-26 11:26:21.315    6237-6237/com.test.effectsfilter_demo E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: com.test.effectsfilter_demo, PID: 6237
    java.lang.NullPointerException

Any help please?

P.S. Is there another way to make Duotone effect?

Upvotes: 0

Views: 497

Answers (1)

fadden
fadden

Reputation: 52323

First and foremost, do not create multiple instances of GLSurfaceView. Each SurfaceView instance has two parts, the Surface and the View. Creating nine sibling Views is okay, but each Surface is a separate graphics layer composited by the system, and having nine of them will be inefficient. The system will end up using GLES to do the composition, so you're better off (for efficiency as well as flexibility and perhaps simplicity) doing the composition yourself.

I don't know why you're getting that particular error. You would need to look at the line of code that's throwing the exception. If the message in your question is all you're getting, then something is filtering the exception, and you'll need to attach a debugger and have it break on NPE.

At any rate, you want to draw all nine images on one GLSurfaceView. Taking a quick look at the demo code (which looks nicely structured), the function computeOutputVertices() in TextureRenderer.java is setting the position and size of the output. Modify that to position each of the nine textures where you want them to go, and modify renderTexture() to operate in a loop.

See also this demo for another way to filter images.

Upvotes: 0

Related Questions