Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Assembly asm = Assembly.GetExecutingAssembly();
- Stream iconStream = asm.GetManifestResourceStream("SomeImage.png");
- PngBitmapDecoder iconDecoder = new PngBitmapDecoder(iconStream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
- ImageSource iconSource = iconDecoder.Frames[0];
- _icon.Source = iconSource;
- Image finalImage = new Image();
- finalImage.Width = 80;
- ...
- BitmapImage logo = new BitmapImage()
- logo.BeginInit();
- logo.UriSource = new Uri("pack://application:,,,/ApplicationName;component/Resources/logo.png");
- logo.EndInit();
- ...
- finalImage.Source = logo;
- var uriSource = new Uri(@"/WpfApplication1;component/Images/Untitled.png", UriKind.Relative);
- foo.Source = new BitmapImage(uriSource);
- string packUri = "pack://application:,,,/AssemblyName;component/Images/icon.png";
- _image.Source = new ImageSourceConverter().ConvertFromString(packUri) as ImageSource;
- Assembly asm = Assembly.GetExecutingAssembly();
- Stream iconStream = asm.GetManifestResourceStream("SomeImage.png");
- BitmapImage bitmap = new BitmapImage();
- bitmap.BeginInit();
- bitmap.StreamSource = iconStream;
- bitmap.EndInit();
- _icon.Source = bitmap;
- if (File.Exists(imagePath))
- {
- // Create image element to set as icon on the menu element
- Image icon = new Image();
- BitmapImage bmImage = new BitmapImage();
- bmImage.BeginInit();
- bmImage.UriSource = new Uri(imagePath, UriKind.Absolute);
- bmImage.EndInit();
- icon.Source = bmImage;
- icon.MaxWidth = 25;
- item.Icon = icon;
- }
- <MenuItem Name="mnuFileSave" Header="Save" Command="ApplicationCommands.Save">
- <MenuItem.Icon>
- <Label VerticalAlignment="Center" HorizontalAlignment="Center" FontFamily="Wingdings"><</Label>
- </MenuItem.Icon>
- </MenuItem>
- VisualBrush brush = new VisualBrush { TileMode = TileMode.None };
- brush.Visual = frame;
- brush.AlignmentX = AlignmentX.Center;
- brush.AlignmentY = AlignmentY.Center;
- brush.Stretch = Stretch.Uniform;
- GeometryDrawing drawing = new GeometryDrawing();
- drawing.Brush = brush;
- //Brush this in 1, 1 ratio
- RectangleGeometry rect = new RectangleGeometry { Rect = new Rect(0, 0, 1, 1) };
- drawing.Geometry = rect;
- new DrawingImage(drawing);
- <Image>
- <Image.Source>
- <BitmapImage UriSource="/yourassembly;component/YourImage.PNG"></BitmapImage>
- </Image.Source>
- </Image>
- Properties.Resources.ResourceManager.GetURI("my_image");
- // Convert the image in resources to a Stream
- Stream ms = new MemoryStream()
- Properties.Resources.MyImage.Save(ms,ImageFormat.Png);
- // Create a BitmapImage with the Stream.
- BitmapImage bitmap = new BitmapImage();
- bitmap.BeginInit();
- bitmap.StreamSource = ms;
- bitmap.EndInit();
- // Set as Source
- Source = bitmap;
- this.Icon = new BitmapImage(new Uri("Icon.ico", UriKind.Relative));
- <UserControl.Resources>
- <ResourceDictionary>
- <ImageBrush x:Key="PosterBrush" ImageSource="..ResourcesImagesEmptyPoster.jpg" Stretch="UniformToFill"/>
- </ResourceDictionary>
- </UserControl.Resources>
- ImageBrush posterBrush = (ImageBrush)Resources["PosterBrush"];
- <Button Width="200" Height="70">
- <Button.Content>
- <StackPanel>
- <Image Width="20" Height="20">
- <Image.Source>
- <BitmapImage UriSource="/Company.ProductAssembly;component/Icons/ClickMe.png"></BitmapImage>
- </Image.Source>
- </Image>
- <TextBlock HorizontalAlignment="Center">Click me!</TextBlock>
- </StackPanel>
- </Button.Content>
- </Button>
- static ImageSource PngStreamToImageSource (Stream pngStream) {
- var decoder = new PngBitmapDecoder(pngStream,
- BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
- return decoder.Frames[0];
- }
- Uri iconUri = new Uri("pack://application:,,,/ImageNAme.ico", UriKind.RelativeOrAbsolute);
- NotifyIcon.Icon = BitmapFrame.Create(iconUri);
Add Comment
Please, Sign In to add comment