0

この関数を使用してイメージ (ネットからフェッチ) を IsolatedStorage に保存すると、ファイル サイズが webbrowse から保存したものよりも大きいことがわかりました。

public static bool CreateImageFile(string filePath, BitmapImage bitmapImage)
{
        //StreamResourceInfo streamResourceInfo = Application.GetResourceStream(new Uri(filePath, UriKind.Relative));

        using (isolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
        {
            string directoryName = System.IO.Path.GetDirectoryName(filePath);
            if (!string.IsNullOrEmpty(directoryName) && !isolatedStorage.DirectoryExists(directoryName))
            {
                isolatedStorage.CreateDirectory(directoryName);
            }

            if (isolatedStorage.FileExists(filePath))
            {
                isolatedStorage.DeleteFile(filePath);
            }

            //bitmapImage

            using (IsolatedStorageFileStream fileStream = isolatedStorage.OpenFile(filePath, FileMode.Create, FileAccess.Write))
            {
                bitmapImage.CreateOptions = BitmapCreateOptions.None;
                WriteableBitmap wb = new WriteableBitmap(bitmapImage);
                wb.SaveJpeg(fileStream, wb.PixelWidth, wb.PixelHeight, 0, 100);
                fileStream.Close();
            }
        }
        return true;
}

WriteableBitmap.SaveJpeg(...) を使用して png 画像を保存してもよろしいですか? また、BitmapImage の長さを取得する関数はありますか?

4

2 に答える 2

1

PNG の場合、実際に保存するために SaveJpeg を使用するのはなぜですか? 標準的な「データからファイルへ」のアプローチを単純に使用しないのはなぜですか? すでに PNG としてエンコードされている場合は、コンテンツを保存するだけです。

ここでもっと読む:

于 2012-07-17T16:35:32.820 に答える
0

バイト配列に変換

byte[] data;
using (MemoryStream ms = new MemoryStream()
{
    bitmapImage.SaveJpeg(ms, LoadedPhoto.PixelWidth, LoadedPhoto.PixelHeight, 0, 95);
    ms.Seek(0, 0);
    data = new byte[ms.Length];
    ms.Read(data, 0, data.Length);
    ms.Close();
}

次に、バイト配列のサイズを取得し、より適切なサイズ (KB、MB...) に変換します。

于 2012-07-17T13:10:13.120 に答える