이것은 내 첫 실버 라이트 응용 프로그램이며 내 C:
디렉토리에 파일을 저장해야합니다. 내 Silverlight 응용 프로그램이 웹캠과 연결 한 다음 스냅 샷을 찍은 다음 내 C:
디렉토리에 저장합니다.Silverlight를 사용하여 디스크에 파일 저장
내가 오류 File operation not permitted. Access to path is denied.
있어 내 WriteBytesToFile
에서
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();
}
을 만들 었는지 확인합니다. imagem.png
이라는 이름으로 C:
디렉토리에 스냅 샷을 저장하려면 어떻게해야합니까?
오류는 매우 명확합니다. C : 디렉토리에 작성하려면 에스컬레이션 된 개인 정보가 필요하므로 이러한 개인 정보가 필요하지 않거나 프로그램의 개인 정보를 평가하는 다른 디렉토리를 선택하십시오. –
나는 D : 시도했지만 액세스도하지 않고. 내 웹 응용 프로그램에서는 디스크에 많은 양을 기록 했으므로이 기능이 작동하지 않는 이유를 모르겠습니다. –