画像をbase64stringに変換する際に助けが必要です。stackoverflow で同様の質問の解決策を使用しましたが、エラーが発生しました。
使用した解決策: wp8 で画像を base64 に変換する
問題は、書き込み可能なビットマップとして設定していたイメージのソースにありますが、結果は null 例外でした。
これは私の画像ソースです:
image123.Source = new BitmapImage(new Uri("/correct1.jpg", UriKind.Relative));
この行でエラーが発生しました:
WriteableBitmap wbitmp = new WriteableBitmap((BitmapImage)image123.Source);
エラー:
An exception of type 'System.NullReferenceException' occurred in System.Windows.ni.dll but was not handled in user code
参照としての私の既存のコード:
image123.Source = new BitmapImage(new Uri("/correct1.jpg", UriKind.Relative));
byte[] bytearray = null;
using (MemoryStream ms = new MemoryStream())
{
if (image123.Source != null)
{
WriteableBitmap wbitmp = new WriteableBitmap((BitmapImage)image123.Source);
wbitmp.SaveJpeg(ms, 46, 38, 0, 100);
bytearray = ms.ToArray();
}
}
str = Convert.ToBase64String(bytearray);
binarytxt.Text = str;
これは私の主要なプロジェクトであるため、本当に助けが必要です。前もって感謝します!