我正在开发windows应用程序,在该应用程序中,我需要将相机捕获的图像存储在隔离存储中,而不需要将其保存在相机卷中。我能够将捕获的图像存储在隔离存储中,但捕获图像的副本也存储在相机卷中。我有没有办法把图像保存在独立的存储器里,而不是相机卷里。
谢谢
发布于 2013-08-08 11:52:39
如果希望仅保存到独立存储,则不能使用CameraCaptureTask。在WP8中,不管您做什么,它都会透明地将图像的副本保存到相机卷中。
尽管如此,还是有解决办法的。您需要使用camera来创建和使用您自己的CameraCaptureTask。我不打算深入,但这应该会让你开始。
您需要做的第一件事是遵循本教程创建视图和基本应用程序。他们使用cam_CaptureImageAvailable方法将图像存储到相机卷中。您需要修改它,以便将其存储在隔离存储中,如下所示:
using (e.ImageStream)
{
using(IsolatedStorageFile storageFile = IsolatedStorageFile.GetuserStoreForApplication())
{
if( !sotrageFile.DirectoryExists(<imageDirectory>)
{
storageFile.CreateDirectory(<imageDirectory>);
}
using( IsolatedStorageFileStream targetStream = storageFile.OpenFile( <filename+path>, FileMode.Create, FileAccess.Write))
{
byte[] readBuffer = new byte[4096];
int bytesRead;
while( (bytesRead = e.ImageStream.Read( readBuffer, 0, readBuffer.Length)) > 0)
{
targetStream.Write(readBuffer, 0, bytesRead);
}
}
}
}从现在开始,您有一个只存储到隔离存储的功能相机应用程序。你可能想用颜色效果或其他东西来调味它,但这是不必要的。
发布于 2014-06-12 07:02:26
以上接受的答案对于Windows 8 Silverlight 8.1是不正确的
我使用已完成的事件来自定义我想要在照片被拍摄和接受之后执行的代码。
public MainPage()
{
InitializeComponent();
cameraTask = new CameraCaptureTask();
cameraTask.Completed += new EventHandler<PhotoResult>(cameraTask_Completed);
cameraTask.Show();
}
void cameraTask_Completed(object sender, PhotoResult e)
{
if (e.TaskResult != TaskResult.OK)
return;
// Save picture as JPEG to isolated storage.
using (IsolatedStorageFile isStore = IsolatedStorageFile.GetUserStoreForApplication())
{
using (IsolatedStorageFileStream targetStream = isStore.OpenFile(fileName, FileMode.Create, FileAccess.Write))
{
// Initialize the buffer for 4KB disk pages.
byte[] readBuffer = new byte[4096];
int bytesRead = -1;
// Copy the image to isolated storage.
while ((bytesRead = e.ImageStream.Read(readBuffer, 0, readBuffer.Length)) > 0)
{
targetStream.Write(readBuffer, 0, bytesRead);
}
}
}
}资源http://msdn.microsoft.com/library/windowsphone/develop/microsoft.phone.tasks.cameracapturetask http://code.msdn.microsoft.com/wpapps/CSWP8ImageFromIsolatedStora-8dcf8411
https://stackoverflow.com/questions/18118749
复制相似问题