本文整理汇总了C#中Windows.UI.Xaml.Media.Imaging.BitmapImage类的典型用法代码示例。如果您正苦于以下问题:C# BitmapImage类的具体用法?C# BitmapImage怎么用?C# BitmapImage使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
BitmapImage类属于Windows.UI.Xaml.Media.Imaging命名空间,在下文中一共展示了BitmapImage类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnCapturePhotoButtonClick
private async void OnCapturePhotoButtonClick(object sender, RoutedEventArgs e)
{
var file = await TestedControl.CapturePhotoToStorageFileAsync(ApplicationData.Current.TemporaryFolder);
var bi = new BitmapImage();
IRandomAccessStreamWithContentType stream;
try
{
stream = await TryCatchRetry.RunWithDelayAsync<Exception, IRandomAccessStreamWithContentType>(
file.OpenReadAsync(),
TimeSpan.FromSeconds(0.5),
10,
true);
}
catch (Exception ex)
{
// Seems like a bug with WinRT not closing the file sometimes that writes the photo to.
#pragma warning disable 4014
new MessageDialog(ex.Message, "Error").ShowAsync();
#pragma warning restore 4014
return;
}
bi.SetSource(stream);
PhotoImage.Source = bi;
CapturedVideoElement.Visibility = Visibility.Collapsed;
PhotoImage.Visibility = Visibility.Visible;
}
示例2: ButtonCamera_Click
private async void ButtonCamera_Click(object sender, RoutedEventArgs e)
{
CameraCaptureUI captureUI = new CameraCaptureUI();
captureUI.PhotoSettings.Format = CameraCaptureUIPhotoFormat.Jpeg;
captureUI.PhotoSettings.CroppedSizeInPixels = new Size(600, 600);
StorageFile photo = await captureUI.CaptureFileAsync(CameraCaptureUIMode.Photo);
if (photo != null)
{
BitmapImage bmp = new BitmapImage();
IRandomAccessStream stream = await photo.
OpenAsync(FileAccessMode.Read);
bmp.SetSource(stream);
BBQImage.Source = bmp;
FileSavePicker savePicker = new FileSavePicker();
savePicker.FileTypeChoices.Add
("jpeg image", new List<string>() { ".jpeg" });
savePicker.SuggestedFileName = "New picture";
StorageFile savedFile = await savePicker.PickSaveFileAsync();
(this.DataContext as BBQRecipeViewModel).imageSource = savedFile.Path;
if (savedFile != null)
{
await photo.MoveAndReplaceAsync(savedFile);
}
}
}
示例3: 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;
}
}
}
示例4: EditCurrentImage
public EditCurrentImage(Image source, int sentId, BitmapImage sentSrc)
{
img = source;
currentAngle = 0;
id = sentId;
bmp = sentSrc;
}
示例5: ImageFromRelativePath
public static BitmapImage ImageFromRelativePath(FrameworkElement parent, string path)
{
var uri = new Uri(parent.BaseUri, path);
BitmapImage result = new BitmapImage();
result.UriSource = uri;
return result;
}
示例6: Activate
/// <summary>
/// Invoked when another application wants to share content through this application.
/// </summary>
/// <param name="args">Activation data used to coordinate the process with Windows.</param>
public async void Activate(ShareTargetActivatedEventArgs args)
{
this._shareOperation = args.ShareOperation;
// Communicate metadata about the shared content through the view model
var shareProperties = this._shareOperation.Data.Properties;
var thumbnailImage = new BitmapImage();
this.DefaultViewModel["Title"] = shareProperties.Title;
this.DefaultViewModel["Description"] = shareProperties.Description;
this.DefaultViewModel["Image"] = thumbnailImage;
this.DefaultViewModel["Sharing"] = false;
this.DefaultViewModel["ShowImage"] = false;
this.DefaultViewModel["Comment"] = String.Empty;
this.DefaultViewModel["SupportsComment"] = true;
Window.Current.Content = this;
Window.Current.Activate();
Detector dt = new Detector(_shareOperation.Data);
dt.Detect();
this.DataContext = dt.Detected;
// Update the shared content's thumbnail image in the background
if (shareProperties.Thumbnail != null)
{
var stream = await shareProperties.Thumbnail.OpenReadAsync();
thumbnailImage.SetSource(stream);
this.DefaultViewModel["ShowImage"] = true;
}
}
示例7: PerformFaceAnalysis
private async void PerformFaceAnalysis(StorageFile file)
{
var imageInfo = await FileHelper.GetImageInfoForRendering(file.Path);
NewImageSizeWidth = 300;
NewImageSizeHeight = NewImageSizeWidth*imageInfo.Item2/imageInfo.Item1;
var newSourceFile = await FileHelper.CreateCopyOfSelectedImage(file);
var uriSource = new Uri(newSourceFile.Path);
SelectedFileBitmapImage = new BitmapImage(uriSource);
// start face api detection
var faceApi = new FaceApiHelper();
DetectedFaces = await faceApi.StartFaceDetection(newSourceFile.Path, newSourceFile, imageInfo, "4c138b4d82b947beb2e2926c92d1e514");
// draw rectangles
var color = Color.FromArgb(125, 255, 0, 0);
var bg = new SolidColorBrush(color);
DetectedFacesCanvas = new ObservableCollection<Canvas>();
foreach (var detectedFace in DetectedFaces)
{
var margin = new Thickness(detectedFace.RectLeft, detectedFace.RectTop, 0, 0);
var canvas = new Canvas()
{
Background = bg,
HorizontalAlignment = HorizontalAlignment.Left,
VerticalAlignment = VerticalAlignment.Top,
Height = detectedFace.RectHeight,
Width = detectedFace.RectWidth,
Margin = margin
};
DetectedFacesCanvas.Add(canvas);
}
}
示例8: TileToImage
public static async Task<BitmapImage> TileToImage(byte[] tile)
{
var image = await ByteArrayToRandomAccessStream(tile);
var bitmapImage = new BitmapImage();
bitmapImage.SetSource(image);
return bitmapImage;
}
示例9: 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;
}
示例10: GetPhotoInDevice
public static async Task<List<LocationData>> GetPhotoInDevice()
{
List<LocationData> mapPhotoIcons = new List<LocationData>();
IReadOnlyList<StorageFile> photos = await KnownFolders.CameraRoll.GetFilesAsync();
for (int i = 0; i < photos.Count; i++)
{
Geopoint geopoint = await GeotagHelper.GetGeotagAsync(photos[i]);
if (geopoint != null)
{
//should use Thumbnail to reduce the size of images, otherwise low-end device will crashes
var fileStream = await photos[i].GetThumbnailAsync(ThumbnailMode.PicturesView);
var img = new BitmapImage();
img.SetSource(fileStream);
mapPhotoIcons.Add(new LocationData
{
Position = geopoint.Position,
DateCreated = photos[i].DateCreated,
ImageSource = img
});
}
}
var retMapPhotos = mapPhotoIcons.OrderBy(x => x.DateCreated).ToList();
return retMapPhotos;
}
示例11: GetUserThumbnailPhotoAsync
/// <summary>
/// Get the user's photo.
/// </summary>
/// <param name="user">The target user.</param>
/// <returns></returns>
public async Task<BitmapImage> GetUserThumbnailPhotoAsync(IUser user)
{
BitmapImage bitmap = null;
try
{
// The using statement ensures that Dispose is called even if an
// exception occurs while you are calling methods on the object.
using (var dssr = await user.ThumbnailPhoto.DownloadAsync())
using (var stream = dssr.Stream)
using (var memStream = new MemoryStream())
{
await stream.CopyToAsync(memStream);
memStream.Seek(0, SeekOrigin.Begin);
bitmap = new BitmapImage();
await bitmap.SetSourceAsync(memStream.AsRandomAccessStream());
}
}
catch(ODataException)
{
// Something went wrong retrieving the thumbnail photo, so set the bitmap to a default image
bitmap = new BitmapImage(new Uri("ms-appx:///assets/UserDefaultSignedIn.png", UriKind.RelativeOrAbsolute));
}
return bitmap;
}
开发者ID:delacruzjayveejoshua920,项目名称:ICNG-App-for-Windows-8.1-and-Windows-Phone-8.1-,代码行数:31,代码来源:UserOperations.cs
示例12: BackgroundButton_Click
private async void BackgroundButton_Click(object sender, RoutedEventArgs e)
{
// Clear previous returned file name, if it exists, between iterations of this scenario
OutputTextBlock.Text = "";
FileOpenPicker openPicker = new FileOpenPicker();
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();
if (file != null)
{
// Application now has read/write access to the picked file
OutputTextBlock.Text = "Picked photo: " + file.Name;
BitmapImage img = new BitmapImage();
img = await ImageHelpers.LoadImage( file );
MyPicture.Source = img;
}
else
{
OutputTextBlock.Text = "Operation cancelled.";
}
}
示例13: GetImage
public static BitmapImage GetImage(string path, bool negateResult = false)
{
if (string.IsNullOrEmpty(path))
{
return null;
}
var isDarkTheme = Application.Current.RequestedTheme == ApplicationTheme.Dark;
if (negateResult)
{
isDarkTheme = !isDarkTheme;
}
BitmapImage result;
path = "ms-appx:" + string.Format(path, isDarkTheme ? "dark" : "light");
// Check if we already cached the image
if (!ImageCache.TryGetValue(path, out result))
{
result = new BitmapImage(new Uri(path, UriKind.Absolute));
ImageCache.Add(path, result);
}
return result;
}
示例14: Activate
/// <summary>
/// 他のアプリケーションがこのアプリケーションを介してコンテンツの共有を求めた場合に呼び出されます。
/// </summary>
/// <param name="args">Windows と連携して処理するために使用されるアクティベーション データ。</param>
public async void Activate(ShareTargetActivatedEventArgs args)
{
this.currentModel = BookmarkerModel.GetDefault();
await this.currentModel.LoadAsync();
this._shareOperation = args.ShareOperation;
// ビュー モデルを使用して、共有されるコンテンツのメタデータを通信します
var shareProperties = this._shareOperation.Data.Properties;
var thumbnailImage = new BitmapImage();
this.DefaultViewModel["Title"] = shareProperties.Title;
this.DefaultViewModel["Description"] = shareProperties.Description;
this.DefaultViewModel["Image"] = thumbnailImage;
this.DefaultViewModel["Sharing"] = false;
this.DefaultViewModel["ShowImage"] = false;
this.DefaultViewModel["Comment"] = String.Empty;
this.DefaultViewModel["SupportsComment"] = true;
this.addBookmarkView.Title = shareProperties.Title;
this.addBookmarkView.Uri = (await this._shareOperation.Data.GetUriAsync()).ToString();
Window.Current.Content = this;
Window.Current.Activate();
// 共有されるコンテンツの縮小版イメージをバックグラウンドで更新します
if (shareProperties.Thumbnail != null)
{
var stream = await shareProperties.Thumbnail.OpenReadAsync();
thumbnailImage.SetSource(stream);
this.DefaultViewModel["ShowImage"] = true;
}
}
示例15: BannerControl
public BannerControl(GridView bannerCanv, XCollection<Banner> banners, Frame frame)
{
_frame = frame;
bannerCanv.Items?.Clear();
var deviceWidth = Window.Current.CoreWindow.Bounds.Width;
foreach (var banner in banners)
{
var bannerBitmap = new BitmapImage {UriSource = new Uri(banner.Image, UriKind.RelativeOrAbsolute)};
var bannerImage = SystemInfoHelper.IsMobile() || deviceWidth < 800 ? new Image
{
Source = bannerBitmap,
Stretch = Stretch.Fill,
MaxWidth = deviceWidth + 5
} : new Image
{
Source = bannerBitmap,
Stretch = Stretch.Fill,
MaxHeight = bannerCanv.MaxHeight
};
bannerImage.Tapped += OnBannerTap;
bannerImage.Tag = banner;
bannerCanv.Visibility = Visibility.Visible;
bannerImage.Visibility = Visibility.Visible;
bannerCanv.Items?.Add(bannerImage);
}
if (SystemInfoHelper.IsMobile() || deviceWidth < 800)
bannerCanv.MaxHeight = deviceWidth / 2.46;
}