本文整理汇总了C#中Windows.UI.Xaml.Media.Imaging.WriteableBitmap.SetSourceAsync方法的典型用法代码示例。如果您正苦于以下问题:C# WriteableBitmap.SetSourceAsync方法的具体用法?C# WriteableBitmap.SetSourceAsync怎么用?C# WriteableBitmap.SetSourceAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Windows.UI.Xaml.Media.Imaging.WriteableBitmap
的用法示例。
在下文中一共展示了WriteableBitmap.SetSourceAsync方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ButtonFilePick_Click
private async void ButtonFilePick_Click(object sender, RoutedEventArgs e)
{
var picker = new FileOpenPicker();
picker.ViewMode = PickerViewMode.Thumbnail;
picker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
picker.FileTypeFilter.Add(".jpg");
picker.FileTypeFilter.Add(".jpeg");
picker.FileTypeFilter.Add(".png");
StorageFile file = await picker.PickSingleFileAsync();
if (file != null)
{
ImageProperties imgProp = await file.Properties.GetImagePropertiesAsync();
var savedPictureStream = await file.OpenAsync(FileAccessMode.Read);
//set image properties and show the taken photo
bitmap = new WriteableBitmap((int)imgProp.Width, (int)imgProp.Height);
await bitmap.SetSourceAsync(savedPictureStream);
BBQImage.Source = bitmap;
BBQImage.Visibility = Visibility.Visible;
(this.DataContext as BBQRecipeViewModel).imageSource = file.Path;
}
}
示例2: Page_Loaded
private async void Page_Loaded(object sender, RoutedEventArgs e)
{
await InitializeQrCode();
var imgProp = new ImageEncodingProperties { Subtype = "BMP", Width = 600, Height = 800 };
var bcReader = new BarcodeReader();
while (true)
{
var stream = new InMemoryRandomAccessStream();
await _mediaCapture.CapturePhotoToStreamAsync(imgProp, stream);
stream.Seek(0);
var wbm = new WriteableBitmap(600, 800);
await wbm.SetSourceAsync(stream);
var result = bcReader.Decode(wbm);
if (result != null)
{
var msgbox = new MessageDialog(result.Text);
await msgbox.ShowAsync();
}
}
}
示例3: OCRAsync
async Task<string> OCRAsync(byte[] buffer, uint width, uint height)
{
var bitmap = new WriteableBitmap((int)width, (int)height);
var memoryStream = new MemoryStream(buffer);
await bitmap.SetSourceAsync(memoryStream.AsRandomAccessStream());
if (bitmap.PixelHeight < 40 ||
bitmap.PixelHeight > 2600 ||
bitmap.PixelWidth < 40 ||
bitmap.PixelWidth > 2600)
bitmap = await ResizeImage(bitmap, (uint)(bitmap.PixelWidth * .7), (uint)(bitmap.PixelHeight * .7));
var ocrResult = await ocrEngine.RecognizeAsync((uint)bitmap.PixelHeight, (uint)bitmap.PixelWidth, bitmap.PixelBuffer.ToArray());
if (ocrResult.Lines != null)
{
var extractedText = new StringBuilder();
foreach (var line in ocrResult.Lines)
{
foreach (var word in line.Words)
extractedText.Append(word.Text + " ");
extractedText.Append(Environment.NewLine);
}
return extractedText.ToString();
}
return null;
}
示例4: ScanBarcodeAsync
public async Task ScanBarcodeAsync(Windows.Storage.StorageFile file)
{
WriteableBitmap bitmap;
BitmapDecoder decoder;
using (IRandomAccessStream str = await file.OpenReadAsync())
{
decoder = await BitmapDecoder.CreateAsync(str);
bitmap = new WriteableBitmap(Convert.ToInt32(decoder.PixelWidth), Convert.ToInt32(decoder.PixelHeight));
await bitmap.SetSourceAsync(str);
}
lock (locker)
{
ZXing.BarcodeReader reader = new ZXing.BarcodeReader();
reader.Options.PossibleFormats = new ZXing.BarcodeFormat[] { ZXing.BarcodeFormat.CODE_128, ZXing.BarcodeFormat.QR_CODE, ZXing.BarcodeFormat.CODE_39 };
reader.Options.TryHarder = true;
reader.AutoRotate = true;
var results = reader.Decode(bitmap);
if (results == null)
{
this.OnBarcodeScannCompleted(new BarcodeScanCompletedEventArgs(false, string.Empty));
}
else
{
this.OnBarcodeScannCompleted(new BarcodeScanCompletedEventArgs(true, results.Text));
}
}
}
示例5: SelectImageFromPicker
async Task<WriteableBitmap> SelectImageFromPicker()
{
var picker = new FileOpenPicker();
picker.ViewMode = PickerViewMode.Thumbnail;
picker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
picker.FileTypeFilter.Add(".jpg");
picker.FileTypeFilter.Add(".jpeg");
picker.FileTypeFilter.Add(".png");
StorageFile file = await picker.PickSingleFileAsync();
if (file != null)
{
ImageProperties imgProp = await file.Properties.GetImagePropertiesAsync();
var savedPictureStream = await file.OpenAsync(FileAccessMode.Read);
//set image properties and show the taken photo
bitmap = new WriteableBitmap((int)imgProp.Width, (int)imgProp.Height);
await bitmap.SetSourceAsync(savedPictureStream);
bitmap.Invalidate();
SaveImageAsync(file);
return bitmap;
}
else return null;
}
示例6: LoadIcon
private async Task<BandIcon> LoadIcon(string uri)
{
StorageFile imageFile = await StorageFile.GetFileFromApplicationUriAsync(new Uri(uri));
using (IRandomAccessStream fileStream = await imageFile.OpenAsync(FileAccessMode.Read))
{
WriteableBitmap bitmap = new WriteableBitmap(1, 1);
await bitmap.SetSourceAsync(fileStream);
return bitmap.ToBandIcon();
}
}
示例7: GetWriteableBitmap
private static async Task<WriteableBitmap> GetWriteableBitmap(Uri uri)
{
var imageFile = await StorageFile.GetFileFromApplicationUriAsync(uri);
using (var fileStream = await imageFile.OpenAsync(FileAccessMode.Read))
{
var writeableBitmap = new WriteableBitmap(1, 1);
await writeableBitmap.SetSourceAsync(fileStream);
return writeableBitmap;
}
}
示例8: GetPictureAsync
public static async Task<WriteableBitmap> GetPictureAsync(StorageFile ImageFile)
{
using (IRandomAccessStream stream = await ImageFile.OpenAsync(FileAccessMode.Read))
{
BitmapDecoder decoder = await BitmapDecoder.CreateAsync(stream);
WriteableBitmap bmp = new WriteableBitmap((int)decoder.PixelWidth, (int)decoder.PixelHeight);
await bmp.SetSourceAsync(stream);
return bmp;
}
}
示例9: GetThumbnail
private async void GetThumbnail()
{
DeviceThumbnail thumb = await _information.GetGlyphThumbnailAsync();
Stream s = thumb.AsStreamForRead();
MemoryStream ms = new MemoryStream();
await s.CopyToAsync(ms);
ms.Seek(0, SeekOrigin.Begin);
WriteableBitmap wb = new WriteableBitmap(1, 1);
await wb.SetSourceAsync(ms.AsRandomAccessStream());
_thumbnail = wb;
OnPropertyChanged("Thumbnail");
}
示例10: Quadraliteral
public async void Quadraliteral(StorageFile file, IList<WF.Point> points)
{
var data = await FileIO.ReadBufferAsync(file);
OpencvImageProcess opencv = new OpencvImageProcess();
// create a stream from the file
var ms = new InMemoryRandomAccessStream();
var dw = new DataWriter(ms);
dw.WriteBuffer(data);
await dw.StoreAsync();
ms.Seek(0);
// find out how big the image is, don't need this if you already know
var bm = new BitmapImage();
await bm.SetSourceAsync(ms);
// create a writable bitmap of the right size
var wb = new WriteableBitmap(bm.PixelWidth, bm.PixelHeight);
ms.Seek(0);
// load the writable bitpamp from the stream
await wb.SetSourceAsync(ms);
Bitmap bmp = (Bitmap)wb;
var wb1 = opencv.GetImageCorners(wb);
wb1.Invalidate();
//wb.Invalidate();
// define quadrilateral's corners
//List<IntPoint> corners = new List<IntPoint>();
//foreach (var point in points)
//{
// corners.Add(new IntPoint((int)point.X, (int)point.Y));
//}
//// create filter
//var filter =
// new SimpleQuadrilateralTransformation(corners);
//// apply the filter
//Bitmap newImage = filter.Apply(bmp);
//wb = (WriteableBitmap)newImage;
var f = await this.WriteableBitmapToStorageFile(wb1, FileFormat.Jpeg);
}
示例11: ReportPhoto
public ReportPhoto(StorageFile file)
{
FilePath = file.Path;
StorageItemThumbnail thumbnail = file.GetThumbnailAsync(ThumbnailMode.ListView).AsTask().Result;
BitmapImage thumbnailImage = new BitmapImage();
var ignore = thumbnailImage.SetSourceAsync(thumbnail);
ThumbnailSource = thumbnailImage;
StorageItemThumbnail imageAsThumbnail = file.GetScaledImageAsThumbnailAsync(ThumbnailMode.SingleItem).AsTask().Result;
WriteableBitmap bitmap = new WriteableBitmap((int)imageAsThumbnail.OriginalWidth, (int)imageAsThumbnail.OriginalHeight);
ignore = bitmap.SetSourceAsync(imageAsThumbnail);
Bitmap = bitmap;
}
示例12: TakePhoto
private async Task<StorageFile> TakePhoto()
{
StorageFile filestr = await USBCam.TakePhotoAsync("picture.jpg");
Debug.WriteLine(string.Format("File name: {0}", filestr.Name));
using (IRandomAccessStream myfileStream = await filestr.OpenAsync(FileAccessMode.Read))
{
WriteableBitmap bitmap = new WriteableBitmap(1, 1);
await bitmap.SetSourceAsync(myfileStream);
FacePhoto.Source = bitmap;
}
return filestr;
}
示例13: FromBase64
public static async Task<ImageSource> FromBase64(string base64)
{
// read stream
var bytes = Convert.FromBase64String(base64);
var image = bytes.AsBuffer().AsStream().AsRandomAccessStream();
// decode image
var decoder = await BitmapDecoder.CreateAsync(image);
image.Seek(0);
// create bitmap
var output = new WriteableBitmap((int) decoder.PixelHeight, (int) decoder.PixelWidth);
await output.SetSourceAsync(image);
return output;
}
示例14: ConvertFromEncodedStream
public async Task<object> ConvertFromEncodedStream(Stream encodedStream, int width, int height)
{
if (encodedStream == null)
return null;
var image = new WriteableBitmap(width, height);
encodedStream.Seek(0, SeekOrigin.Begin);
await image.SetSourceAsync(encodedStream.AsRandomAccessStream());
return image;
//var writeableImage = new WriteableBitmap(image.PixelWidth, image.PixelHeight);
//image.SetSource(encodedStream.AsRandomAccessStream());
//return writeableImage;
}
示例15: LoadImageAsync
public async Task LoadImageAsync()
{
using (var stream = await file.OpenReadAsync())
{
WriteableBitmap bitmap = new WriteableBitmap(width, height);
await bitmap.SetSourceAsync(stream);
using (var buffer = bitmap.PixelBuffer.AsStream())
{
pixels = new Byte[4 * width * height];
buffer.Read(pixels, 0, pixels.Length);
}
this.bitmap = bitmap;
}
}