ウィンドウズフォン7を使用しています
Timer オブジェクトのすべてのティックで次のことを行いたい:
- PhotoCamera オブジェクトからカメラ データを取得する
- そのデータを WritableBitmap に変換します。
システム例外エラーで立ち往生しています。
これが私のコードです
if (camReady == true)
{
try
{
var image = new Image();
byte[] ba = new byte[camBufferSize];
cam.GetPreviewBufferY(ba);
var mem = new MemoryStream(ba);
bitmap.SetSource(mem);
var result = reader.Decode(bitmap);
if (result == null)
{
txtDebug.Text = "Tick\t" + savedCounter + "\n" + (result == null ? "Result jest nullem" : result.Text) + "\tsize " + buffer.Length
+ "\nPierwszy elem" + buffer[0];
//+ "\nByteArray Len "+byteArray.Length
//+ "\nFirst Elem of ByteArray "+byteArray[0];
}
else
{
txtDebug.Text = "HURRAAAAAAAA!!!!"+
"\nresult.Text\t" + result.Text;
}
}
catch (Exception ex)
{
Console.WriteLine("{0} Exception caught.", ex);
txtDebug.Text = "{0} Exception caught.\t"+ ex;
}
Console.WriteLine("Buffer", buffer);
if (savedCounter % 6 == 0) cam.Focus();
//var result = reader.Decode(bitmap);
}
「ビットマップ」オブジェクトと camBufferSize オブジェクトは、コードの別の部分で作成されます
bitmap = new WriteableBitmap((int)cam.Resolution.Width, (int)cam.Resolution.Height);
camBufferSize = (int)cam.Resolution.Width * (int)cam.Resolution.Height;
WritableBitmap の作成中にエラーが発生しました
bitmap.SetSource(mem);
デバッガーで前の行を確認しましたが、null などではありません。
このように WritableBitmap を作成する目的は何ですか?
私はバーコードスキャナーを構築しています.ZXingライブラリの入力としてWritableBitmapデータが必要で、カメラを使用するときに画像のバーコードをデコードします。
私はC#の初心者ですが、この問題を解決するのを手伝ってくれてありがとうございます:)