本文整理汇总了C#中Windows.UI.Xaml.Media.Imaging.WriteableBitmap.SetSource方法的典型用法代码示例。如果您正苦于以下问题:C# WriteableBitmap.SetSource方法的具体用法?C# WriteableBitmap.SetSource怎么用?C# WriteableBitmap.SetSource使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Windows.UI.Xaml.Media.Imaging.WriteableBitmap
的用法示例。
在下文中一共展示了WriteableBitmap.SetSource方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ToBitmapImageAsync
public async static Task<WriteableBitmap> ToBitmapImageAsync(this byte[] imageBytes, Tuple<int, int> downscale)
{
if (imageBytes == null)
return null;
IRandomAccessStream image = imageBytes.AsBuffer().AsStream().AsRandomAccessStream();
if (downscale != null && (downscale.Item1 > 0 || downscale.Item2 > 0))
{
image = await image.ResizeImage((uint)downscale.Item1, (uint)downscale.Item2);
}
using (image)
{
BitmapDecoder decoder = await BitmapDecoder.CreateAsync(image);
image.Seek(0);
WriteableBitmap bitmap = null;
await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Low, () =>
{
bitmap = new WriteableBitmap((int)decoder.PixelWidth, (int)decoder.PixelHeight);
bitmap.SetSource(image);
});
return bitmap;
}
}
示例2: clipboard
public async Task<string> clipboard(DataPackageView con)
{
string str = string.Empty;
//文本
if (con.Contains(StandardDataFormats.Text))
{
str = await con.GetTextAsync();
return str;
}
//图片
if (con.Contains(StandardDataFormats.Bitmap))
{
RandomAccessStreamReference img = await con.GetBitmapAsync();
var imgstream = await img.OpenReadAsync();
BitmapImage bitmap = new BitmapImage();
bitmap.SetSource(imgstream);
WriteableBitmap src = new WriteableBitmap(bitmap.PixelWidth, bitmap.PixelHeight);
src.SetSource(imgstream);
BitmapDecoder decoder = await BitmapDecoder.CreateAsync(imgstream);
PixelDataProvider pxprd =
await
decoder.GetPixelDataAsync(BitmapPixelFormat.Bgra8, BitmapAlphaMode.Straight,
new BitmapTransform(), ExifOrientationMode.RespectExifOrientation,
ColorManagementMode.DoNotColorManage);
byte[] buffer = pxprd.DetachPixelData();
str = "image";
StorageFolder folder = await _folder.GetFolderAsync(str);
StorageFile file =
await
folder.CreateFileAsync(
DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() +
DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() +
(ran.Next()%10000).ToString() + ".png", CreationCollisionOption.GenerateUniqueName);
using (var fileStream = await file.OpenAsync(FileAccessMode.ReadWrite))
{
var encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.PngEncoderId, fileStream);
encoder.SetPixelData(BitmapPixelFormat.Bgra8, BitmapAlphaMode.Straight, decoder.PixelWidth,
decoder.PixelHeight, decoder.DpiX, decoder.DpiY, buffer);
await encoder.FlushAsync();
str = $"![这里写图片描述](image/{file.Name})\n";
}
}
//文件
if (con.Contains(StandardDataFormats.StorageItems))
{
var filelist = await con.GetStorageItemsAsync();
StorageFile file = filelist.OfType<StorageFile>().First();
return await imgfolder(file);
}
return str;
}
示例3: LoadImageAsync
public async Task<BitmapSource> LoadImageAsync(Stream imageStream, Uri uri)
{
if (imageStream == null)
{
return null;
}
var stream = new InMemoryRandomAccessStream();
imageStream.CopyTo(stream.AsStreamForWrite());
stream.Seek(0);
BitmapImage bitmap = new BitmapImage();
await bitmap.SetSourceAsync(stream);
// convert to a writable bitmap so we can get the PixelBuffer back out later...
// in case we need to edit and/or re-encode the image.
WriteableBitmap bmp = new WriteableBitmap(bitmap.PixelHeight, bitmap.PixelWidth);
stream.Seek(0);
bmp.SetSource(stream);
List<Byte> allBytes = new List<byte>();
byte[] buffer = new byte[4000];
int bytesRead = 0;
while ((bytesRead = await imageStream.ReadAsync(buffer, 0, 4000)) > 0)
{
allBytes.AddRange(buffer.Take(bytesRead));
}
DataContainerHelper.Instance.WriteableBitmapToStorageFile(bmp, uri);
return bmp;
}
示例4: LoadWriteableBitmap
/// <summary>
/// Return WriteableBitmap object from a given path
/// </summary>
/// <param name="relativePath">file path</param>
/// <returns>WriteableBitmap</returns>
public static async Task<WriteableBitmap> LoadWriteableBitmap(string relativePath)
{
var storageFile = await Package.Current.InstalledLocation.GetFileAsync(relativePath.Replace('/', '\\'));
var stream = await storageFile.OpenReadAsync();
var wb = new WriteableBitmap(1, 1);
wb.SetSource(stream);
return wb;
}
示例5: RetrieveAndPutBitmapAsync
public async Task<WriteableBitmap> RetrieveAndPutBitmapAsync(StorageFile file)
{
IRandomAccessStream contents = await file.OpenAsync(FileAccessMode.Read);
WriteableBitmap bitmap = new WriteableBitmap(100, 100);
bitmap.SetSource(contents);
_cache.Add(new BitmapCacheItem() { StorageFile = file, Bitmap = bitmap });
Debug.WriteLine("Caching bitmap for file: " + file.Path + "::" + file.Name);
return bitmap;
}
示例6: LoadBitmap
private async Task LoadBitmap(IRandomAccessStream stream)
{
_writeableBitmap = new WriteableBitmap(1, 1);
_writeableBitmap.SetSource(stream);
_writeableBitmap.Invalidate();
await Dispatcher.RunAsync(
Windows.UI.Core.CoreDispatcherPriority.Normal,
() => ImageTarget.Source = _writeableBitmap);
}
示例7: OnNavigatedTo
protected override async void OnNavigatedTo(NavigationEventArgs e)
{
try
{
var cameras = await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture);
if (cameras.Count < 1)
{
Error.Text = "No camera found, decoding static image";
await DecodeStaticResource();
return;
}
MediaCaptureInitializationSettings settings;
if (cameras.Count == 1)
{
settings = new MediaCaptureInitializationSettings { VideoDeviceId = cameras[0].Id }; // 0 => front, 1 => back
}
else
{
settings = new MediaCaptureInitializationSettings { VideoDeviceId = cameras[1].Id }; // 0 => front, 1 => back
}
await _mediaCapture.InitializeAsync(settings);
VideoCapture.Source = _mediaCapture;
await _mediaCapture.StartPreviewAsync();
while (_result == null)
{
var photoStorageFile = await KnownFolders.PicturesLibrary.CreateFileAsync("scan.jpg", CreationCollisionOption.GenerateUniqueName);
await _mediaCapture.CapturePhotoToStorageFileAsync(ImageEncodingProperties.CreateJpeg(), photoStorageFile);
var stream = await photoStorageFile.OpenReadAsync();
// initialize with 1,1 to get the current size of the image
var writeableBmp = new WriteableBitmap(1, 1);
writeableBmp.SetSource(stream);
// and create it again because otherwise the WB isn't fully initialized and decoding
// results in a IndexOutOfRange
writeableBmp = new WriteableBitmap(writeableBmp.PixelWidth, writeableBmp.PixelHeight);
stream.Seek(0);
writeableBmp.SetSource(stream);
_result = ScanBitmap(writeableBmp);
await photoStorageFile.DeleteAsync(StorageDeleteOption.PermanentDelete);
}
await _mediaCapture.StopPreviewAsync();
VideoCapture.Visibility = Visibility.Collapsed;
CaptureImage.Visibility = Visibility.Visible;
ScanResult.Text = _result.Text;
}
catch (Exception ex)
{
Error.Text = ex.Message;
}
}
示例8: LoadImage
private async Task LoadImage(StorageFile file)
{
ImageProperties imgProp = await file.Properties.GetImagePropertiesAsync();
using (var imgStream = await file.OpenAsync(FileAccessMode.Read))
{
bitmap = new WriteableBitmap((int)imgProp.Width, (int)imgProp.Height);
bitmap.SetSource(imgStream);
PreviewImage.Source = bitmap;
}
}
示例9: LoadIcon
private static async Task<BandIcon> LoadIcon(string uri)
{
var imageFile = await StorageFile.GetFileFromApplicationUriAsync(new Uri(uri));
using (var fileStream = await imageFile.OpenAsync(FileAccessMode.Read))
{
var bitmap = new WriteableBitmap(1, 1);
bitmap.SetSource(fileStream);
return bitmap.ToBandIcon();
}
}
示例10: LoadImage
public static async Task<WriteableBitmap> LoadImage(StorageFile file)
{
ImageProperties imgProp = await file.Properties.GetImagePropertiesAsync();
using (var imgStream = await file.OpenAsync(FileAccessMode.Read))
{
WriteableBitmap writeablebitmap = new WriteableBitmap((int)imgProp.Width, (int)imgProp.Height);
writeablebitmap.SetSource(imgStream);
return writeablebitmap;
}
}
示例11: Load
async void Load(string filename)
{
var file = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync(filename);
using (var stream = await file.OpenReadAsync())
{
var bmp = new WriteableBitmap(width, height);
bmp.SetSource(stream);
internalBuffer = bmp.PixelBuffer.ToArray();
}
}
示例12: OnNavigatedTo
protected override async void OnNavigatedTo(NavigationEventArgs e)
{
try
{
var cameras = await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture);
if (cameras.Count < 1)
{
await DecodeStaticResource();
return;
}
MediaCaptureInitializationSettings settings;
settings = cameras.Count == 1 ? new MediaCaptureInitializationSettings { VideoDeviceId = cameras[0].Id } : new MediaCaptureInitializationSettings { VideoDeviceId = cameras[1].Id };
await _mediaCapture.InitializeAsync(settings);
VideoCapture.Source = _mediaCapture;
await _mediaCapture.StartPreviewAsync();
while (_result == null)
{
var photoStorageFile = await KnownFolders.PicturesLibrary.CreateFileAsync("scan.jpg", CreationCollisionOption.GenerateUniqueName);
await _mediaCapture.CapturePhotoToStorageFileAsync(ImageEncodingProperties.CreateJpeg(), photoStorageFile);
var stream = await photoStorageFile.OpenReadAsync();
// initialize with 1,1 to get the current size of the image
var writeableBmp = new WriteableBitmap(1, 1);
writeableBmp.SetSource(stream);
// and create it again because otherwise the WB isn't fully initialized and decoding
// results in a IndexOutOfRange
writeableBmp = new WriteableBitmap(writeableBmp.PixelWidth, writeableBmp.PixelHeight);
stream.Seek(0);
writeableBmp.SetSource(stream);
_result = ScanBitmap(writeableBmp);
if (_result != null)
{
if (!_barcodeFound)
{
Messenger.Default.Send(new NotificationMessage(_result, "ResultFoundMsg"));
_barcodeFound = true;
}
}
await photoStorageFile.DeleteAsync(StorageDeleteOption.PermanentDelete);
}
await _mediaCapture.StopPreviewAsync();
}
catch (Exception ex)
{
var s = "";
}
}
示例13: OnLoadImage
private async void OnLoadImage(IRandomAccessStream imageStream)
{
var image = new WriteableBitmap(1, 1);
image.SetSource(imageStream);
ComicImage.Source = image;
ComicImage.Width = 400;
ComicImage.Height = 300;
imageStream.Dispose();
}
示例14: StorageFileToWriteableBitmap
public static async Task<WriteableBitmap> StorageFileToWriteableBitmap(StorageFile file)
{
if (file == null)
return null;
WriteableBitmap bmp;
using (IRandomAccessStream stream = await file.OpenAsync(FileAccessMode.Read))
{
BitmapDecoder decoder = await BitmapDecoder.CreateAsync(stream);
bmp = new WriteableBitmap((int)decoder.PixelWidth, (int)decoder.PixelHeight);
bmp.SetSource(stream);
}
return bmp;
}
示例15: LoadImage
private async Task<Mat> LoadImage(String imageUri)
{
StorageFile file =
await Package.Current.InstalledLocation.GetFileAsync(imageUri);
using (IRandomAccessStream fileStream = await file.OpenAsync(FileAccessMode.Read))
{
BitmapImage bmpImage = new BitmapImage();
bmpImage.SetSource(fileStream);
WriteableBitmap bmp = new WriteableBitmap(bmpImage.PixelWidth, bmpImage.PixelHeight);
bmp.SetSource(await file.OpenAsync(FileAccessMode.Read));
Mat img = new Mat(bmp);
return img;
}
}