本文整理汇总了C#中System.Windows.Media.Imaging.BitmapImage.BeginInit方法的典型用法代码示例。如果您正苦于以下问题:C# BitmapImage.BeginInit方法的具体用法?C# BitmapImage.BeginInit怎么用?C# BitmapImage.BeginInit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Media.Imaging.BitmapImage
的用法示例。
在下文中一共展示了BitmapImage.BeginInit方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Create
public Model3DGroup Create(Color modelColor,string pictureName, Point3D startPos, double maxHigh)
{
try
{
Uri inpuri = new Uri(@pictureName, UriKind.Relative);
BitmapImage bi = new BitmapImage();
bi.BeginInit();
bi.UriSource = inpuri;
bi.EndInit();
ImageBrush imagebrush = new ImageBrush(bi);
imagebrush.Opacity = 100;
imagebrush.Freeze();
Point[] ptexture0 = { new Point(0, 0), new Point(0, 1), new Point(1, 0) };
Point[] ptexture1 = { new Point(1, 0), new Point(0, 1), new Point(1, 1) };
SolidColorBrush modelbrush = new SolidColorBrush(modelColor);
Model3DGroup cube = new Model3DGroup();
Point3D uppercircle = startPos;
modelbrush.Freeze();
uppercircle.Y = startPos.Y + maxHigh;
cube.Children.Add(CreateEllipse2D(modelbrush, uppercircle, _EllipseHigh, new Vector3D(0, 1, 0)));
cube.Children.Add(CreateEllipse2D(modelbrush, startPos, _EllipseHigh, new Vector3D(0, -1, 0)));
cube.Children.Add(CreateEllipse3D(imagebrush, startPos, _EllipseHigh, maxHigh, ptexture0));
return cube;
}
catch (Exception ex)
{
throw ex;
}
}
示例2: DeviceView
//-------------------------------------------------------------------------------------
/// <summary>
/// Constructor
/// </summary>
/// <param name="device">ref NodeController</param>
/// <param name="deviceType">type of device</param>
public DeviceView(DeviceController device, DeviceType deviceType)
{
InitializeComponent();
this.deviceController = device;
BitmapImage bi3 = new BitmapImage();
if (deviceType == DeviceType.dPc)
{
bi3.BeginInit();
bi3.UriSource = new Uri("/GEditor;component/Resources/screen_zoom_in_ch.png", UriKind.Relative);
bi3.EndInit();
}
else
{
if (deviceType == DeviceType.dSwitch)
{
bi3.BeginInit();
bi3.UriSource = new Uri("/GEditor;component/Resources/switch_ch.png", UriKind.Relative);
bi3.EndInit();
}
else
{
bi3.BeginInit();
bi3.UriSource = new Uri("/GEditor;component/Resources/password_ch.png", UriKind.Relative);
bi3.EndInit();
}
}
this.point.Source = bi3;
Canvas.SetZIndex(this, 2);
this.point.Width = this.point.Height = radiusView;
}
示例3: GetHeadIcon
public BitmapImage GetHeadIcon(string dir)
{
BitmapImage headBit = new BitmapImage();
if (File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "/" + dir + "/" + "logindata"))
{
headBit.BeginInit();
string line1;
string line2;
string line3;
using (StreamReader reader = new StreamReader(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "/" + dir + "/" + "logindata"))
{
line1 = reader.ReadLine();
line2 = reader.ReadLine();
line3 = reader.ReadLine();
}
headBit.UriSource = new Uri("https://minotar.net/avatar/" + line3);
headBit.EndInit();
return headBit;
}
else
{
headBit.BeginInit();
headBit.UriSource = new Uri("https://minotar.net/avatar/char");
headBit.EndInit();
return headBit;
}
}
示例4: Convert
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
var imageParameter = value as string;
if (imageParameter == null)
imageParameter = parameter as string;
if (!string.IsNullOrEmpty(imageParameter as string))
{
System.Drawing.Bitmap bitmap = null;
var bitmapImage = new BitmapImage();
// Application Resource - File Build Action is marked as None, but stored in Resources.resx
// parameter= myresourceimagename
try
{
bitmap = Properties.Resources.ResourceManager.GetObject(imageParameter) as System.Drawing.Bitmap;
}
catch { }
if (bitmap != null)
{
using (var ms = new MemoryStream())
{
bitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
bitmapImage.BeginInit();
bitmapImage.StreamSource = ms;
bitmapImage.CacheOption = BitmapCacheOption.OnLoad;
bitmapImage.EndInit();
}
return bitmapImage;
}
// Embedded Resource - File Build Action is marked as Embedded Resource
// parameter= MyWpfApplication.EmbeddedResource.myotherimage.png
var asm = Assembly.GetExecutingAssembly();
var stream = asm.GetManifestResourceStream(imageParameter);
if (stream != null)
{
bitmapImage.BeginInit();
bitmapImage.StreamSource = stream;
bitmapImage.EndInit();
return bitmapImage;
}
// This is the standard way of using Image.SourceDependancyProperty. You shouldn't need to use a converter to to this.
//// Resource - File Build Action is marked as Resource
//// parameter= pack://application:,,,/MyWpfApplication;component/Images/myfunkyimage.png
//Uri imageUriSource = null;
//if (Uri.TryCreate(imageParameter, UriKind.RelativeOrAbsolute, out imageUriSource))
//{
// bitmapImage.BeginInit();
// bitmapImage.UriSource = imageUriSource;
// bitmapImage.EndInit();
// return bitmapImage;
//}
}
return null;
}
示例5: DownloadPicture
public async Task<ImageSource> DownloadPicture(string imageUri)
{
var request = (HttpWebRequest)WebRequest.Create(imageUri);
if (string.IsNullOrEmpty(Configuration.SessionCookies) == false)
{
request.CookieContainer = new CookieContainer();
request.CookieContainer.SetCookies(request.RequestUri, Configuration.SessionCookies);
}
var response = (HttpWebResponse)(await request.GetResponseAsync());
using (Stream inputStream = response.GetResponseStream())
using (Stream outputStream = new MemoryStream())
{
var buffer = new byte[4096];
int bytesRead;
do
{
bytesRead = await inputStream.ReadAsync(buffer, 0, buffer.Length);
outputStream.Write(buffer, 0, bytesRead);
} while (bytesRead != 0);
var bitmapImage = new BitmapImage();
bitmapImage.BeginInit();
bitmapImage.CacheOption = BitmapCacheOption.OnLoad;
bitmapImage.StreamSource = outputStream;
bitmapImage.EndInit();
bitmapImage.Freeze();
return bitmapImage;
}
}
示例6: ShowImage
//TODO filter by mimetype
public void ShowImage(MemoryStream stream)
{
try
{
stream.Position = 0;
var bitmapImage = new BitmapImage();
bitmapImage.BeginInit();
bitmapImage.StreamSource = stream;
bitmapImage.EndInit();
image1.Width = bitmapImage.Width;
image1.Height = bitmapImage.Height;
var screenInfo = GetScreenInfo();
image1.Height = screenInfo.Height - 150;
image1.Width = (image1.Height * bitmapImage.Width) / bitmapImage.Height;
Height = image1.Height + 3;
Width = image1.Width + 3;
image1.Source = bitmapImage;
}
catch (NotSupportedException)
{ }
}
示例7: ExtTreeNode
public ExtTreeNode(Image icon, string title)
: this()
{
if (icon != null)
{
this.icon = icon;
}
else//test inti icon
{
this.icon = new Image();
BitmapImage bitmapImage = new BitmapImage();
bitmapImage.BeginInit();
bitmapImage.UriSource = new Uri(@"pack://application:,,,/ATNET;component/icons/add.png", UriKind.RelativeOrAbsolute);
//bitmapImage.UriSource = new Uri(@"../../icons/add.png", UriKind.RelativeOrAbsolute);
bitmapImage.EndInit();
this.icon.Source = bitmapImage;
}
this.icon.Width = 16;
this.icon.Height = 16;
this.title = title;
TextBlock tb = new TextBlock();
tb.Text = title;
Grid grid = new Grid();
grid.ColumnDefinitions.Add(new ColumnDefinition());
grid.ColumnDefinitions.Add(new ColumnDefinition());
grid.Children.Add(this.icon);
grid.Children.Add(tb);
Grid.SetColumn(this.icon, 0);
Grid.SetColumn(tb, 1);
this.Header = grid;
}
示例8: updateImage
private void updateImage()
{
try
{
SnapshotImg.Source = null;
ImageExportOptions options = new ImageExportOptions();
options.FilePath = snapshot;
// options.
options.HLRandWFViewsFileType = ImageFileType.PNG;
options.ShadowViewsFileType = ImageFileType.PNG;
options.ExportRange = ExportRange.VisibleRegionOfCurrentView;
options.ZoomType = ZoomFitType.FitToPage;
options.ImageResolution = ImageResolution.DPI_72;
options.PixelSize = 1000;
doc.ExportImage(options);
BitmapImage source = new BitmapImage();
source.BeginInit();
source.UriSource = new Uri(snapshot);
source.CacheOption = BitmapCacheOption.OnLoad;
source.CreateOptions = BitmapCreateOptions.IgnoreImageCache;
source.EndInit();
SnapshotImg.Source = source;
PathLabel.Content = "none";
}
catch (System.Exception ex1)
{
TaskDialog.Show("Error!", "exception: " + ex1);
}
}
示例9: init
/// <summary>
/// 初始化
/// </summary>
public void init(string[] func_list)
{
for (int i = 0; i < func_list.Length; i++)
{
// 分割线
Image img = new Image();
BitmapImage bi = new BitmapImage();
bi.BeginInit();
bi.UriSource = new Uri(AppConfig.IconPath, UriKind.Relative);
bi.EndInit();
img.Margin = new Thickness(5, (i + 1) * 72 - 20, 0, 0);
img.Width = 150;
img.Height = 10;
img.HorizontalAlignment = HorizontalAlignment.Left;
img.VerticalAlignment = VerticalAlignment.Top;
img.Source = bi;
// 按钮
MainNavButton mnb = new MainNavButton();
mnb.Tag = func_list[i];
mnb.id = i;
mnb.init();
mnb.HorizontalAlignment = HorizontalAlignment.Left;
mnb.VerticalAlignment = VerticalAlignment.Top;
mnb.Margin = new Thickness(0, (i + 1) * 72 - 20 + 3, 0, 0);
if (i == 0)
{
mnb.change_state();
}
mnbs.Add(mnb);
this.main.Children.Add(img);
this.main.Children.Add(mnb);
}
}
示例10: Convert
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var bytes = value as byte[];
if (bytes == null || bytes.Length == 0)
return DependencyProperty.UnsetValue;
var image = new BitmapImage();
using (Stream stream = new MemoryStream(bytes))
{
image.BeginInit();
image.StreamSource = stream;
image.CacheOption = BitmapCacheOption.OnLoad;
image.EndInit();
}
if (!image.IsFrozen)
{
image.AddMemoryPressure();
image.Freeze();
}
return image;
}
示例11: FileListItem
public FileListItem(string captionText, string imagePath)
: base()
{
Margin = new Thickness(13);
var panel = new StackPanel();
var imageSource = new BitmapImage();
var image = new Image();
var caption = new TextBlock();
imageSource.BeginInit();
imageSource.UriSource = new Uri(imagePath, UriKind.Relative);
imageSource.EndInit();
image.VerticalAlignment = System.Windows.VerticalAlignment.Center;
image.Source = imageSource;
image.Height = 64;
image.Width = 64;
image.ToolTip = "Select & click on 'Table' for data view.";
caption.TextAlignment = TextAlignment.Center;
caption.TextWrapping = TextWrapping.Wrap;
caption.Text = captionText;
Caption = captionText;
if (caption.Text.Length <= 18)
caption.Text += "\n ";
panel.Children.Add(image);
panel.Children.Add(caption);
Child = panel;
}
示例12: MainWindow
public MainWindow()
{
InitializeComponent();
Window w = new DBItems();
VkRepository.ImageReady += () =>
{
UserAvatar.Children.Clear();
Image i = new Image();
BitmapImage src = new BitmapImage();
src.BeginInit();
src.UriSource = new Uri(string.Format("{0}avatar.jpg", VkRepository.counter.ToString()), UriKind.Relative);
src.CacheOption = BitmapCacheOption.OnLoad;
src.EndInit();
i.Source = src;
i.Stretch = Stretch.Uniform;
UserAvatar.Children.Add(i);
};
AuthWindow.OnLoggedIn += (c) =>
{
AuthInfo.Text = VkRepository.GetUserInfo(c).ToString();
};
VkRepository.UserDbLoaded += (users) =>
{
w.Show();
};
}
示例13: 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);
}
示例14: CreateImageSource2
static ImageSource CreateImageSource2(byte[] data) {
var bimg = new BitmapImage();
bimg.BeginInit();
bimg.StreamSource = new MemoryStream(data);
bimg.EndInit();
return bimg;
}
示例15: BitmapImageFromBytes
private BitmapImage BitmapImageFromBytes(byte[] bytes)
{
BitmapImage image = null;
MemoryStream stream = null;
try
{
stream = new MemoryStream(bytes);
stream.Seek(0, SeekOrigin.Begin);
System.Drawing.Image img = System.Drawing.Image.FromStream(stream);
image = new BitmapImage();
image.BeginInit();
MemoryStream ms = new MemoryStream();
img.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);
ms.Seek(0, SeekOrigin.Begin);
image.StreamSource = ms;
image.StreamSource.Seek(0, SeekOrigin.Begin);
image.EndInit();
}
catch (Exception)
{
throw;
}
finally
{
stream.Close();
stream.Dispose();
}
return image;
}