The code is pretty easy, it has to load from a settings file all the existing images references, scale them to 250×250 and save them with another name.
The problem is that on the device (tested on an iPhone 3g and an iPad) it crashes after a while with memory warnings. On the simulator it’s working perfect.
I have a UIViewController which has on ViewDidAppear this code:
ThreadPool.QueueUserWorkItem( delegate{
make_thumbs();
});
The make_thumbs function is:
void make_thumbs()
{
using( var ns = new NSAutoreleasePool() )
{
foreach( var c in Settings.Instance.Categories )
{
for( var i = 0; i < c.Pictures.Count; i++ )
{
//this is the existing bundled image path
string path = c.Pictures[i].PicturePath;
string folder = Environment.GetFolderPath( Environment.SpecialFolder.Personal );
//this is the destination image file name
string filename = Path.Combine( folder, c.Name + i + ".png");
if( !File.Exists( filename ) )
{
NSError err;
using(UIImage img = UIImage.FromFile( path ).Scale( 250,250 ))
{
img.AsPNG().Save( filename, true, out err );
}
}
}
}
}
}
Thx @poupou, it was almost good your answer, with a little completion: i had to put the
using( var ns = new NSAutoreleasePool() ) inside the for loop. So my code is now like this and it’s working: