Main Menu
Menu

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Show posts Menu

Messages - Luca

#1
Support / Re: new Texture(Bitmap) and Bitmap.recycle()
October 08, 2011, 01:05:25 PM
Thank you so much...
I resolve the problem using ITextureEffect, this is the code:

private Bitmap overlayBitmap = null;
private Canvas overlayCanvas = null;
private Texture overlay = null;
private void drawOverlay(int width, int height) {
if(overlayBitmap == null || nextPow2(width) != overlayBitmap.getWidth() || nextPow2(height) != overlayBitmap.getHeight()){
overlayBitmap = Bitmap.createBitmap(nextPow2(width), nextPow2(height), Bitmap.Config.ARGB_8888);
overlayCanvas = new Canvas(overlayBitmap);
overlay = new Texture(Bitmap.createBitmap(overlayBitmap));
overlay.setEffect(new ITextureEffect() {
@Override
public void init(Texture arg0) {}

@Override
public boolean containsAlpha() {
return true;
}

@Override
public void apply(int[] dest, int[] src) {
overlayBitmap.getPixels(dest, 0, overlay.getWidth(), 0, 0, overlay.getWidth(), overlay.getHeight());
}
});
}

overlayCanvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR);

//Paint what you want
Paint p = new Paint();
p.setColor(Color.CYAN);
overlayCanvas.drawText("" + (SystemClock.uptimeMillis() / 1000), 50, 50, p);
//End Paint

overlay.applyEffect();
}

public int nextPow2(int num) {
return (int)Math.pow(2, num == 0 ? 0 : 32 - Integer.numberOfLeadingZeros(num - 1));
}


And in onDrawFrame:
[...]

drawOverlay(fb.getWidth(), fb.getHeight());
fb.blit(overlay, 0, 0, 0, 0, fb.getWidth(), fb.getHeight(), true);

[...]
#2
Support / new Texture(Bitmap) and Bitmap.recycle()
October 07, 2011, 04:22:21 PM
Hello, I'm new in jpct.

I try to create an overlay on a 3d scene with FrameBuffer.blit(...). I want a dynamic overlay, so i use a Bitmap to create a Texture to pass at FrameBuffer.blit(...).

But i have found this error:
10-07 16:10:18.512: ERROR/AndroidRuntime(32002): java.lang.RuntimeException: [ 1317996618471 ] - ERROR: java.lang.IllegalStateException: Can't call getPixels() on a recycled bitmap

I deduce that this error is caused by a call of Bitmap.recycle() in Texture constructor.

I try to create everytime a new Bitmap in each iteration but in android cause out of memory error.

How can I do a dynamic overlay?

ps. sorry for may bad english.