本文整理汇总了C#中Image.BeginInit方法的典型用法代码示例。如果您正苦于以下问题:C# Image.BeginInit方法的具体用法?C# Image.BeginInit怎么用?C# Image.BeginInit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Image
的用法示例。
在下文中一共展示了Image.BeginInit方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnSelectedItemChanged
private void OnSelectedItemChanged(IImgObject selectedObj)
{
var img = selectedObj as ImgImage;
if (img != null)
{
var imgCtrl = new Image();
imgCtrl.BeginInit();
{
imgCtrl.Source = img.GetImageSource();
imgCtrl.HorizontalAlignment = HorizontalAlignment.Left;
imgCtrl.VerticalAlignment = VerticalAlignment.Top;
}
imgCtrl.EndInit();
ImgCanvas.Children.Clear();
ImgCanvas.Children.Add(imgCtrl);
ImgCanvas.Width = img.Width;
this.orgImgWidth = img.Width;
ImgCanvas.Height = img.Height;
this.orgImgHeight = img.Height;
(this.DataContext as ImageDetailViewModel).TargetImage = img;
}
}
示例2: addt
public void addt(String url)
{
Image image = new Image();
image.BeginInit();
image.Source = new BitmapImage(new Uri(url));
image.EndInit();
image.Width = 100;
image.Height = 100;
image.Stretch = Stretch.Uniform;
image.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
image.VerticalAlignment = System.Windows.VerticalAlignment.Top;
myg.Children.Add(image);
}
示例3: Convert
/// <summary>
/// Converts an <see cref="ImageSource"/> into an <see cref="Image"/>.
/// </summary>
/// <param name="value">The value produced by the binding source.</param>
/// <param name="targetType">The type of the binding target property.</param>
/// <param name="parameter">The converter parameter to use.</param>
/// <param name="culture">The culture to use in the converter.</param>
/// <returns>
/// A converted value. If the method returns null, the valid null value is used.
/// </returns>
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var inputImage = value as ImageSource;
if (inputImage != null)
{
var image = new Image();
image.BeginInit();
image.Source = inputImage;
image.EndInit();
return image;
}
return DependencyProperty.UnsetValue;
}
示例4: GetInfoObject
public UIElement GetInfoObject(double width)
{
if(string.IsNullOrEmpty(Path))
{
throw new ArgumentNullException("Path cannot be null");
}
var img = new Image();
img.BeginInit();
img.Source = new BitmapImage(new Uri("/CozyLauncher.Plugin.Guide;component/" + Path, UriKind.RelativeOrAbsolute));
img.Stretch = Stretch.Fill;
img.EndInit();
img.MaxWidth = width;
return img;
}
示例5: AddButton
public void AddButton(ImageSource imgSrc)
{
Image img = new Image();
img.BeginInit();
img.Width = BUTTON_SIZE;
img.Height = BUTTON_SIZE;
img.Source = imgSrc;
img.EndInit();
buttons.Add(img);
wheelCanvas.Children.Add(img);
if (IsInitialized)
{
refreshButtons();
}
}
示例6: initializeButtonImages
private void initializeButtonImages()
{
leftButton = new Image();
leftButton.BeginInit();
BitmapImage bmp = new BitmapImage(new Uri(@"C:\Users\Kartikeya\Documents\Visual Studio 2010\Projects\Share\Share\left.png", UriKind.Absolute));
bmp.CacheOption = BitmapCacheOption.OnLoad;
leftButton.Source = bmp;
leftButton.EndInit();
leftButton.Height = 100;
leftButton.Width = 100;
galleryButton = new Image();
galleryButton.BeginInit();
bmp = new BitmapImage(new Uri(@"C:\Users\Kartikeya\Documents\Visual Studio 2010\Projects\Share\Share\gallery.jpg", UriKind.Absolute));
bmp.CacheOption = BitmapCacheOption.OnLoad;
galleryButton.Source = bmp;
galleryButton.EndInit();
galleryButton.Height = 100;
galleryButton.Width = 100;
rightButton = new Image();
rightButton.BeginInit();
bmp = new BitmapImage(new Uri(@"C:\Users\Kartikeya\Documents\Visual Studio 2010\Projects\Share\Share\right.png", UriKind.Absolute));
bmp.CacheOption = BitmapCacheOption.OnLoad;
rightButton.Source = bmp;
rightButton.EndInit();
rightButton.Height = 100;
rightButton.Width = 100;
trashButton = new Image();
trashButton.BeginInit();
bmp = new BitmapImage(new Uri(@"C:\Users\Kartikeya\Documents\Visual Studio 2010\Projects\Share\Share\trash.png", UriKind.Absolute));
bmp.CacheOption = BitmapCacheOption.OnLoad;
trashButton.Source = bmp;
trashButton.EndInit();
trashButton.Height = 100;
trashButton.Width = 100;
}
示例7: SetImage
//change l'image d'un bouton pour le chemin spécifié
private void SetImage(string path, Button b)
{
Image i = new Image();
i.BeginInit();
i.Source = new BitmapImage(new Uri(path, UriKind.RelativeOrAbsolute));
i.EndInit();
b.Content = i;
}
示例8: ExecuteThread
public string ExecuteThread(FileItem item,string infile, string dest, ValuePairEnumerator configData)
{
try
{
var conf = new OverlayTransformViewModel(configData);
using (var fileStream = new MemoryStream(File.ReadAllBytes(infile)))
{
BitmapDecoder bmpDec = BitmapDecoder.Create(fileStream,
BitmapCreateOptions.PreservePixelFormat,
BitmapCacheOption.OnLoad);
WriteableBitmap writeableBitmap = BitmapFactory.ConvertToPbgra32Format(bmpDec.Frames[0]);
writeableBitmap.Freeze();
Grid grid = new Grid
{
Width = writeableBitmap.PixelWidth,
Height = writeableBitmap.PixelHeight,
ClipToBounds = true,
SnapsToDevicePixels = true
};
grid.UpdateLayout();
var size = new Size(writeableBitmap.PixelWidth, writeableBitmap.PixelWidth);
grid.Measure(size);
grid.Arrange(new Rect(size));
Image overlay = new Image();
Image image = new Image { Width = writeableBitmap.PixelWidth, Height = writeableBitmap.PixelHeight };
image.BeginInit();
image.Source = writeableBitmap;
image.EndInit();
image.Stretch = Stretch.Fill;
grid.Children.Add(image);
grid.UpdateLayout();
string text = "";
if (!string.IsNullOrEmpty(conf.Text))
{
Regex regPattern = new Regex(@"\[(.*?)\]", RegexOptions.Singleline);
MatchCollection matchX = regPattern.Matches(conf.Text);
text = matchX.Cast<Match>()
.Aggregate(conf.Text,
(current1, match) =>
item.FileNameTemplates.Where(
template =>
String.Compare(template.Name, match.Value,
StringComparison.InvariantCultureIgnoreCase) == 0).Aggregate(current1,
(current, template) => current.Replace(match.Value, template.Value)));
}
TextBlock textBlock = new TextBlock
{
Text = text,
Foreground = (SolidColorBrush) new BrushConverter().ConvertFromString(conf.FontColor),
FontFamily = (FontFamily) new FontFamilyConverter().ConvertFromString(conf.Font),
FontSize = conf.FontSize,
Opacity = conf.Transparency/100.00
};
if (conf.A11)
{
textBlock.HorizontalAlignment = HorizontalAlignment.Left;
textBlock.VerticalAlignment = VerticalAlignment.Top;
}
if (conf.A12)
{
textBlock.HorizontalAlignment = HorizontalAlignment.Center;
textBlock.VerticalAlignment = VerticalAlignment.Top;
}
if (conf.A13)
{
textBlock.HorizontalAlignment = HorizontalAlignment.Right;
textBlock.VerticalAlignment = VerticalAlignment.Top;
}
if (conf.A21)
{
textBlock.HorizontalAlignment = HorizontalAlignment.Left;
textBlock.VerticalAlignment = VerticalAlignment.Center;
}
if (conf.A22)
{
textBlock.HorizontalAlignment = HorizontalAlignment.Center;
textBlock.VerticalAlignment = VerticalAlignment.Center;
}
if (conf.A23)
{
textBlock.HorizontalAlignment = HorizontalAlignment.Right;
textBlock.VerticalAlignment = VerticalAlignment.Center;
}
if (conf.A31)
{
textBlock.HorizontalAlignment = HorizontalAlignment.Left;
textBlock.VerticalAlignment = VerticalAlignment.Bottom;
}
if (conf.A32)
{
textBlock.HorizontalAlignment = HorizontalAlignment.Center;
textBlock.VerticalAlignment = VerticalAlignment.Bottom;
}
if (conf.A33)
{
textBlock.HorizontalAlignment = HorizontalAlignment.Right;
//.........这里部分代码省略.........
示例9: TileToImage
private static Image TileToImage(byte[] tile)
{
var stream = new MemoryStream(tile);
var bitmapImage = new BitmapImage();
bitmapImage.BeginInit();
bitmapImage.StreamSource = stream;
bitmapImage.EndInit();
var image = new Image();
image.BeginInit();
image.Source = bitmapImage;
image.EndInit();
return image;
}
示例10: btnAfficherTrombi_Click
private void btnAfficherTrombi_Click(object sender, RoutedEventArgs e)
{
if (cbFiltre.SelectedItem != null || rbModule.IsChecked.Value == true){
CtrlTrombinoscope ctrlTrombi = new CtrlTrombinoscope();
List<Stagiaire> listStagiaire = ctrlTrombi.listeStagiaires(filtre);
if (listStagiaire.Count == 0)
{
Label lab = new Label();
lab.Foreground = new SolidColorBrush(Colors.Red);
lab.FontWeight = FontWeights.Bold;
lab.Content = "Pas de stagiaires disponibles.";
Grid g = new Grid();
g.Children.Add(lab);
groupBox2.Visibility = Visibility.Hidden;
groupBox3.Visibility = Visibility.Hidden;
groupBox4.Visibility = Visibility.Visible;
groupBox4.Content = g;
}
else {
groupBox2.Visibility = Visibility.Visible;
groupBox4.Visibility = Visibility.Hidden;
groupBox3.Visibility = Visibility.Visible;
Grid tableauImages = new Grid();
int i = 0;
int j = 0;
int photo = 1;
RowDefinition testRow, testRowNomStagiaire;
if (gridTrombi.RowDefinitions.Count > 0)
{
gridTrombi.RowDefinitions.RemoveRange(0, gridTrombi.RowDefinitions.Count);
}
if (gridTrombi.ColumnDefinitions.Count > 0)
{
gridTrombi.ColumnDefinitions.RemoveRange(0, gridTrombi.ColumnDefinitions.Count);
}
foreach (Stagiaire s in listStagiaire)
{
if (i - 4 == 0)
{
i = 0;
j += 2;
}
ColumnDefinition testColumn = new ColumnDefinition();
testColumn.Width = new GridLength(140);
gridTrombi.ColumnDefinitions.Add(testColumn);
if (i == 0)
{
testRow = new RowDefinition();
testRow.Height = new GridLength(120);
gridTrombi.RowDefinitions.Add(testRow);
}
gridTrombi.Width = 1000;
Image image = new Image();
image.BeginInit();
TextBox txt = new TextBox();
BitmapImage img;
try
{
img = new BitmapImage(new Uri(s._photo));
}
catch (Exception)
{
img = new BitmapImage(new Uri("pack://application:,,,/ApplicationENI;component/Images/portrait-vide.jpg"));
}
image.Source = img;
image.Stretch = Stretch.Uniform;
TextBox txtBoxTest = new TextBox();
txtBoxTest.Background = Brushes.AliceBlue;
txtBoxTest.TextAlignment = TextAlignment.Center;
txtBoxTest.BorderThickness = new Thickness(0);
image.SetValue(Grid.ColumnProperty, i);
image.SetValue(Grid.RowProperty, j);
txtBoxTest.Text = s._prenom + " " + s._nom;
txtBoxTest.SetValue(Grid.ColumnProperty, i);
txtBoxTest.SetValue(Grid.RowProperty, j + 1);
gridTrombi.Children.Add(image);
// redéfinition de la hauteur de ligne pour le nom du stagiaire
if (i == 0)
{
testRowNomStagiaire = new RowDefinition();
testRowNomStagiaire.Height = new GridLength(30);
gridTrombi.RowDefinitions.Add(testRowNomStagiaire);
}
gridTrombi.Children.Add(txtBoxTest);
i += 1;
photo++;
}
//.........这里部分代码省略.........
示例11: CreateThisButton
//.........这里部分代码省略.........
if (BeforeImageAttribute != null)
{
BeforeImagePath = GetButtonFileName(BeforeImageAttribute.Value);
if (!File.Exists(BeforeImagePath))
{
throw new Exception("HandleAllButtonPage.CreateThisButton\r\n" +
"Der File (\"" + BeforeImagePath + "\") für ein Before-Image fehlt");
BeforeImagePath = null;
}
}
if (AfterImageAttribute != null)
{
AfterImagePath = GetButtonFileName(AfterImageAttribute.Value);
if (!File.Exists(AfterImagePath))
{
throw new Exception("HandleAllButtonPage.CreateThisButton\r\n" +
"Der File (\"" + AfterImagePath + "\") für ein After-Image fehlt");
AfterImagePath = null;
}
}
int ButtonColumn = Convert.ToInt32(ColumnAttribute.Value);
int ButtonRow = Convert.ToInt32(RowAttribute.Value);
if (!String.IsNullOrEmpty(BeforeImagePath))
{
beforeImageSource = ConvertFileNameToBitmapImage(BeforeImagePath);
}
if (!String.IsNullOrEmpty(AfterImagePath))
{
afterImageSource = ConvertFileNameToBitmapImage(AfterImagePath);
}
if (RootIsDynamic == false && (afterImageSource == null))
{
column2 = new GridLength(1, GridUnitType.Star);
column3 = new GridLength(1, GridUnitType.Pixel);
}
Button rootButton = new Button();
rootButton.Style = mybuttonstyle;
rootButton.Tag = ButtonEntry;
Grid buttonGrid = new Grid();
buttonGrid.ColumnDefinitions.Add(new ColumnDefinition());
buttonGrid.ColumnDefinitions.Add(new ColumnDefinition());
buttonGrid.ColumnDefinitions.Add(new ColumnDefinition());
buttonGrid.ColumnDefinitions[0].Width = column1;
buttonGrid.ColumnDefinitions[1].Width = column2;
buttonGrid.ColumnDefinitions[2].Width = column3;
Image imagebefore = new Image();
if (beforeImageSource != null)
{
imagebefore.BeginInit();
imagebefore.MaxHeight = beforeImageSource.Height;
imagebefore.MaxWidth = beforeImageSource.Width;
imagebefore.Source = beforeImageSource;
imagebefore.EndInit();
}
imagebefore.Style = beforeImageStyle;
Image imageafter = new Image();
if (afterImageSource != null)
{
imageafter.BeginInit();
imageafter.MaxHeight = afterImageSource.Height;
imageafter.MaxWidth = afterImageSource.Width;
imageafter.Source = afterImageSource;
imageafter.EndInit();
}
imageafter.Style = afterImageStyle;
TextBlock textBlock = new TextBlock();
textBlock.Style = textBlockStyle;
textBlock.Text = Text;
buttonGrid.Children.Add(imagebefore);
buttonGrid.Children.Add(textBlock);
buttonGrid.Children.Add(imageafter);
Grid.SetColumn(imagebefore, 0);
Grid.SetColumn(textBlock, 1);
Grid.SetColumn(imageafter, 2);
rootButton.Content = buttonGrid;
if (RootIsDynamic == true)
{
Button_Grid_Root.Children.Add(rootButton);
}
else
{
Static_Grid_Root.Children.Add(rootButton);
}
Grid.SetColumn(rootButton, ButtonColumn);
Grid.SetRow(rootButton, ButtonRow);
rootButton.Click += ButtonClickEventHandler;
}
示例12: DrawImage
private double DrawImage(Canvas canvas, MemoryStream memoryStream, Rect dest, TileInfo tile)
{
Image image = images.Find(tile.Index);
if (image == null)
{
image = new Image();
memoryStream.Seek(0, SeekOrigin.Begin);
BitmapSource source = BitmapFrame.Create(memoryStream);
image.BeginInit();
image.Source = source;
image.EndInit();
images.Add(tile.Index, image);
Canvas.SetZIndex(image, tile.Index.Level);
image.Opacity = 0;
AnimateOpacity(image, 0, 1, 600);
}
if (!canvas.Children.Contains(image))
canvas.Children.Add(image);
Rect destRounded = new Rect(
new Point(
Math.Round(dest.X) - 0.5,
Math.Round(dest.Y) - 0.5),
new Point(
Math.Round(dest.X + dest.Width) + 0.5,
Math.Round(dest.Y + dest.Height) + 0.5));
Canvas.SetLeft(image, destRounded.X);
Canvas.SetTop(image, destRounded.Y);
image.Width = destRounded.Width;
image.Height = destRounded.Height;
image.Visibility = Visibility.Visible;
return image.Opacity;
}
示例13: ShowBitmapSource
private void ShowBitmapSource (BitmapSource ClipboardContentImage, String ContentFormatParameter)
{
Window BitmapWindow = new Window ();
BitmapWindow.Title = ContentFormatParameter;
ScrollViewer Scroll = new ScrollViewer ();
BitmapWindow.Content = Scroll;
Image BitmapImage = new Image ();
BitmapImage.BeginInit ();
BitmapImage.Source = ClipboardContentImage;
BitmapImage.EndInit ();
Scroll.Content = BitmapImage;
BitmapWindow.ShowDialog ();
}