本文整理汇总了C#中Microsoft.Xna.Framework.Media.MediaLibrary.SavePictureToCameraRoll方法的典型用法代码示例。如果您正苦于以下问题:C# MediaLibrary.SavePictureToCameraRoll方法的具体用法?C# MediaLibrary.SavePictureToCameraRoll怎么用?C# MediaLibrary.SavePictureToCameraRoll使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Xna.Framework.Media.MediaLibrary
的用法示例。
在下文中一共展示了MediaLibrary.SavePictureToCameraRoll方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: saveButton_Click
/// <summary>
/// Clicking on the save button saves the photo in DataContext.ImageStream to media library
/// camera roll. Once image has been saved, the application will navigate back to the main page.
/// </summary>
private void saveButton_Click(object sender, EventArgs e)
{
try
{
// Reposition ImageStream to beginning, because it has been read already in the OnNavigatedTo method.
_dataContext.ImageStream.Position = 0;
MediaLibrary library = new MediaLibrary();
library.SavePictureToCameraRoll("CameraExplorer_" + DateTime.Now.ToString("yyyyMMddhhmmss") + ".jpg", _dataContext.ImageStream);
// There should be no temporary file left behind
using (var isolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
{
var files = isolatedStorage.GetFileNames("CameraExplorer_*.jpg");
foreach (string file in files)
{
isolatedStorage.DeleteFile(file);
//System.Diagnostics.Debug.WriteLine("Temp file deleted: " + file);
}
}
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine("Saving picture to camera roll failed: " + ex.HResult.ToString("x8") + " - " + ex.Message);
}
NavigationService.GoBack();
}
示例2: SaveButton_Click
private void SaveButton_Click(object sender, EventArgs e)
{
WriteableBitmap wb = new WriteableBitmap(mapControl, null);
wb.Render(mapControl, null);
MemoryStream memoryStream = new MemoryStream();
wb.SaveJpeg(memoryStream, wb.PixelWidth, wb.PixelHeight, 0, 80);
MediaLibrary library = new MediaLibrary();
library.SavePictureToCameraRoll("SavedMap_" + DateTime.Now.ToString() + ".jpg", memoryStream.GetBuffer());
}
示例3: SaveToMediaLibrary
/// <summary>
/// Saves the WriteableBitmap encoded as JPEG to the Media library.
/// </summary>
/// <param name="bitmap">The WriteableBitmap to save.</param>
/// <param name="name">The name of the destination file.</param>
/// <param name="quality">The quality for JPEG encoding has to be in the range 0-100,
/// where 100 is the best quality with the largest size.</param>
/// <param name="saveToCameraRoll">If true the bitmap will be saved to the camera roll, otherwise it will be written to the default saved album.</param>
public static Picture SaveToMediaLibrary(this WriteableBitmap bitmap, string name, int quality, bool saveToCameraRoll = false)
{
using (var stream = new MemoryStream())
{
// Save the picture to the WP media library
bitmap.SaveJpeg(stream, bitmap.PixelWidth, bitmap.PixelHeight, 0, quality);
stream.Seek(0, SeekOrigin.Begin);
var mediaLibrary = new MediaLibrary();
return saveToCameraRoll ? mediaLibrary.SavePictureToCameraRoll(name, stream) : mediaLibrary.SavePicture(name, stream);
}
}
示例4: Save_Clicked
private async void Save_Clicked(object sender, RoutedEventArgs e)
{
using (MemoryStream stream = new MemoryStream())
{
WriteableBitmap bitmap = new WriteableBitmap(3552, 2448);
await session.RenderToWriteableBitmapAsync(bitmap);
bitmap.SaveJpeg(stream, bitmap.PixelWidth, bitmap.PixelHeight, 0, 100);
stream.Seek(0, SeekOrigin.Begin);
using (MediaLibrary mediaLibrary = new MediaLibrary())
mediaLibrary.SavePictureToCameraRoll("Picture.jpg", stream);
MessageBox.Show("Image saved!");
}
}
示例5: share
private void share(object sender, RoutedEventArgs e)
{
//Create a filename for the JPEG file in isolated storage
String tempJPEG = "TempJPEG";
// Create a virtual store and file stream. Check for duplicate tempJPEG files.
var myStore = IsolatedStorageFile.GetUserStoreForApplication();
if (myStore.FileExists(tempJPEG))
{
myStore.DeleteFile(tempJPEG);
}
IsolatedStorageFileStream myFileStream = myStore.CreateFile(tempJPEG);
// Create a stream out of the sample JPEG file.
// For [Application Name] in the URI, use the project name that you entered
// in the previous steps. Also, TestImage.jpg is an example;
// you must enter your JPEG file name if it is different.
StreamResourceInfo sri = null;
Uri uri = new Uri("[Application Name];component/TestImage.jpg", UriKind.Relative);
sri = Application.GetResourceStream(uri);
// Create a new WriteableBitmap object and set it to the JPEG stream.
BitmapImage bitmap = new BitmapImage();
bitmap.CreateOptions = BitmapCreateOptions.None;
bitmap.SetSource(sri.Stream);
WriteableBitmap wb = new WriteableBitmap(bitmap);
// Encode the WriteableBitmap object to a JPEG stream.
wb.SaveJpeg(myFileStream, wb.PixelWidth, wb.PixelHeight, 0, 85);
myFileStream.Close();
// Create a new stream from isolated storage, and save the JPEG file to the media library on Windows Phone.
myFileStream = myStore.OpenFile(tempJPEG, FileMode.Open, FileAccess.Read);
// Save the image to the camera roll or saved pictures album.
MediaLibrary library = new MediaLibrary();
// Save the image to the camera roll album.
Picture pic = library.SavePictureToCameraRoll("SavedPicture.jpg", myFileStream);
MessageBox.Show("Image saved to camera roll album");
/* // Save the image to the saved pictures album.
Picture pic = library.SavePicture("SavedPicture.jpg", myFileStream);
MessageBox.Show("Image saved to saved pictures album");
*/
myFileStream.Close();
}
示例6: Button_Click_2
private async void Button_Click_2(object sender, RoutedEventArgs e) {
CameraCaptureSequence cameraCaptureSequence = _cam.CreateCaptureSequence(1);
MemoryStream stream = new MemoryStream();
cameraCaptureSequence.Frames[0].CaptureStream = stream.AsOutputStream();
await _cam.PrepareCaptureSequenceAsync(cameraCaptureSequence);
await cameraCaptureSequence.StartCaptureAsync();
stream.Seek(0, SeekOrigin.Begin);
var library = new MediaLibrary();
library.SavePictureToCameraRoll("pic1.jpg", stream);
}
示例7: Button_Click_1
private async void Button_Click_1(object sender, RoutedEventArgs e)
{
CameraCaptureSequence seq;
seq = captureDevice.CreateCaptureSequence(1);
seq.Frames[0].DesiredProperties[KnownCameraPhotoProperties.SceneMode] = CameraSceneMode.Portrait;
MemoryStream captureStream1 = new MemoryStream();
seq.Frames[0].CaptureStream = captureStream1.AsOutputStream();
await captureDevice.PrepareCaptureSequenceAsync(seq);
await seq.StartCaptureAsync();
captureStream1.Seek(0, SeekOrigin.Begin);
MediaLibrary mediaLibrary = new MediaLibrary();
mediaLibrary.SavePictureToCameraRoll( "1111.jpg", captureStream1);
}
示例8: MainPage_Loaded
private async void MainPage_Loaded(object sender, RoutedEventArgs e)
{
using (MemoryStream stream = new MemoryStream())
using (var camera = await PhotoCaptureDevice.OpenAsync(CameraSensorLocation.Back,
PhotoCaptureDevice.GetAvailableCaptureResolutions(CameraSensorLocation.Back).First()))
{
var sequence = camera.CreateCaptureSequence(1);
sequence.Frames[0].CaptureStream = stream.AsOutputStream();
camera.PrepareCaptureSequenceAsync(sequence);
await sequence.StartCaptureAsync();
stream.Seek(0, SeekOrigin.Begin);
using (var library = new MediaLibrary())
{
library.SavePictureToCameraRoll("currentImage.jpg", stream);
BitmapImage licoriceImage = new BitmapImage(new Uri("currentImage.jpg", UriKind.Relative));
imgPlace.Source = licoriceImage;
}
}
}
示例9: SaveButton_Click
/// <summary>
/// Clicking on the save button saves the photo in MainPage.ImageStream
/// to media library camera roll. Once image has been saved, the
/// application will navigate back to the main page.
/// </summary>
private async void SaveButton_Click(object sender, EventArgs e)
{
_progressIndicator.Text = AppResources.SavingText;
_progressIndicator.IsVisible = true;
SystemTray.SetProgressIndicator(this, _progressIndicator);
int selectedIndex = FilterPreviewPivot.SelectedIndex;
DataContext dataContext = FilterEffects.DataContext.Instance;
try
{
if (selectedIndex == 0)
{
using (MediaLibrary library = new MediaLibrary())
{
library.SavePictureToCameraRoll(FileNamePrefix
+ DateTime.Now.ToString() + ".jpg",
dataContext.FullResolutionStream);
}
}
else
{
AbstractFilter filter = _filters[selectedIndex];
IBuffer buffer = await filter.RenderJpegAsync(
dataContext.FullResolutionStream.GetWindowsRuntimeBuffer());
using (MediaLibrary library = new MediaLibrary())
{
library.SavePictureToCameraRoll(FileNamePrefix
+ DateTime.Now.ToString() + ".jpg", buffer.AsStream());
}
}
}
catch (Exception ex)
{
MessageBox.Show("Failed to save the image: " + ex.ToString());
}
_progressIndicator.IsVisible = false;
SystemTray.SetProgressIndicator(this, _progressIndicator);
AdRequest adRequest = new AdRequest();
adRequest.ForceTesting = true;
interstitialAd.LoadAd(adRequest);
interstitialAd.ReceivedAd += OnAdReceived;
if (p == true)
{
p = false;
q = true;
interstitialAd.ShowAd();
//NavigationService.Navigate(new Uri("/PreveiwPage.xaml", UriKind.Relative));
}
NavigationService.Navigate(new Uri("/Page1.xaml", UriKind.Relative));
NavigationService.GoBack();
}
示例10: SaveButton_Click
/// <summary>
/// Clicking on the save button saves the photo in MainPage.ImageStream
/// to media library camera roll. Once image has been saved, the
/// application will navigate back to the main page.
/// </summary>
private async void SaveButton_Click(object sender, EventArgs e)
{
_progressIndicator.Text = AppResources.SavingText;
_progressIndicator.IsVisible = true;
SystemTray.SetProgressIndicator(this, _progressIndicator);
int selectedIndex = FilterPreviewPivot.SelectedIndex;
DataContext dataContext = FilterEffects.DataContext.Singleton;
try
{
if (selectedIndex == 0)
{
using (MediaLibrary library = new MediaLibrary())
{
library.SavePictureToCameraRoll(FileNamePrefix
+ DateTime.Now.ToString() + ".jpg",
dataContext.ImageStream);
}
}
else
{
AbstractFilter filter = _filters[selectedIndex];
IBuffer buffer = await filter.RenderJpegAsync(
dataContext.ImageStream.GetWindowsRuntimeBuffer());
using (MediaLibrary library = new MediaLibrary())
{
library.SavePictureToCameraRoll(FileNamePrefix
+ DateTime.Now.ToString() + ".jpg", buffer.AsStream());
}
}
}
catch (Exception ex)
{
MessageBox.Show("Failed to save the image: " + ex.ToString());
}
_progressIndicator.IsVisible = false;
SystemTray.SetProgressIndicator(this, _progressIndicator);
NavigationService.GoBack();
}
示例11: SaveToIsolatedStorage
public void SaveToIsolatedStorage(Stream imageStream, string fileName)
{
using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
{
if (myIsolatedStorage.FileExists(fileName))
{
myIsolatedStorage.DeleteFile(fileName);
}
IsolatedStorageFileStream fileStream = myIsolatedStorage.CreateFile(fileName);
BitmapImage bitmap = new BitmapImage();
bitmap.SetSource(imageStream);
WriteableBitmap wb = new WriteableBitmap(bitmap);
Extensions.SaveJpeg(wb, fileStream, wb.PixelWidth, wb.PixelHeight, 0, 100);
fileStream.Close();
}
using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
{
using (IsolatedStorageFileStream fileStream = myIsolatedStorage.OpenFile(fileName, FileMode.Open, FileAccess.Read))
{
MediaLibrary mediaLibrary = new MediaLibrary();
Picture picture = mediaLibrary.SavePictureToCameraRoll(fileName, fileStream);
fileStream.Close();
}
}
}
示例12: SaveToCameraRoll
private async Task<string> SaveToCameraRoll(Stream cameraImage, string filenameBase)
{
string filename = filenameBase + ".jpg";
StorageFolder storageFolder = KnownFolders.CameraRoll;
AutoResizeConfiguration resizeConfiguration = null;
var buffer = StreamToBuffer(cameraImage);
// Store low resolution image
using (var source = new BufferImageSource(buffer))
{
var info = await source.GetInfoAsync();
if (info.ImageSize.Width * info.ImageSize.Height > LibraryMaxArea)
{
var compactedSize = CalculateSize(info.ImageSize, LibraryMaxSize, LibraryMaxArea);
resizeConfiguration = new AutoResizeConfiguration(LibraryMaxBytes, compactedSize,
new Size(0, 0), AutoResizeMode.Automatic, 0, ColorSpace.Yuv420);
buffer = await Nokia.Graphics.Imaging.JpegTools.AutoResizeAsync(buffer, resizeConfiguration);
}
using (var library = new MediaLibrary())
{
library.SavePictureToCameraRoll(filename, buffer.AsStream());
}
}
// Store high resolution image
if (resizeConfiguration != null)
{
filename = filenameBase + HIGH_RESOLUTION_PHOTO_SUFFIX + @".jpg";
cameraImage.Position = 0;
using (var stream = await storageFolder.OpenStreamForWriteAsync(filename, CreationCollisionOption.GenerateUniqueName))
{
await cameraImage.CopyToAsync(stream);
}
}
_saved = true;
return storageFolder.Path + "\\" + filename;
}
示例13: AutoFocus
/*
/// <summary>
/// Starts autofocusing, if supported. Capturing buttons are disabled while focusing.
/// </summary>
private async Task AutoFocus()
{
if (!_capturing && PhotoCaptureDevice.IsFocusSupported(_dataContext.Device.SensorLocation))
{
SetScreenButtonsEnabled(false);
SetCameraButtonsEnabled(false);
await _dataContext.Device.FocusAsync();
SetScreenButtonsEnabled(true);
SetCameraButtonsEnabled(true);
_capturing = false;
}
}
*/
/// <summary>
/// Captures a photo. Photo data is stored to DataContext.ImageStream, and application
/// is navigated to the preview page after capturing.
/// </summary>
private async Task Capture()
{
// capture maxFrame images
while (frameIndex < maxFrame)
{
// don't go to preview
// save the image directly
//bool goToPreview = false;
if (!_capturing)
{
_capturing = true;
MemoryStream stream = new MemoryStream();
CameraCaptureSequence sequence = _dataContext.Device.CreateCaptureSequence(1);
sequence.Frames[0].CaptureStream = stream.AsOutputStream();
await _dataContext.Device.PrepareCaptureSequenceAsync(sequence);
await sequence.StartCaptureAsync();
_dataContext.ImageStream = stream;
_capturing = false;
// Defer navigation as it will release the camera device and the
// following Device calls must still work.
//goToPreview = true;
}
_manuallyFocused = false;
if (PhotoCaptureDevice.IsFocusRegionSupported(_dataContext.Device.SensorLocation))
{
_dataContext.Device.FocusRegion = null;
}
FocusIndicator.SetValue(Canvas.VisibilityProperty, Visibility.Collapsed);
_dataContext.Device.SetProperty(KnownCameraPhotoProperties.LockedAutoFocusParameters, AutoFocusParameters.None);
// now we can save the images
// Reposition ImageStream to beginning, because it has been read already in the OnNavigatedTo method.
_dataContext.ImageStream.Position = 0;
MediaLibrary library = new MediaLibrary();
DateTime t = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Local);
string fileName = frameIndex + "-" + t.Hour + "-" + t.Minute + "-" + t.Second + "-" + t.Millisecond + ".jpg";
frameIndex++;
library.SavePictureToCameraRoll(fileName, _dataContext.ImageStream);
// There should be no temporary file left behind
using (var isolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
{
var files = isolatedStorage.GetFileNames("CameraExplorer_*.jpg");
foreach (string file in files)
{
isolatedStorage.DeleteFile(file);
//System.Diagnostics.Debug.WriteLine("Temp file deleted: " + file);
}
}
/*
if (goToPreview)
{
NavigationService.Navigate(new Uri("/PreviewPage.xaml", UriKind.Relative));
}*/
}
}
示例14: SaveImageToCameraRoll
private void SaveImageToCameraRoll(int imageHandle, String imageName, Resource imageResource)
{
MediaLibrary library = new MediaLibrary();
MemoryStream targetStream = new MemoryStream();
int mediaType = MoSync.Constants.MA_MEDIA_TYPE_IMAGE;
int mediaHandle = imageHandle;
int eventReturnCode = MoSync.Constants.MA_MEDIA_RES_OK;
try
{
WriteableBitmap data = (WriteableBitmap)imageResource.GetInternalObject();
data.SaveJpeg(targetStream, data.PixelWidth, data.PixelHeight, 0, 100);
data = null;
library.SavePictureToCameraRoll(imageName, targetStream.GetBuffer()).Dispose();
}
catch (Exception e)
{
System.Diagnostics.Debug.WriteLine(e.ToString());
eventReturnCode = MoSync.Constants.MA_MEDIA_RES_IMAGE_EXPORT_FAILED;
}
finally
{
library.Dispose();
targetStream.Dispose();
PostMediaEvent(mediaType, mediaHandle, eventReturnCode);
}
}
示例15: Capture
private async System.Threading.Tasks.Task Capture()
{
try
{
await camera.FocusAsync();
MemoryStream imageStream = new MemoryStream();
imageStream.Seek(0, SeekOrigin.Begin);
CameraCaptureSequence sequence = camera.CreateCaptureSequence(1);
sequence.Frames[0].CaptureStream = imageStream.AsOutputStream();
await camera.PrepareCaptureSequenceAsync(sequence);
await sequence.StartCaptureAsync();
camera.SetProperty(
KnownCameraPhotoProperties.LockedAutoFocusParameters,
AutoFocusParameters.None);
MediaLibrary library = new MediaLibrary();
EditingSession session = new EditingSession(imageStream.GetWindowsRuntimeBuffer());
using (session)
{
session.AddFilter(FilterFactory.CreateSketchFilter(SketchMode.Gray));
IBuffer data = await session.RenderToJpegAsync();
library.SavePictureToCameraRoll(FileNamePrefix
+ DateTime.Now.ToString() + ".jpg",
data.AsStream());
}
}
catch (Exception ex)
{
Debug.WriteLine("Failed to save the image to camera roll: " + ex.ToString());
}
}