本文整理汇总了C#中System.Windows.Media.Imaging.WriteableBitmap.LoadJpeg方法的典型用法代码示例。如果您正苦于以下问题:C# WriteableBitmap.LoadJpeg方法的具体用法?C# WriteableBitmap.LoadJpeg怎么用?C# WriteableBitmap.LoadJpeg使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Media.Imaging.WriteableBitmap
的用法示例。
在下文中一共展示了WriteableBitmap.LoadJpeg方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: cameraTask_Completed
protected void cameraTask_Completed(object sender, PhotoResult e)
{
rho.common.Hashtable<String, String> mapRes = new rho.common.Hashtable<String, String>();
switch (e.TaskResult)
{
case TaskResult.OK:
WriteableBitmap writeableBitmap = new WriteableBitmap(1600, 1200);
writeableBitmap.LoadJpeg(e.ChosenPhoto);
string imageFolder = "rho/apps";//CFilePath.join( rho_native_rhopath(), RHO_APPS_DIR);//"rho";
string datetime = DateTime.Now.ToString().Replace("/", "");
datetime = datetime.Replace(":", "");
string imageFileName = "Foto_" + datetime.Replace(" ", String.Empty) + ".jpg";
string filePath = "";
using (var isoFile = IsolatedStorageFile.GetUserStoreForApplication())
{
if (!isoFile.DirectoryExists(imageFolder))
{
isoFile.CreateDirectory(imageFolder);
}
filePath = System.IO.Path.Combine(imageFolder, imageFileName);
using (var stream = isoFile.CreateFile(filePath))
{
writeableBitmap.SaveJpeg(stream, writeableBitmap.PixelWidth, writeableBitmap.PixelHeight, 0, 100);
}
}
mapRes["imageUri"] = "/"+imageFileName;//e.OriginalFileName;
mapRes["image_uri"] = "/"+imageFileName;//e.OriginalFileName;
mapRes["status"] = "ok";
break;
case TaskResult.None:
mapRes["message"] = "Error";
mapRes["status"] = "error";
break;
case TaskResult.Cancel:
mapRes["message"] = "User cancelled operation";
mapRes["status"] = "cancel";
break;
default:
break;
}
_oResult.set(mapRes);
//Code to display the photo on the page in an image control named myImage.
//System.Windows.Media.Imaging.BitmapImage bmp = new System.Windows.Media.Imaging.BitmapImage();
//bmp.SetSource(e.ChosenPhoto);
//myImage.Source = bmp;
}
示例2: camera_CaptureImageAvailable
// ---
private void camera_CaptureImageAvailable(object sender, ContentReadyEventArgs e)
{
capturing = false;
Stream imageStream = (Stream)e.ImageStream;
BarcodeDecoder barcodeDecoder = new BarcodeDecoder();
Dictionary<DecodeOptions, object> decodingOptions =
new Dictionary<DecodeOptions, object>();
List<BarcodeFormat> possibleFormats = new List<BarcodeFormat>(1);
Result result;
Dispatcher.BeginInvoke(
() =>
{
WriteableBitmap qrImage = new WriteableBitmap((int)camera.Resolution.Width, (int)camera.Resolution.Height);
imageStream.Position = 0;
qrImage.LoadJpeg(imageStream);
possibleFormats.Add(BarcodeFormat.QRCode);
decodingOptions.Add(
DecodeOptions.PossibleFormats,
possibleFormats);
try
{
result = barcodeDecoder.Decode(qrImage, decodingOptions);
resultText.Text = result.Text;
}
catch (NotFoundException)
{
// this is expected if the image does not contain a valid
// code, Or is too distorted to read
resultText.Text = "<nothing to display>";
}
catch (Exception ex)
{
// something else went wrong, so alert the user
MessageBox.Show(
ex.Message,
"Error Decoding Image",
MessageBoxButton.OK);
}
}
);
}
示例3: Convert
public object Convert( object value, Type targetType, object parameter, System.Globalization.CultureInfo culture )
{
if(value is byte[])
{
BitmapImage image = new BitmapImage();
WriteableBitmap writeBitmap = new WriteableBitmap(200, 200);
MemoryStream memoryStream = new MemoryStream(value as byte[]);
writeBitmap.LoadJpeg(memoryStream);
image.SetSource(memoryStream);
return image;
}
else
return null;
//BitmapImage image = new BitmapImage();
//string s = System.Convert.ToString(value);
//image.UriSource = new Uri(s, UriKind.Relative);
//return value;
}
示例4: ApplyYey
/// <summary>
/// 画像に遺影を重ねます。
/// </summary>
/// <param name="bitmap"></param>
/// <returns></returns>
private WriteableBitmap ApplyYey(WriteableBitmap bitmap)
{
var wb = bitmap.Clone();
var file = Application.GetResourceStream(new Uri("photoframe.png", UriKind.Relative));
var yey = new WriteableBitmap(wb.PixelWidth, wb.PixelHeight);
yey.LoadJpeg(file.Stream);
for (int i = 0; i < yey.Pixels.Length; i++)
{
var oPx = yey.Pixels[i];
var a2 = Convert.ToByte((oPx >> 24) & 0xff);
var ax2 = (double)a2 / 255;
if (a2 == 0)
{
// 透明なので下地を描画
}
else if (a2 == 255)
{
// 不透明なので上に書き込み
wb.Pixels[i] = yey.Pixels[i];
}
else
{
// 下地の画像の色を取り出す
var a = Convert.ToByte((wb.Pixels[i] >> 24) & 0xff);
var r = Convert.ToByte((wb.Pixels[i] >> 16) & 0xff);
var g = Convert.ToByte((wb.Pixels[i] >> 8) & 0xff);
var b = Convert.ToByte((wb.Pixels[i]) & 0xff);
// 枠の色を取り出す
var r2 = Convert.ToByte((oPx >> 16) & 0xff);
var g2 = Convert.ToByte((oPx >> 8) & 0xff);
var b2 = Convert.ToByte((oPx) & 0xff);
// アルファ値を元に合成
var a3 = Convert.ToByte((a * (1.0 - ax2) + a2 * ax2));
var r3 = Convert.ToByte((r * (1.0 - ax2) + r2 * ax2));
var g3 = Convert.ToByte((g * (1.0 - ax2) + g2 * ax2));
var b3 = Convert.ToByte((b * (1.0 - ax2) + b2 * ax2));
wb.Pixels[i] = a3 << 24 | r3 << 16 | g3 << 8 | b3;
}
}
wb.Invalidate();
return wb;
}
示例5: ConvertToWriteableBitmap
/// <summary>
/// ストリームを WriteableBitmap に変換します。
/// </summary>
/// <param name="st"></param>
/// <returns></returns>
private WriteableBitmap ConvertToWriteableBitmap(Stream st)
{
using (var s = PictureExtension.PhotoStreamToMemoryStream(st))
{
try
{
var size = PictureExtension.GetOriginalSize(s);
WriteableBitmap bitmap = null;
bitmap = new WriteableBitmap((int)size.Width, (int)size.Height);
// WriteableBitmapに画像を読み込ませる
s.Seek(0, SeekOrigin.Begin);
bitmap.LoadJpeg(s);
return bitmap;
}
catch
{
return null;
}
}
}
示例6: photoChooserTask_Completed
void photoChooserTask_Completed(object sender, PhotoResult e)
{
if (e.TaskResult == TaskResult.OK)
{
App.firstAccess = true;
WriteableBitmap image = new WriteableBitmap(160, 120);
image.LoadJpeg(e.ChosenPhoto);
userPic.Source = image;
userPic.Height = image.PixelHeight;
userPic.Width = image.PixelWidth;
MemoryStream ms = new MemoryStream();
image.SaveJpeg(ms, image.PixelWidth, image.PixelHeight, 0, 100);
byte[] imageData = ms.ToArray();
//upload new user pic
Service1Client client = new Service1Client();
client.UploadUserImageCompleted += new EventHandler<UploadUserImageCompletedEventArgs>(client_UploadUserImageCompleted);
client.UploadUserImageAsync(App.currentUser.Name, "JPEG", imageData);
}
}
示例7: client_GetUserImageCompleted
/* Fetch user's new profile image. Also writes the image to the siolated storage */
void client_GetUserImageCompleted(object sender, GetUserImageCompletedEventArgs e)
{
if (e.Result != null)
{
WriteableBitmap image = new WriteableBitmap(160, 120);
MemoryStream ms = new MemoryStream(e.Result);
image.LoadJpeg(ms);
//Image userImage = DynamicPanel.Children.OfType<Image>().First() as Image;
userPic.Source = image;
userPic.Height = image.PixelHeight;
userPic.Width = image.PixelWidth;
IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication();
try
{
if (!myIsolatedStorage.DirectoryExists("MyScience/Images"))
{
myIsolatedStorage.CreateDirectory("MyScience/Images");
}
if (myIsolatedStorage.FileExists("MyScience/Images/" + App.currentUser.Name + ".jpg"))
{
turnOffProgressBar(ProfileProgressBar);
return;
//myIsolatedStorage.DeleteFile("MyScience/Images/" + App.currentUser.Name + ".jpg");
}
IsolatedStorageFileStream fileStream = myIsolatedStorage.CreateFile("MyScience/Images/" + App.currentUser.Name + ".jpg");
image.SaveJpeg(fileStream, image.PixelWidth, image.PixelHeight, 0, 100);
fileStream.Close();
}
catch (Exception ex){ }
}
turnOffProgressBar(ProfileProgressBar);
}
示例8: camera_CaptureImageAvailable
// ---
private void camera_CaptureImageAvailable(object sender, ContentReadyEventArgs e)
{
capturing = false;
Stream imageStream = (Stream)e.ImageStream;
BarcodeDecoder barcodeDecoder = new BarcodeDecoder();
Dictionary<DecodeOptions, object> decodingOptions =
new Dictionary<DecodeOptions, object>();
List<BarcodeFormat> possibleFormats = new List<BarcodeFormat>(1);
Result result;
Dispatcher.BeginInvoke(
() =>
{
WriteableBitmap qrImage = new WriteableBitmap((int)camera.Resolution.Width, (int)camera.Resolution.Height);
imageStream.Position = 0;
qrImage.LoadJpeg(imageStream);
possibleFormats.Add(BarcodeFormat.QRCode);
decodingOptions.Add(
DecodeOptions.PossibleFormats,
possibleFormats);
try
{
result = barcodeDecoder.Decode(qrImage, decodingOptions);
resultText.Text = result.Text;
VerDonoButton.Visibility = System.Windows.Visibility.Visible;
foreach (var animal in PerfisControl.GetPerfilByEmail("[email protected]").Animais)
{
if (animal.Especie.Equals("Ovelha"))
{
LocalizacoesControl.InsertLocalizacao(new Localizacao()
{
DataHora = DateTime.Now,
Coordenada = new GeoCoordinate(-3.1243974, -59.9838239),
AnimalId = animal.Id
});
}
}
//resultText.Text = "Animal identificado.";
//StkQRInfo.Visibility = Visibility.Visible;
//StkQRInfo.DataContext = new QRInfo(0);
}
catch (NotFoundException)
{
// this is expected if the image does not contain a valid
// code, Or is too distorted to read
resultText.Text = "Imagem não identificada. Aponte a câmera para o código QR na coleira do animal.";
VerDonoButton.Visibility = System.Windows.Visibility.Collapsed;
}
catch (Exception ex)
{
// something else went wrong, so alert the user
MessageBox.Show(
ex.Message,
"Erro ao decodificar a imagem",
MessageBoxButton.OK);
}
}
);
}
示例9: CameraOnCaptureImageAvailable
private void CameraOnCaptureImageAvailable(object sender, ContentReadyEventArgs contentReadyEventArgs)
{
Dispatcher.BeginInvoke(delegate()
{
WriteableBitmap bitmap = new WriteableBitmap((int)camera.Resolution.Width, (int)camera.Resolution.Height);
contentReadyEventArgs.ImageStream.Position = 0;
bitmap.LoadJpeg(contentReadyEventArgs.ImageStream);
PhoneApplicationService.Current.State["obraz"] = bitmap;
// NavigationService.Navigate(new Uri("/result.xaml", UriKind.Relative));
});
}
示例10: PhotoChooserTask_Completed_Async
/// <summary>
/// Called when an image has been selected using PhotoChooserTask.
/// </summary>
/// <param name="sender">PhotoChooserTask that is completed.</param>
/// <param name="e">Result of the task, including chosen photo.</param>
private async void PhotoChooserTask_Completed_Async(object sender, PhotoResult e)
{
if (e.TaskResult == TaskResult.OK && e.ChosenPhoto != null)
{
DataContext dataContext = FilterEffects.DataContext.Instance;
// Reset the streams
dataContext.ResetStreams();
// Use the largest possible dimensions
WriteableBitmap bitmap = new WriteableBitmap(3552, 2448);
BitmapImage image = new BitmapImage();
image.SetSource(e.ChosenPhoto);
try
{
// Jpeg images can be used as such
bitmap.LoadJpeg(e.ChosenPhoto);
e.ChosenPhoto.Position = 0;
e.ChosenPhoto.CopyTo(dataContext.FullResolutionStream);
}
catch (Exception /*ex*/)
{
// Image format is not jpeg. Can be anything, so first
// load it into a bitmap image and then write as jpeg
bitmap = new WriteableBitmap(image);
bitmap.SaveJpeg(dataContext.FullResolutionStream, image.PixelWidth, image.PixelHeight, 0, 100);
}
dataContext.SetFullResolution(image.PixelWidth, image.PixelHeight);
dataContext.PreviewResolution = new Windows.Foundation.Size(
FilterEffects.DataContext.DefaultPreviewResolutionWidth, 0);
int previewWidth = (int)FilterEffects.DataContext.DefaultPreviewResolutionWidth;
int previewHeight = 0;
AppUtils.CalculatePreviewResolution(
(int)dataContext.FullResolution.Width, (int)dataContext.FullResolution.Height,
ref previewWidth, ref previewHeight);
dataContext.SetPreviewResolution(previewWidth, previewHeight);
await AppUtils.ScaleImageStreamAsync(
e.ChosenPhoto, dataContext.PreviewResolutionStream, dataContext.PreviewResolution);
// Get the storyboard from application resources
Storyboard sb = (Storyboard)Resources["CaptureAnimation"];
sb.Begin();
NavigationService.Navigate(new Uri("/PreviewPage.xaml", UriKind.Relative));
}
}
示例11: PhotoChooserTask_Completed
/// <summary>
/// Called when an image has been selected using PhotoChooserTask.
/// </summary>
/// <param name="sender">PhotoChooserTask that is completed.</param>
/// <param name="e">Result of the task, including chosen photo.</param>
void PhotoChooserTask_Completed(object sender, PhotoResult e)
{
if (e.TaskResult == TaskResult.OK && e.ChosenPhoto != null)
{
DataContext dataContext = FilterEffects.DataContext.Singleton;
// Reset the streams
dataContext.CreateStreams();
// Use the largest possible dimensions
WriteableBitmap bitmap = new WriteableBitmap(3552, 2448);
try
{
// Jpeg images can be used as such.
bitmap.LoadJpeg(e.ChosenPhoto);
e.ChosenPhoto.Position = 0;
e.ChosenPhoto.CopyTo(dataContext.ImageStream);
}
catch (Exception /*ex*/)
{
// Image format is not jpeg. Can be anything, so first
// load it into a bitmap image and then write as jpeg.
BitmapImage image = new BitmapImage();
image.SetSource(e.ChosenPhoto);
bitmap = new WriteableBitmap(image);
bitmap.SaveJpeg(dataContext.ImageStream, image.PixelWidth, image.PixelHeight, 0, 100);
}
// Get the storyboard from application resources
Storyboard sb = (Storyboard)Resources["CaptureAnimation"];
sb.Begin();
NavigationService.Navigate(new Uri("/FilterPreviewPage.xaml", UriKind.Relative));
}
}
示例12: photoChooserTask_Completed
void photoChooserTask_Completed(object sender, PhotoResult e)
{
if (e.TaskResult == TaskResult.OK)
{
WriteableBitmap image = new WriteableBitmap(2560, 1920);
//image.SetSource(e.ChosenPhoto);
image.LoadJpeg(e.ChosenPhoto);
Image photo = DynamicPanel.Children.OfType<Image>().First() as Image;
photo.Source = image;
photo.Height = 210;
photo.Width = 280;
}
}
示例13: BuildItemToolTip
//.........这里部分代码省略.........
if (ViewModel.ItemForToolTip.BuyPrice > 0)
{
var stackPanelCost = new StackPanel();
stackPanelCost.Orientation = System.Windows.Controls.Orientation.Horizontal;
if (ViewModel.ItemForToolTip.BuyPriceObject.Gold > 0)
{
var goldText = new TextBlock();
goldText.Text = ViewModel.ItemForToolTip.BuyPriceObject.Gold.ToString();
goldText.Style = normalStyle;
goldText.VerticalAlignment = VerticalAlignment.Center;
stackPanelCost.Children.Add(goldText);
var goldImage = new Image();
goldImage.Source = CacheManager.GetImageSourceFromCache("/WowArmory.Core;Component/Images/Coin_Gold.png");
goldImage.Width = 24;
goldImage.Height = 17;
goldImage.Margin = new Thickness(6, 0, 6, 0);
goldImage.VerticalAlignment = VerticalAlignment.Center;
stackPanelCost.Children.Add(goldImage);
}
if (ViewModel.ItemForToolTip.BuyPriceObject.Silver > 0)
{
var silverText = new TextBlock();
silverText.Text = ViewModel.ItemForToolTip.BuyPriceObject.Silver.ToString();
silverText.Style = normalStyle;
silverText.VerticalAlignment = VerticalAlignment.Center;
stackPanelCost.Children.Add(silverText);
var silverImage = new Image();
silverImage.Source = CacheManager.GetImageSourceFromCache("/WowArmory.Core;Component/Images/Coin_Silver.png");
silverImage.Width = 24;
silverImage.Height = 17;
silverImage.Margin = new Thickness(6, 0, 6, 0);
silverImage.VerticalAlignment = VerticalAlignment.Center;
stackPanelCost.Children.Add(silverImage);
}
if (ViewModel.ItemForToolTip.BuyPriceObject.Copper > 0)
{
var copperText = new TextBlock();
copperText.Text = ViewModel.ItemForToolTip.BuyPriceObject.Copper.ToString();
copperText.Style = normalStyle;
copperText.VerticalAlignment = VerticalAlignment.Center;
stackPanelCost.Children.Add(copperText);
var copperImage = new Image();
copperImage.Source = CacheManager.GetImageSourceFromCache("/WowArmory.Core;Component/Images/Coin_Copper.png");
copperImage.Width = 24;
copperImage.Height = 17;
copperImage.Margin = new Thickness(6, 0, 0, 0);
copperImage.VerticalAlignment = VerticalAlignment.Center;
stackPanelCost.Children.Add(copperImage);
}
AddSourceInformation(spItemToolTipSource, AppResources.Item_Source_VendorCost, stackPanelCost);
}
sbWowheadVendorLink.Visibility = Visibility.Visible;
}
else if (ViewModel.ItemForToolTip.ItemSource.SourceType.Equals("CREATED_BY_SPELL", StringComparison.CurrentCultureIgnoreCase))
{
sbWowheadSpellLink.Visibility = Visibility.Visible;
}
spItemToolTipSource.Visibility = Visibility.Visible;
}
}
// 3d item viewer
if (AppSettingsManager.Is3DItemViewerEnabled)
{
var webClient = new WebClient();
webClient.OpenReadCompleted += delegate(object senderInternal, OpenReadCompletedEventArgs openReadCompletedEventArgs)
{
try
{
_itemImageWidth = 6720;
_itemFrameWidth = 280;
_itemMaxFrames = _itemImageWidth / _itemFrameWidth;
_writeableBitmap = new WriteableBitmap(_itemImageWidth, _itemFrameWidth);
_writeableBitmap.LoadJpeg(openReadCompletedEventArgs.Result);
cvItemViewerSpriteStrip.Width = _itemFrameWidth;
cvItemViewerSpriteStrip.Height = _itemFrameWidth;
rgItemViewerSpriteStrip.Rect = new Rect(0, 0, _itemFrameWidth, _itemFrameWidth);
imgItemViewerSpriteStrip.Width = _itemImageWidth;
imgItemViewerSpriteStrip.Height = _itemFrameWidth;
imgItemViewerSpriteStrip.Source = _writeableBitmap;
Canvas.SetLeft(imgItemViewerSpriteStrip, 0);
Canvas.SetTop(imgItemViewerSpriteStrip, 0);
sbItemViewer.Visibility = Visibility.Visible;
}
catch (Exception ex)
{
// do nothing
}
};
webClient.OpenReadAsync(new Uri(BattleNetClient.Current.GetItemRenderUrl(ViewModel.ItemForToolTip.Id)));
}
// external links
spItemToolTipExternalLinks.Visibility = Visibility.Visible;
}
示例14: GetWriteableBitmap
/// <summary>
/// Converts the current Image into a WriteableBitmap.
/// This method will be dispatched to the UI thread if called from a background thread.
/// </summary>
/// <param name="Width">Width of desired return image (Required)</param>
/// <param name="Height">Optional height of return image. Will maintain original aspect ratio if Height == 0.</param>
/// <param name="ImageStream">Optional stream to original image (Use Camera PhotoResult or Application.GetResourceStream). Will use BarcodeImage.UriSource if omitted.</param>
public WriteableBitmap GetWriteableBitmap(int Width, int Height = 0, System.IO.Stream ImageStream = null)
{
//WARNING: I kept getting Null Pointer Exceptions "Invalid pointer" in "MS.Internal.XcpImports.CheckHResult" when creating WriteableBitmap from resource or content files
//Seems like it works so long as the BitmapImage object was created in calling page and is set to the Source of an Image Control
//Errors also occur when URI does not have a leading slash (ie: background.png instead of /background.png
//Code from: http://msdn.microsoft.com/en-us/library/ff967560(v=VS.92).aspx#CodeSpippet1
//Question: why does LoadOriginalImage() require Application.GetResourceStream(new Uri (UriImage.OriginalString.TrimStart('/'), UriKind.Relative)); //TODO: Figure out why this works!!!
//NOTE issues with accessing image from background thread. http://stackoverflow.com/questions/1924408/invalid-cross-thread-access-issue
//Cannot create a WriteableBitmap from background thread or access BarcodeImage.PixelWidth/Height properties.
if (!WP7Utilities.isUIThread) //Invoke on dispatcher if method called from background thread
{
WriteableBitmap wbReturn = new WriteableBitmap(0, 0);
using (var are = new System.Threading.AutoResetEvent(false)) //Use AutoResetEvent to wait for results from dispatcher
{
WP7Utilities.UIThreadInvoke(() => //Invoke method on UI Thread
{
wbReturn = GetWriteableBitmap(Width, Height, ImageStream);
are.Set(); //Signal background thread
});
are.WaitOne(); //Wait for signal from dispatch thread;
}
return wbReturn;
}
else //called from UI Thread so process image
{
try {
if (BarcodeImage == null) {
ExceptionThrown = new NullReferenceException("BarcodeImage must be set before you can call SetupBarcodeImages.");
throw ExceptionThrown;
}
if (Height == 0)//Calculate new height using original aspect ratio
{
Height = (int)(Width * ((Double)BarcodeImage.PixelHeight) / (double)BarcodeImage.PixelWidth);
}
wbBarcodeImage = new WriteableBitmap(Width, Height);//set height and width of new image. Use wbBarcodeImage to cache results.
if (ImageStream == null)//Use BarcodeImage.UriSource if stream is not provided
{
System.Windows.Resources.StreamResourceInfo sri = null;
if (BarcodeImage.UriSource.OriginalString == "")//Special code if image comes from camera
{
//Can't access source image, so just return a WriteableBitmap of current Bitmap
System.Diagnostics.Debug.WriteLine("Warning: GetWriteableBitmap Could not locate image UriSource. Original image cannot be loaded.");
return new WriteableBitmap(BarcodeImage); //TODO: use new EXIF information to get original size information.
}
sri = Application.GetResourceStream(BarcodeImage.UriSource);
if (sri == null) //Check if object was found
{
sri = Application.GetResourceStream(new Uri(BarcodeImage.UriSource.OriginalString.TrimStart('/'), UriKind.Relative)); //try without leading / TODO: Figure out why this works!!
}
if (sri != null) {
ImageStream = sri.Stream; //Update imagestream that will be used for processing
}
else //GetResourceStream can't load all types, so fall back on standard load.
{
//wbBarcodeImage = new WriteableBitmap(BarcodeImage);//TODO: Make sure image is 640x480
throw new Exception("GetWriteableBitmap cannot open image stream.");
}
}
else //ImageStream was provided by caller
{
ImageStream.Seek(0, System.IO.SeekOrigin.Begin); // Seek to the beginning of the stream
}
wbBarcodeImage.LoadJpeg(ImageStream);//Load JPEG from stream into our re-sized writeable bitmap
return wbBarcodeImage;
}
catch (Exception ex) {
ExceptionThrown = new InvalidOperationException("Error: Cannot create WriteableBitmap.\r\n", ex); //store exception
throw ExceptionThrown;
}
}
}
示例15: cameraCaptureTask_ImgNeg90Deg_Completed
private void cameraCaptureTask_ImgNeg90Deg_Completed(object sender, PhotoResult e)
{
if (e.TaskResult == TaskResult.OK)
{
info = ExifLib.ExifReader.ReadJpeg(e.ChosenPhoto, e.OriginalFileName);
//wbmpNeg90 = new WriteableBitmap(info.Width, info.Height);
wbmpNeg90 = new WriteableBitmap(1282, 720);
e.ChosenPhoto.Position = 0;
wbmpNeg90.LoadJpeg(e.ChosenPhoto);
imgNeg90Deg.Source = wbmpNeg90;
//BitmapImage bitmap = new BitmapImage();
//bitmap.SetSource(e.ChosenPhoto);
//imgNeg90Deg.Source = bitmap;
}
else if (e.TaskResult == TaskResult.Cancel)
return;// MessageBox.Show("Photo was not captured - operation was cancelled", "Photo not captured", MessageBoxButton.OK);
else
MessageBox.Show("Error while capturing photo:\n" + e.Error.Message, "Fail", MessageBoxButton.OK);
}