本文整理汇总了C#中Windows.UI.Xaml.Media.Imaging.BitmapImage.SetSourceAsync方法的典型用法代码示例。如果您正苦于以下问题:C# BitmapImage.SetSourceAsync方法的具体用法?C# BitmapImage.SetSourceAsync怎么用?C# BitmapImage.SetSourceAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Windows.UI.Xaml.Media.Imaging.BitmapImage
的用法示例。
在下文中一共展示了BitmapImage.SetSourceAsync方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Update
private async void Update()
{
var writer1 = new BarcodeWriter
{
Format = BarcodeFormat.QR_CODE,
Options = new ZXing.Common.EncodingOptions
{
Height = 200,
Width = 200
},
};
var image = writer1.Write(Text);//Write(text);
using (InMemoryRandomAccessStream ms = new InMemoryRandomAccessStream())
{
using (DataWriter writer = new DataWriter(ms.GetOutputStreamAt(0)))
{
writer.WriteBytes(image);
await writer.StoreAsync();
}
var output = new BitmapImage();
await output.SetSourceAsync(ms);
ImageSource = output;
}
}
示例2: ReadFolderPick
private async void ReadFolderPick()
{
foreach (var temp in FolderStorage)
{
try
{
temp.FolderStorage =
await StorageApplicationPermissions.FutureAccessList.GetFolderAsync(temp.Token);
}
catch (Exception)
{
}
}
foreach (var temp in FolderStorage)
{
//image
try
{
StorageFolder folder = temp.FolderStorage;
string str = "image";
folder = await folder.GetFolderAsync(str);
StorageFile file = await folder.GetFileAsync(str + ".png");
BitmapImage image = new BitmapImage();
await image.SetSourceAsync(await file.OpenAsync(FileAccessMode.Read));
temp.Image = image;
}
catch
{
}
}
}
示例3: OnLoaded
// TODO: test data
private async void OnLoaded(object sender, RoutedEventArgs e)
{
var file = await Package.Current.InstalledLocation.GetFileAsync(@"Assets\service-icon.png");
var videoFile = await Package.Current.InstalledLocation.GetFileAsync(@"Assets\video-test.mp4");
var bitmap = new BitmapImage();
await bitmap.SetSourceAsync(
await ConvertionExtensions.ConvertToInMemoryStream(await ConvertionExtensions.ReadFile(file)));
Details = new RecipientDetailsInfo
{
Name = "Recipient",
Age = 24,
Description = Enumerable.Repeat("I'm so depressed...", 20).Aggregate(string.Empty, (x, y) => x + y),
Image = bitmap,
AdditionalImages = Enumerable.Repeat(bitmap, 10).Cast<ImageSource>().ToArray(),
Wishes = new WishInfo[]
{
new ImageWishInfo {Description = "myWish", Image = bitmap},
new VideoWishInfo
{
Source = await ConvertionExtensions.ReadFile(videoFile),
Description = "myVideoWish",
MimeType = "video/mp4"
}
}
};
}
示例4: GetPhotoAsync
public async Task<BitmapImage> GetPhotoAsync(string photoUrl, string token) {
using (var client = new HttpClient()) {
try {
var request = new HttpRequestMessage(HttpMethod.Get, new Uri(photoUrl));
BitmapImage bitmap = null;
request.Headers.Add("Authorization", "Bearer " + token);
var response = await client.SendAsync(request);
var stream = await response.Content.ReadAsStreamAsync();
if (response.IsSuccessStatusCode) {
using (var memStream = new MemoryStream()) {
await stream.CopyToAsync(memStream);
memStream.Seek(0, SeekOrigin.Begin);
bitmap = new BitmapImage();
await bitmap.SetSourceAsync(memStream.AsRandomAccessStream());
}
return bitmap;
} else {
Debug.WriteLine("Unable to find an image at this endpoint.");
bitmap = new BitmapImage(new Uri("ms-appx:///assets/UserDefault.png", UriKind.RelativeOrAbsolute));
return bitmap;
}
} catch (Exception e) {
Debug.WriteLine("Could not get the thumbnail photo: " + e.Message);
return null;
}
}
}
示例5: Capture_Click
/// <summary>
/// Triggered when the Capture Photo button is clicked by the user
/// </summary>
private async void Capture_Click(object sender, RoutedEventArgs e)
{
// Hide the capture photo button
CaptureButton.Visibility = Visibility.Collapsed;
// Capture current frame from webcam, store it in temporary storage and set the source of a BitmapImage to said photo
currentIdPhotoFile = await webcam.CapturePhoto();
var photoStream = await currentIdPhotoFile.OpenAsync(FileAccessMode.ReadWrite);
BitmapImage idPhotoImage = new BitmapImage();
await idPhotoImage.SetSourceAsync(photoStream);
// Set the soruce of the photo control the new BitmapImage and make the photo control visible
IdPhotoControl.Source = idPhotoImage;
IdPhotoControl.Visibility = Visibility.Visible;
// Collapse the webcam feed or disabled feed grid. Make the enter user name grid visible.
WebcamFeed.Visibility = Visibility.Collapsed;
DisabledFeedGrid.Visibility = Visibility.Collapsed;
UserNameGrid.Visibility = Visibility.Visible;
// Dispose photo stream
photoStream.Dispose();
}
示例6: AsBitmapImage
private static async Task<BitmapImage> AsBitmapImage(this StorageFile file)
{
var stream = await file.OpenAsync(FileAccessMode.Read);
var bitmapImage = new BitmapImage();
await bitmapImage.SetSourceAsync(stream);
return bitmapImage;
}
示例7: LoadAsync
public static async Task<BitmapImage> LoadAsync(StorageFolder folder, string fileName)
{
BitmapImage bitmap = new BitmapImage();
var file = await folder.GetFileByPathAsync(fileName);
return await bitmap.SetSourceAsync(file);
}
示例8: LoadImage
/// <summary>
/// DOwnloads a picture from the specified url.
/// </summary>
/// <param name="uri">The url of the image.</param>
/// <returns>The downloaded image.</returns>
public async static Task<Image> LoadImage(Uri uri)
{
if (uri == null)
{
throw new ArgumentException("The uri object must not be null.");
}
try
{
var streamRef = RandomAccessStreamReference.CreateFromUri(uri);
using (IRandomAccessStreamWithContentType fileStream = await streamRef.OpenReadAsync())
{
var bitmapImage = new BitmapImage(uri);
await bitmapImage.SetSourceAsync(fileStream);
var img = new Image();
img.Source = bitmapImage;
return img;
}
}
catch (Exception ex)
{
Debug.WriteLine("Couldn't load the image: {0}", ex.Message);
}
return null;
}
示例9: fromStorageFile
// Fetches all the data for the specified file
public async static Task<FileItem> fromStorageFile(StorageFile f, CancellationToken ct)
{
FileItem item = new FileItem();
item.Filename = f.DisplayName;
// Block to make sure we only have one request outstanding
await gettingFileProperties.WaitAsync();
BasicProperties bp = null;
try
{
bp = await f.GetBasicPropertiesAsync().AsTask(ct);
}
catch (Exception) { }
finally
{
gettingFileProperties.Release();
}
ct.ThrowIfCancellationRequested();
item.Size = (int)bp.Size;
item.Key = f.FolderRelativeId;
StorageItemThumbnail thumb = await f.GetThumbnailAsync(ThumbnailMode.SingleItem).AsTask(ct);
ct.ThrowIfCancellationRequested();
BitmapImage img = new BitmapImage();
await img.SetSourceAsync(thumb).AsTask(ct);
item.ImageData = img;
return item;
}
示例10: LoadData
public async void LoadData(IEnumerable<XElement> sprites, StorageFile spriteSheetFile, string appExtensionId)
{
var bitmapImage = new BitmapImage();
using (var stream = await spriteSheetFile.OpenReadAsync()) {
await bitmapImage.SetSourceAsync(stream);
}
//xaml
List<ImageListItem> listOfImages = new List<ImageListItem>();
foreach (var sprite in sprites) {
var row = int.Parse(sprite.Attributes("Row").First().Value);
var col = int.Parse(sprite.Attributes("Column").First().Value);
var brush = new ImageBrush();
brush.ImageSource = bitmapImage;
brush.Stretch = Stretch.UniformToFill;
brush.AlignmentX = AlignmentX.Left;
brush.AlignmentY = AlignmentY.Top;
brush.Transform = new CompositeTransform() { ScaleX = 2.35, ScaleY = 2.35, TranslateX = col * (-140), TranslateY = row * (-87) };
listOfImages.Add(new ImageListItem() {
Title = sprite.Attributes("Title").First().Value,
SpriteSheetBrush = brush,
File = sprite.Attributes("File").First().Value,
AppExtensionId = appExtensionId
});
}
lbPictures.ItemsSource = listOfImages;
}
示例11: getItemFromDB
public async void getItemFromDB()
{
this.allItems.Clear();
try
{
var dp = App.conn;
using (var statement = dp.Prepare(@"SELECT * FROM TaskItem"))
{
while (SQLiteResult.ROW == statement.Step())
{
//do with pic
BitmapImage bimage = new BitmapImage();
StorageFile file = await StorageFile.GetFileFromPathAsync((string)statement[4]);
IRandomAccessStream instream = await file.OpenAsync(FileAccessMode.Read);
string boot = Windows.Storage.AccessCache.StorageApplicationPermissions.MostRecentlyUsedList.Add(file);
await bimage.SetSourceAsync(instream);
// 处理时间
DateTime dt;
DateTimeFormatInfo dtFormat = new DateTimeFormatInfo();
dtFormat.ShortDatePattern = "yyyy-MM-dd";
dt = Convert.ToDateTime((string)statement[3], dtFormat);
this.allItems.Add(new Models.TaskItem(statement[0].ToString(), statement[1].ToString(), (string)statement[2], bimage, dt, (string)statement[4], (string)statement[5], (string)statement[6]));
}
}
}
catch
{
return;
}
}
示例12: Base64ToBitmapImage
public async Task<BitmapImage> Base64ToBitmapImage(string base64String)
{
BitmapImage img = new BitmapImage();
if (string.IsNullOrEmpty(base64String))
return img;
using (var ims = new InMemoryRandomAccessStream())
{
byte[] bytes = Convert.FromBase64String(base64String);
base64String = "";
using (DataWriter dataWriter = new DataWriter(ims))
{
dataWriter.WriteBytes(bytes);
bytes = null;
await dataWriter.StoreAsync();
ims.Seek(0);
await img.SetSourceAsync(ims); //not in RC
return img;
}
}
}
示例13: wczytywanie_obrazkow
private async Task wczytywanie_obrazkow()
{
var bounds = Window.Current.Bounds;
int i = 0;
foreach (var x in Data.Data.fileList)
{
using (IRandomAccessStream fileStream = await x.OpenAsync(Windows.Storage.FileAccessMode.Read))
{
BitmapImage bitmapImage = new BitmapImage();
await bitmapImage.SetSourceAsync(fileStream);
int wysokosc1 = Convert.ToInt32(bounds.Height * 0.25);
int szerokosc1 = Convert.ToInt32(bounds.Width * 0.4);
int szerokosc2 = Convert.ToInt32(bounds.Width * 0.55);
lista.Add(new Model.lista_klasa { Nazwa = x.Name, Image = bitmapImage, id = i, wysokosc1 = wysokosc1, szerokosc1 = szerokosc1, szerokosc2 = szerokosc2 });
}
i++;
}
}
示例14: SelectPictureButton_Click
private async void SelectPictureButton_Click(object sender, RoutedEventArgs e)
{
FileOpenPicker openPicker = new FileOpenPicker(); //允许用户打开和选择文件的UI
openPicker.ViewMode = PickerViewMode.Thumbnail;
openPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
openPicker.FileTypeFilter.Add(".jpg");
openPicker.FileTypeFilter.Add(".jpeg");
openPicker.FileTypeFilter.Add(".png");
StorageFile file = await openPicker.PickSingleFileAsync(); //storageFile:提供有关文件及其内容以及操作的方式
if (file != null)
{
path = file.Path;
using (IRandomAccessStream fileStream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read))
{
// Set the image source to the selected bitmap
BitmapImage bitmapImage = new BitmapImage();
bitmapImage.DecodePixelWidth = 600; //match the target Image.Width, not shown
await bitmapImage.SetSourceAsync(fileStream);
img.Source = bitmapImage;
}
}
else
{
var i = new MessageDialog("error with picture").ShowAsync();
}
}
示例15: Page_Loaded
private async void Page_Loaded(object sender, RoutedEventArgs e)
{
ClearErrorMessage();
saveButton.Focus(FocusState.Keyboard);
_savedAppSettings = await ApplicationUtilities.GetAppSettings();
if (_savedAppSettings != null && _savedAppSettings.CompanyImage.Length > 0)
{
Uri uri = new Uri(@"ms-appdata:///local/" + _savedAppSettings.CompanyImage, UriKind.Absolute);
try
{
var file = await StorageFile.GetFileFromApplicationUriAsync(uri);
using (var fileStream = await file.OpenAsync(FileAccessMode.Read))
{
BitmapImage bitmapImage = new BitmapImage
{
DecodePixelHeight = 300,
DecodePixelWidth = 300
};
await bitmapImage.SetSourceAsync(fileStream);
CompanyImage.Source = bitmapImage;
}
}
catch (Exception)
{
}
}
}