これは初めての Silverlight アプリケーションで、C:
ディレクトリにファイルを保存する必要があります。Silverlight アプリが Web カメラに接続し、スナップショットを作成してC:
ディレクトリに保存します。
私が作ったものを見て
protected void photoButton_Click(object sender, RoutedEventArgs e)
{
this.src.CaptureImageCompleted += (s, a) =>
{
this.lastSnapshot = a.Result;
this.snapshot.Visibility = Visibility.Visible;
this.snapshot.Source = this.lastSnapshot;
this.src.Stop();
if (this.lastSnapshot != null)
{
var pngStream = this.GetPngStream(lastSnapshot);
byte[] binaryData = new Byte[pngStream.Length];
long bytesRead = pngStream.Read(binaryData, 0, (int)pngStream.Length);
WriteBytesToFile("imagem.png", binaryData);
}
};
src.CaptureImageAsync();
}
static public void WriteBytesToFile(string fileName, byte[] content)
{
FileStream fs = new FileStream(fileName, FileMode.Create);
BinaryWriter w = new BinaryWriter(fs);
try
{
w.Write(content);
}
finally
{
fs.Close();
w.Close();
}
}
protected Stream GetPngStream(WriteableBitmap bmp)
{
// Use Joe Stegman's PNG Encoder
// http://bit.ly/77mDsv
EditableImage imageData = new EditableImage(bmp.PixelWidth, bmp.PixelHeight);
for (int y = 0; y < bmp.PixelHeight; ++y)
{
for (int x = 0; x < bmp.PixelWidth; ++x)
{
int pixel = bmp.Pixels[bmp.PixelWidth * y + x];
imageData.SetPixel(x, y,
(byte)((pixel >> 16) & 0xFF),
(byte)((pixel >> 8) & 0xFF),
(byte)(pixel & 0xFF),
(byte)((pixel >> 24) & 0xFF)
);
}
}
return imageData.GetStream();
}
私WriteBytesToFile
はエラーが発生しましFile operation not permitted. Access to path is denied.
た。C:
名前でディレクトリにスナップショットを保存するにはどうすればよいimagem.png
ですか?