本文整理汇总了C#中Microsoft.Xna.Framework.Media.MediaLibrary.SavePicture方法的典型用法代码示例。如果您正苦于以下问题:C# MediaLibrary.SavePicture方法的具体用法?C# MediaLibrary.SavePicture怎么用?C# MediaLibrary.SavePicture使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Xna.Framework.Media.MediaLibrary
的用法示例。
在下文中一共展示了MediaLibrary.SavePicture方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: btnSalvar_Click
private void btnSalvar_Click(object sender, RoutedEventArgs e)
{
try
{
string _tmpImage = "tmpImage";
string _msgMensagem = "Imagem grava com sucesso!";
var store = IsolatedStorageFile.GetUserStoreForApplication();
if (store.FileExists(_tmpImage)) store.DeleteFile(_tmpImage);
IsolatedStorageFileStream _stream = store.CreateFile(_tmpImage);
WriteableBitmap _writeImage = new WriteableBitmap(_imagetmp);
Extensions.SaveJpeg(_writeImage, _stream, _writeImage.PixelWidth,
_writeImage.PixelHeight, 0, 100);
_stream.Close();
_stream = store.OpenFile(_tmpImage, System.IO.FileMode.Open,
System.IO.FileAccess.Read);
MediaLibrary _mlibrary = new MediaLibrary();
_mlibrary.SavePicture(_stream.Name, _stream);
_stream.Close();
btnSalvar.IsEnabled = false;
lblStatus.Text = _msgMensagem;
}
catch (Exception error)
{
lblStatus.Text = error.Message;
}
}
示例2: saveImageDataToLibrary
public void saveImageDataToLibrary(string jsonArgs)
{
try
{
var options = JsonHelper.Deserialize<string[]>(jsonArgs);
string imageData = options[0];
byte[] imageBytes = Convert.FromBase64String(imageData);
using (var imageStream = new MemoryStream(imageBytes))
{
imageStream.Seek(0, SeekOrigin.Begin);
string fileName = String.Format("c2i_{0:yyyyMMdd_HHmmss}", DateTime.Now);
var library = new MediaLibrary();
var picture = library.SavePicture(fileName, imageStream);
if (picture.Name.Contains(fileName))
{
DispatchCommandResult(new PluginResult(PluginResult.Status.OK,
"Image saved: " + picture.Name));
}
else
{
DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR,
"Failed to save image: " + picture.Name));
}
}
}
catch (Exception ex)
{
DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, ex.Message));
}
}
示例3: WebClientOpenReadCompleted
void WebClientOpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
{
const string tempJpeg = "TempJPEG";
var streamResourceInfo = new StreamResourceInfo(e.Result, null);
var userStoreForApplication = IsolatedStorageFile.GetUserStoreForApplication();
if (userStoreForApplication.FileExists(tempJpeg))
{
userStoreForApplication.DeleteFile(tempJpeg);
}
var isolatedStorageFileStream = userStoreForApplication.CreateFile(tempJpeg);
var bitmapImage = new BitmapImage { CreateOptions = BitmapCreateOptions.None };
bitmapImage.SetSource(streamResourceInfo.Stream);
var writeableBitmap = new WriteableBitmap(bitmapImage);
writeableBitmap.SaveJpeg(isolatedStorageFileStream, writeableBitmap.PixelWidth, writeableBitmap.PixelHeight, 0, 85);
isolatedStorageFileStream.Close();
isolatedStorageFileStream = userStoreForApplication.OpenFile(tempJpeg, FileMode.Open, FileAccess.Read);
// Save the image to the camera roll or saved pictures album.
var mediaLibrary = new MediaLibrary();
// Save the image to the saved pictures album.
mediaLibrary.SavePicture(string.Format("SavedPicture{0}.jpg", DateTime.Now), isolatedStorageFileStream);
isolatedStorageFileStream.Close();
}
示例4: capture
public static Boolean capture(int quality)
{
try
{
PhoneApplicationFrame frame = (PhoneApplicationFrame)Application.Current.RootVisual;
WriteableBitmap bitmap = new WriteableBitmap((int)frame.ActualWidth, (int)frame.ActualHeight);
bitmap.Render(frame, null);
bitmap.Invalidate();
string fileName = DateTime.Now.ToString("'Capture'yyyyMMddHHmmssfff'.jpg'");
IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication();
if (storage.FileExists(fileName))
return false;
IsolatedStorageFileStream stream = storage.CreateFile(fileName);
bitmap.SaveJpeg(stream, bitmap.PixelWidth, bitmap.PixelHeight, 0, quality);
stream.Close();
stream = storage.OpenFile(fileName, FileMode.Open, FileAccess.Read);
MediaLibrary mediaLibrary = new MediaLibrary();
Picture picture = mediaLibrary.SavePicture(fileName, stream);
stream.Close();
storage.DeleteFile(fileName);
}
catch (Exception e)
{
MessageBox.Show(e.Message);
return false;
}
return true;
}
示例5: SaveToPhotoLibrary
public static void SaveToPhotoLibrary(this Texture2D texture, string filename)
{
MemoryStream memoryStream = new MemoryStream();
texture.SaveAsJpeg(memoryStream, texture.Width, texture.Height);
memoryStream.Position = 0;
MediaLibrary mediaLibrary = new MediaLibrary();
mediaLibrary.SavePicture(filename, memoryStream);
memoryStream.Close();
}
示例6: ButtonSaveFile_Click
private void ButtonSaveFile_Click(object sender, RoutedEventArgs e)
{
FileTransfer trans = ((FrameworkElement)sender).DataContext as FileTransfer;
if (trans != null)
{
var library = new MediaLibrary();
library.SavePicture(trans.FileName, trans.Bytes);
MessageBox.Show("File saved to 'Saved Pictures'", "File Saved", MessageBoxButton.OK);
}
}
示例7: GeoTagAddition
public void GeoTagAddition()
{
var task = WaitLocation();
task.Wait();
var position = task.Result;
Debug.WriteLine("pos: " + position.Coordinate.Longitude + " " + position.Coordinate.Latitude);
var mediaLibrary = new MediaLibrary();
int count = 0;
foreach (string filename in TestFiles.GeotagTargetImages)
{
var image = TestUtil.GetResourceByteArray(filename);
var originalMetadata = JpegMetaDataParser.ParseImage(image);
var NewImage = MetaDataOperator.AddGeoposition(image, position);
var newMetadata = JpegMetaDataParser.ParseImage(NewImage);
try
{
var pic = mediaLibrary.SavePicture(string.Format("Exif addition test_" + count + "_{0:yyyyMMdd_HHmmss}.jpg", DateTime.Now), NewImage);
}
catch (NullReferenceException) { }
TestUtil.IsGpsDataAdded(originalMetadata, newMetadata);
using (var imageStream = TestUtil.GetResourceStream(filename))
{
originalMetadata = JpegMetaDataParser.ParseImage(imageStream);
var newImageStream = MetaDataOperator.AddGeoposition(imageStream, position);
try
{
var pic2 = mediaLibrary.SavePicture(string.Format("Exif addition test_" + count + "_stream_{0:yyyyMMdd_HHmmss}.jpg", DateTime.Now), newImageStream);
}
catch (NullReferenceException) { }
finally { newImageStream.Close(); }
TestUtil.IsGpsDataAdded(originalMetadata, newMetadata);
imageStream.Close();
newImageStream.Close();
count++;
}
GC.Collect(); // Saving many big images in short time, memory mey be run out and it may throws NullReferenceException.
}
}
示例8: SaveMergebtn_click
private void SaveMergebtn_click(object sender, RoutedEventArgs e)
{
using (MemoryStream stream = new MemoryStream())
{
wb.SaveJpeg(stream, wb.PixelWidth, wb.PixelHeight, 0, 100);
stream.Seek(0, SeekOrigin.Begin);
using (MediaLibrary mediaLibrary = new MediaLibrary())
mediaLibrary.SavePicture("Picture.jpg", stream);
}
MessageBox.Show("Picture Saved to media library...");
}
示例9: 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);
}
}
示例10: Save_Click
/// <summary>
/// Salva a imagem na biblioteca de imagens
/// </summary>
private void Save_Click(object sender, RoutedEventArgs e)
{
MediaLibrary library = new MediaLibrary();
WriteableBitmap bitMap = new WriteableBitmap(drawCanvas, null);
MemoryStream ms = new MemoryStream();
Extensions.SaveJpeg(bitMap, ms, bitMap.PixelWidth,
bitMap.PixelHeight, 0, 100);
ms.Seek(0, SeekOrigin.Begin);
library.SavePicture(string.Format("Images\\{0}.jpg",
Guid.NewGuid()), ms);
New_Click(sender, e);
}
示例11: Button_Click_2
private void Button_Click_2(object sender, RoutedEventArgs e)
{
WriteableBitmap writeableBitmap = new WriteableBitmap(480, 800);
writeableBitmap.Render(App.Current.RootVisual, null);
writeableBitmap.Invalidate();
MemoryStream memoryStream = new MemoryStream();
writeableBitmap.SaveJpeg(memoryStream, writeableBitmap.PixelWidth, writeableBitmap.PixelHeight,0, 100);
memoryStream.Seek(0, SeekOrigin.Begin);
MediaLibrary mediaLibrary = new MediaLibrary();
mediaLibrary.SavePicture(Guid.NewGuid().ToString() + ".jpg", memoryStream);
memoryStream.Close();
}
示例12: SaveButton_OnClick
private void SaveButton_OnClick(object sender, EventArgs e)
{
if (!_canPress) return;
string path = EditingLockscreenFilename + ".jpg";
using (IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication())
{
var stream = storage.OpenFile(path, FileMode.Open);
var library = new MediaLibrary();
library.SavePicture("test", stream);
stream.Close();
}
}
示例13: btnSaveImage_Click
private void btnSaveImage_Click (object sender, RoutedEventArgs e)
{
WriteableBitmap bitmap = signatureView.GetImage ();
using (MemoryStream stream = new MemoryStream ()) {
bitmap.SaveJpeg (stream, bitmap.PixelWidth, bitmap.PixelHeight, 0, 100);
stream.Seek (0, SeekOrigin.Begin);
using (MediaLibrary mediaLibrary = new MediaLibrary ())
mediaLibrary.SavePicture ("signature.jpg", stream);
}
MessageBox.Show ("Picture saved to photo library");
}
示例14: btnSave_Click
private void btnSave_Click(object sender, EventArgs e)
{
// Grid から Jpeg 保存用ストリームを作成
WriteableBitmap wp = new WriteableBitmap(imgGrid, null);
MemoryStream stream = new MemoryStream();
wp.SaveJpeg(stream, wp.PixelWidth, wp.PixelHeight, 0, 100);
// PictureHub に保存する
using (MediaLibrary lib = new MediaLibrary()) {
lib.SavePicture("PhotoEffect-" + DateTime.Now.ToString("yyyyMMddhhmmss"), stream.ToArray());
MessageBox.Show("保存しました");
}
}
示例15: PageMethod1
// Constructor
public PageMethod1()
{
InitializeComponent();
CameraButtons.ShutterKeyPressed += (s, e) =>
{
Deployment.Current.Dispatcher.BeginInvoke(() =>
{
var bmp = new WriteableBitmap(displayImage, null);
var sout = new MemoryStream();
bmp.SaveJpeg(sout, bmp.PixelWidth, bmp.PixelHeight, 0, 70);
sout.Seek(0, SeekOrigin.Begin);
using (MediaLibrary mediaLibrary = new MediaLibrary())
mediaLibrary.SavePicture(String.Format("PictureNavigation Method1 {0:yyyyMMdd-HHmmss}", DateTime.Now), sout);
});
};
Loaded += (s, e) =>
{
method.Output = displayImage;
DispatcherTimer timer = new DispatcherTimer();
timer.Tick += (ss, ee) =>
{
const string total = "DeviceTotalMemory";
const string current = "ApplicationCurrentMemoryUsage";
const string peak = "ApplicationPeakMemoryUsage";
var currentBytes = ((long)DeviceExtendedProperties.GetValue(current)) / 1024.0 / 1024.0;
var txt = string.Format("Memory = {0,5:F} MB / {1,5:F} MB\n", currentBytes, DeviceStatus.ApplicationMemoryUsageLimit / 1024 / 1024);
displayInfo.Text = txt + method.Info();
};
timer.Interval = new TimeSpan(0, 0, 0, 0, 40);
timer.Start();
};
}