本文整理汇总了C#中System.Windows.Media.Imaging.BitmapImage.Freeze方法的典型用法代码示例。如果您正苦于以下问题:C# BitmapImage.Freeze方法的具体用法?C# BitmapImage.Freeze怎么用?C# BitmapImage.Freeze使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Media.Imaging.BitmapImage
的用法示例。
在下文中一共展示了BitmapImage.Freeze方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: getImage
public Image getImage()
{
Image img = new Image();
if (!imageCache.ContainsKey(Item.IconURL))
{
using (var stream = ApplicationState.Model.GetImage(Item))
{
var bitmap = new BitmapImage();
bitmap.BeginInit();
bitmap.StreamSource = stream;
bitmap.CacheOption = BitmapCacheOption.OnLoad;
bitmap.EndInit();
bitmap.Freeze();
imageCache.Add(Item.IconURL, bitmap);
}
}
img.Source = imageCache[Item.IconURL];
var itemhover = new ItemHover() { DataContext = ItemHoverViewModelFactory.Create(Item) };
Popup popup = new Popup();
popup.AllowsTransparency = true;
popup.PopupAnimation = PopupAnimation.Fade;
popup.StaysOpen = true;
popup.Child = itemhover;
popup.PlacementTarget = img;
img.Stretch = Stretch.None;
img.MouseEnter += (o, e) => { popup.IsOpen = true; };
img.MouseLeave += (o, e) => { popup.IsOpen = false; };
return img;
}
示例2: Convert
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) {
if (value == null)
return null;
if (value.ToString().IsEmpty() || (value.ToString() == "none")) {
var image = new BitmapImage();
image.BeginInit();
image.UriSource = new Uri("pack://application:,,,/PCSX2Bonus;component/Images/noart.png", UriKind.Absolute);
image.DecodePixelWidth = 0x109;
image.DecodePixelHeight = 350;
image.EndInit();
if (image.CanFreeze)
image.Freeze();
return image;
}
var image2 = new BitmapImage();
using (var stream = File.OpenRead(value.ToString())) {
image2.BeginInit();
image2.StreamSource = stream;
image2.DecodePixelWidth = 0x109;
image2.DecodePixelHeight = 350;
image2.CacheOption = BitmapCacheOption.OnLoad;
image2.EndInit();
}
if (image2.CanFreeze)
image2.Freeze();
return image2;
}
示例3: SignatureWindow
public SignatureWindow(string signature)
{
var digitalSignatureCollection = new List<object>();
digitalSignatureCollection.Add(new ComboBoxItem() { Content = "" });
digitalSignatureCollection.AddRange(Settings.Instance.Global_DigitalSignatureCollection.Select(n => new DigitalSignatureComboBoxItem(n)).ToArray());
InitializeComponent();
{
var icon = new BitmapImage();
icon.BeginInit();
icon.StreamSource = new FileStream(Path.Combine(App.DirectoryPaths["Icons"], "Amoeba.ico"), FileMode.Open, FileAccess.Read, FileShare.Read);
icon.EndInit();
if (icon.CanFreeze) icon.Freeze();
this.Icon = icon;
}
_signatureComboBox.ItemsSource = digitalSignatureCollection;
for (int index = 0; index < Settings.Instance.Global_DigitalSignatureCollection.Count; index++)
{
if (Settings.Instance.Global_DigitalSignatureCollection[index].ToString() == signature)
{
_signatureComboBox.SelectedIndex = index + 1;
break;
}
}
}
示例4: ComposerToThumbnail
public static BitmapImage ComposerToThumbnail(Composer composer)
{
var thumbnail = (BitmapImage)null;
if (_thumbnailCache.TryGetValue(composer.ComposerId, out thumbnail))
{
return _thumbnailCache[composer.ComposerId];
}
var directoryPath = [email protected]"{Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData, Environment.SpecialFolderOption.Create)}\Music Timeline\Resources\Thumbnails\";
if (!Directory.Exists(directoryPath))
{
Directory.CreateDirectory(directoryPath);
}
var thumbnailPath = [email protected]"{Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData, Environment.SpecialFolderOption.Create)}\Music Timeline\Resources\Thumbnails\{composer.ComposerId}.jpg";
var thumbnailUri = new Uri(thumbnailPath, UriKind.Absolute);
if (File.Exists(thumbnailPath))
{
thumbnail = new BitmapImage();
thumbnail.BeginInit();
thumbnail.DecodePixelHeight = 50;
thumbnail.StreamSource = new MemoryStream(File.ReadAllBytes(thumbnailPath));
thumbnail.EndInit();
thumbnail.Freeze();
_thumbnailCache[composer.ComposerId] = thumbnail;
return thumbnail;
}
return CreateThumbnail(composer);
}
示例5: LoadImage
internal static async Task LoadImage(this Canvas canvas, WindowData data, int imageIndex)
{
var image = await Task.Run(delegate
{
var im = new BitmapImage(new Uri(data.FileList[imageIndex].FileName));
im.Freeze();
return im;
});
data.ScaleX = image.Width / image.PixelWidth;
data.ScaleY = image.Height / image.PixelHeight;
//if (image.PixelWidth != FileAccess.imageWidth || image.PixelHeight != FileAccess.imageHeight) throw new Exception();
var bg = new ImageBrush
{
ImageSource = image
};
data.WindowTitle = Path.GetFileName(data.FileList[imageIndex].FileName) + " (" + bg.ImageSource.Width + "x" + bg.ImageSource.Height + ")";
canvas.Background = bg;
canvas.Width = bg.ImageSource.Width;
canvas.Height = bg.ImageSource.Height;
canvas.Scale(data.Zoom);
Keyboard.Focus(canvas);
}
示例6: load_image
public void load_image(object arg, DoWorkEventArgs e)
{
int contribution_id = (int)e.Argument;
if (!window_manager.downloaded_contributions.Contains(contribution_id))
{
naturenet_dataclassDataContext db = new naturenet_dataclassDataContext();
var result1 = from c in db.Contributions
where c.id == contribution_id
select c;
if (result1.Count() != 0)
{
Contribution contrib = result1.First<Contribution>();
bool result = file_manager.download_file_from_googledirve(contrib.media_url, contribution_id);
if (result) window_manager.downloaded_contributions.Add(contribution_id);
}
}
try
{
ImageSource src = new BitmapImage(new Uri(configurations.GetAbsoluteContributionPath() + contribution_id.ToString() + ".jpg"));
src.Freeze();
the_image = src;
//window_manager.contributions.Add(contribution_id, src);
e.Result = (object)contribution_id;
}
catch (Exception)
{
/// write log
e.Result = -1;
}
}
示例7: GetAlbumArt
public static BitmapImage GetAlbumArt(string path)
{
if(path != null)
{
try
{
TagLib.File tagFile = TagLib.File.Create(path);
if (tagFile.Tag.Pictures.Length != 0)
{
MemoryStream ms = new MemoryStream(tagFile.Tag.Pictures[0].Data.Data);
ms.Seek(0, SeekOrigin.Begin);
// ImageSource for System.Windows.Controls.Image
BitmapImage bitmap = new BitmapImage();
bitmap.BeginInit();
bitmap.StreamSource = ms;
bitmap.EndInit();
bitmap.Freeze();
return bitmap;
}
}
catch(Exception e)
{
}
}
return null;
}
示例8: GetBmpFromBitmap
/// <summary>
/// 将bitmap转换成bitmapImage类型
/// </summary>
/// <param name="bitmap"></param>
/// <returns>绑定给控件显示的类型</returns>
public static BitmapImage GetBmpFromBitmap(Bitmap bitmap)
{
BitmapImage bitImg = new BitmapImage();
using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
{
bitmap.Save(ms, ImageFormat.Bmp);
try
{
bitImg.BeginInit();
bitImg.CacheOption = BitmapCacheOption.OnLoad;
bitImg.StreamSource = ms;
bitImg.EndInit();
bitImg.Freeze();
return bitImg;
}
catch (System.Exception ex)
{
throw new Exception(ex.Message);
}
}
}
示例9: createImage
private Image createImage(Node node, int children)
{
Image img = new Image();
BitmapImage bi = new BitmapImage();
bi.BeginInit();
bi.UriSource = new Uri("res/img/" + node.ImageName + ".png", UriKind.Relative);
bi.EndInit();
bi.Freeze();
img.Source = bi;
if (node.Level == 1)
{
img.Height = 118;
img.Width = 258;
}
else
{
if (children <= 6)
{
img.Height = 200;
img.Width = 209;
}
else
{
img.Height = 150;
img.Width = 153;
}
}
img.Margin = new Thickness(10, 0, 80, 0);
img.Tag = node;
img.MouseLeftButtonDown += gotoNext;
return img;
}
示例10: GetCover
public BitmapImage GetCover(Guid guid, string artist, string album = null)
{
var item = new byte[] { };
try
{
item = Get(guid);
}
catch (DataIdentifierNotFoundException)
{
if (SettingsModel.Instance.CoverDownloadEnabled)
{
item = DownloadImage(guid, artist, album, 5);
}
}
if (item.Length == 0) return _defaultCover;
var source = new BitmapImage();
using (Stream stream = new MemoryStream(item))
{
source.BeginInit();
source.StreamSource = stream;
source.CacheOption = BitmapCacheOption.OnLoad;
source.EndInit();
}
source.Freeze();
return source;
}
示例11: MulticastMessageEditWindow
public MulticastMessageEditWindow(Tag tag, string comment, AmoebaManager amoebaManager)
{
_tag = tag;
_amoebaManager = amoebaManager;
_digitalSignatureCollection.AddRange(Settings.Instance.Global_DigitalSignatures.ToArray());
InitializeComponent();
this.Title = LanguagesManager.Instance.MulticastMessageEditWindow_Title + " - " + MessageConverter.ToTagString(tag);
{
var icon = new BitmapImage();
icon.BeginInit();
icon.StreamSource = new FileStream(Path.Combine(_serviceManager.Paths["Icons"], "Amoeba.ico"), FileMode.Open, FileAccess.Read, FileShare.Read);
icon.EndInit();
if (icon.CanFreeze) icon.Freeze();
this.Icon = icon;
}
_signatureComboBox.ItemsSource = _digitalSignatureCollection;
_signatureComboBox.SelectedIndex = 0;
_commentTextBox.Text = comment;
_watchTimer = new WatchTimer(this.WatchThread, 0, 1000);
this.Closed += (sender, e) => _watchTimer.Dispose();
_textEditor_Helper.Setup(_textEditor);
}
示例12: Convert
public BitmapImage Convert(BitmapSource bitmap)
{
var encoder = new PngBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(bitmap));
var memoryStream = new MemoryStream();
encoder.Save(memoryStream);
var bitmapImage = new BitmapImage();
bitmapImage.CacheOption = BitmapCacheOption.OnLoad;
bitmapImage.CreateOptions = BitmapCreateOptions.None;
try
{
bitmapImage.BeginInit();
bitmapImage.StreamSource = new MemoryStream(memoryStream.ToArray());
}
finally
{
bitmapImage.EndInit();
bitmapImage.Freeze();
memoryStream.Close();
}
return bitmapImage;
}
示例13: GetImage
public static BitmapImage GetImage(string resource, int size = -1, Assembly assembly = null)
{
BitmapImage bitmap;
if (assembly == null)
{
assembly = Assembly.GetExecutingAssembly();
}
using (var stream = assembly.GetManifestResourceStream(resource))
{
if (stream != null)
{
bitmap = new BitmapImage();
bitmap.BeginInit();
bitmap.StreamSource = stream;
bitmap.CacheOption = BitmapCacheOption.OnLoad;
if (size != -1)
{
bitmap.DecodePixelHeight = size;
bitmap.DecodePixelWidth = size;
}
bitmap.EndInit();
bitmap.Freeze();
return bitmap;
}
}
return null;
}
示例14: GetDefaultAlbumArt
/// <summary>
/// Returns a 'default' image for when album art wasn't found in a song
/// </summary>
/// <returns></returns>
private static BitmapImage GetDefaultAlbumArt()
{
var img = new BitmapImage(new Uri("pack://application:,,,/Resources/Images/DefaultAlbumCover.png",
UriKind.RelativeOrAbsolute));
img.Freeze();
return img;
}
示例15: FigureWrapper
public FigureWrapper(byte figure)
{
InitializeComponent();
FigurePlacedOrChosen = false;
Figure = figure;
Ellipse e1 = (Ellipse)this.FindName("Ellipse1");
Ellipse e2 = (Ellipse)this.FindName("Ellipse2");
Ellipse e3 = (Ellipse)this.FindName("Ellipse3");
Ellipse e4 = (Ellipse)this.FindName("Ellipse4");
e1.Fill = new SolidColorBrush(((figure & 1) == 0) ? Color.FromArgb(255, 0x44, 0x44, 0x44) : Color.FromArgb(255, 255, 255, 255));
e2.Fill = new SolidColorBrush(((figure & 2) == 0) ? Color.FromArgb(255, 0x44, 0x44, 0x44) : Color.FromArgb(255, 255, 255, 255));
e3.Fill = new SolidColorBrush(((figure & 4) == 0) ? Color.FromArgb(255, 0x44, 0x44, 0x44) : Color.FromArgb(255, 255, 255, 255));
e4.Fill = new SolidColorBrush(((figure & 8) == 0) ? Color.FromArgb(255, 0x44, 0x44, 0x44) : Color.FromArgb(255, 255, 255, 255));
using (Stream _stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("Quarto.Images.figure" + figure + ".png"))
{
BitmapImage bi = new BitmapImage();
bi.BeginInit();
bi.StreamSource = _stream;
bi.CacheOption = BitmapCacheOption.OnLoad;
bi.EndInit();
bi.Freeze();
this.Background = new ImageBrush
{
ImageSource = bi
};
}
SwitchToPieceView();
}