hi everyone!
i’m making an app that use a lot high poly models and this is using a lot of memory (about 300 mb ram).
it’s running great and now i created a screenshot system.
i’m using
Application.CaptureScreenshot("/screenshots/" + _screenShotName +".png");
for capture screenshot and I made a thumbnail preview function called on OnGUI.
The app show one thumbnail at time and user can change by tabbing the prev/next arrow.
I used just one
private Texture2D _tempTexture;
and all screenshots are load in this texture.
this is the function:
private void drawThumbnail()
{
if(GUI.Button(new Rect(118,408,29f/2,47/2),GUIManager.Instance.GetTexture("back"), GUIStyle.none))
{
if(_screenShotIndexForPreview > 0)
{
_screenShotIndexForPreview--;
StartCoroutine (loadScreenShotPNG(_screenShotNames[_screenShotIndexForPreview]));
}
}
if(GUI.Button(new Rect(320,408,29f/2,47/2),GUIManager.Instance.GetTexture("next"), GUIStyle.none))
{
//if is not the last image
if(_screenShotIndexForPreview < _screenShotNames.Length - 2)
{
_screenShotIndexForPreview++;
StartCoroutine (loadScreenShotPNG(_screenShotNames[_screenShotIndexForPreview]));
}
}
if(_tempTexture != null)
{
GUI.DrawTexture(new Rect(xScreen,yScreen, xScale/2, yScale /2),_tempTexture);
}
}
IEnumerator loadScreenShotPNG(string pngName)
{
string imageFileURL;
imageFileURL= "file://" + path + "/screenshots/" + pngName + ".png";
imageFileURL = imageFileURL.Replace(" ", "%20");
WWW _www = new WWW(imageFileURL);
yield return _www;
//the actual size of screenshot is 1024x768
//I tryed various smaller sizes but it make no diffrence
_tempTexture = new Texture2D(512, 512);
_www.LoadImageIntoTexture(_tempTexture);
}
This works. The problem is that the app crashes after some next/back.
I think this is a memory problem because of the repeatedly allocation/deallocation of textures.
I want to know if exist a better way to do this.
Att.