Loading an embedded resource PNG image into any view works fine, but when i try to load an embedded resource SVG image it wont appear any reasons why !
this code works fine
Image devimage= new Image() { Source = ImageSource.FromResource("DOTFORMS3.Icons.developers.png") };
but this code wont make the svg image appears
Image devimage= new Image() { Source = ImageSource.FromResource("DOTFORMS3.Icons.developers.svg") };
i even tried this code still nathing !
SvgCachedImage devimage= new SvgCachedImage() { Source = ImageSource.FromResource("DOTFORMS3.Icons.developers.svg") };
if you want to load an SVG, use SvgImageSource with SvgCachedImage
Related
I have a List where the string is the url of an image.
I am trying to dynamically create a grid of images with the source being each url.
I have tried binding but it doesn't seem to work. I also cannot access the x:Name of an image I created in Xaml. I am open to doing this in Xaml or in the code behind.
Any ideas of how to do this.
//imageList is a List<string> with your image urls in it
foreach(var i in imageList) {
Image image = new Image();
image.Source = ImageSource.FromUri(new Uri(i));
// you will need to add logic to calculate the Row/Column for each image
myGrid.Children.Add(image,x,y);
}
I have the following code for showing an image:
Image im = new Image();
im.Source = new BitmapImage(new Uri("Icons.login.jpg", UriKind.RelativeOrAbsolute));
im.Height = 200;
im.Width = 200;
icons.Add(new IconImagesForDummies() { Name = str, Image = im });
The Image class belongs to System.Windows.Controls.Image. I have added a folder to store images separately from Resources folder (named Icons). But I have set the build action property of all images to Embed Resource and they have been set to Copy Always. I do not know why I can not see the images. I'm using WPF. During debugging I found out that the image path was fine and it founded that, but I do not know the reason, the image was not showed. I have read here but was useless.
Is there something wrong with the Uri?
EDIT: maybe its just this simple
im.Source = new BitmapImage(new Uri(#"Icons\login.jpg", UriKind.Relative));
Edit: changing build action to content works.
My aim is to extract an image from a loaded webbrowser control.
// get the image link from the image element ID.
string imageLink = wbVideos.Document.GetElementById("sbvdcapimg").GetAttribute("src").ToString();
//Download the image into a bitmap
Bitmap image = new Bitmap(new System.IO.MemoryStream(new System.Net.WebClient().DownloadData(imageLink)));
so the code works for most pictures, but i receive me a format error when i use it with the link below.
The error is thrown when i parse this link into my code: "http://www.swagbucks.com/?cmd=cp-get-captcha-image&ctype=1&tai=478817685&sid=0.4015013770493371"
(Please Note to view the image you need to login!)
Notice how the image does not end in a extension, this is most likely causing the error.
Example of the extracted link:
so, my question, how can i make my code accept this link as a valid image file?
I want to change the background of a button manually in my WPF app.
I have an image imported into my resources and I want to do:
MyButton.Background = MyProject.Properties.Resources.myImage;
But I get the error:
cannot implicitly convert system.drawing.bitmap to media.brush
How can I do this??
You should read about brushes first here.
And then use ImageBrush, something like this:
MyButton.Background = new ImageBrush(...);
(or, maybe, put the brush into resources...)
UPDATE
You can find how to create imageSource from bitmap easilly. for example, here. Like:
var bitmapSource = Imaging.CreateBitmapSourceFromHBitmap(MyProject.Properties.Resources.myImage.GetHbitmap(),
IntPtr.Zero,
Int32Rect.Empty,
BitmapSizeOptions.FromEmptyOptions());
MyButton.Background = new ImageBrush(bitmapSource);
In a WPF application, you do usually not add image resources as you did in WinForms.
Instead you add the image file directly to your Visual Studio project, just like any other file. If there are multiple images, it may make sense to put them in a subfolder of the project (e.g. called "images"). The Build Action of that file has to be set to Resource (which is the default for image files).
Now you can create a BitmapImage from a Pack URI to that file.
Finally you create an ImageBrush from the BitmapImage to set the Background property.
var uri = new Uri("pack://application:,,,/images/myImage.jpg");
var image = new BitmapImage(uri);
MyButton.Background = new ImageBrush(image);
I'm trying to display splash screen for my WPF application. Based on some condition I have to load one of two images I have created. So i have to use SplashScreen class instead of setting a static image as flashscreen. Which is easy and works in my case.
I'm doing something like following,(I have set the both images as Embedded Resource)
string splashImage = string.Empty;
if (Condition)
{
splashImage = "ApplicationType1.png";
}
else
{
splashImage = "ApplicationType2.png";
}
SplashScreen screen = new SplashScreen(splashImage);
screen.Show(true);
Which gives me exeception,
Cannot locate resource ApplicationType1.png
Finally i figured it out,
Problem was with the .png image i have added. Still i have no clue why it couldn't load that specific image. I just got the .jpg image and it works fine.
And it works with both build actions Embedded Resource or Resource