Author Topic: Save Texture Back To File  (Read 2697 times)

Offline sushobhit

  • long
  • ***
  • Posts: 109
  • future is now
    • View Profile
    • ANDROID APPS
Save Texture Back To File
« on: July 08, 2014, 12:29:38 pm »
Hi ,

I am facing difficulty in saving Texture Back to File.

OK.

So , I get the  rendered scene into a Texture.

Now , how can I save this Texture into a bitmap ????



Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Save Texture Back To File
« Reply #1 on: July 08, 2014, 12:57:16 pm »
You can't, at least not directly. But you can blit the texture into the FrameBuffer and get the pixels via FrameBuffer.getPixels(). Convert that int[]-array into a bitmap, crop and save it.

Offline sushobhit

  • long
  • ***
  • Posts: 109
  • future is now
    • View Profile
    • ANDROID APPS
Re: Save Texture Back To File
« Reply #2 on: July 10, 2014, 07:25:21 am »
Also a very peculiar issue that crops up during the process of putting the rendered scene onto a Texture is the resulting image is

Mirrored & inverted 180 degrees (is it a bug or am I doing something wrong)

I do something like this :

fb.setRenderTarget(TextureManager.getInstance().getTexture("theimage"));

world.renderScene(fb);
world.draw(fb);

fb.display();

fb.removeRenderTarget();

/// Then I blit the image on the fb

fb.blit(TextureManager.getInstance().getTexture("theimage"),0,0,0,0,512,512,fb.getWidth(),fb.getHeight(),-1,false);

/// This image I get is rotated 180degrees and mirrored ?? why so ??? I dont know !!!

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Save Texture Back To File
« Reply #3 on: July 10, 2014, 08:37:38 am »
That's how it's supposed to be. It's caused by the way in which OpenGL works. You can either blit the texture with yStart at the bottom and a negative height or flip the bitmap after grabbing it.

Offline sushobhit

  • long
  • ***
  • Posts: 109
  • future is now
    • View Profile
    • ANDROID APPS
Re: Save Texture Back To File
« Reply #4 on: July 11, 2014, 07:00:55 am »
Thanks I works perfectly now ... I just changed this :

From :

fb.blit(TextureManager.getInstance().getTexture("cctv1"),0,0,0,0,512,512,300,200,-1,false);

To :

fb.blit(TextureManager.getInstance().getTexture("cctv1"),0,0,0,200,512,512,300,-200,-1,false);