コードはかなり簡単です。設定ファイルから既存の画像参照をすべて読み込み、250x250に拡大して別の名前で保存する必要があります。UIImageを別のスレッドのpngとして保存する
問題は、(iPhone 3GとiPadでテストされた)デバイスでは、メモリ警告が表示されてしばらくしてからクラッシュすることです。シミュレータ上では完璧に動作しています。
がThreadPool.QueueUserWorkItem(delegate{
make_thumbs();
});
make_thumbs機能は次のとおりです:
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);
}
}
}
}
}
}
私は問題が何であるか分かりませんが、あなたのコードに適用できるパフォーマンスの微調整があります。 MonoTouchはThreadPoolスレッド用のNSAutoReleasePoolオブジェクトを作成するので、作成する必要はありません。ここでの情報:http://docs.xamarin.com/ios/advanced_topics/threading?highlight=Thread –
完了したらAsPNGの結果を破棄してみてください。最新のMonoDevelop + MonoTouchベータ版では、漏れの原因を突き止めるために使用できるプロファイラもあります。 –
'string folder = Environment.GetFolderPath(Environment.SpecialFolder.Personal);'は不変であり、ループ外に移動する必要があります。 – poupou