I need show 2,54MB jpeg image (15232 x 7912 pixels, 96DPI) in Silverlight 5.0.
I using BitMapImage component and image not showing.
When opening a browser window by doubleclick on image, will sometimes appear.
When i have breakpoint in ImageFailed handler i see in eventargs ErrorException: "AG_E_NETWORK_ERROR" (InnerException is null).
What does it mean?
Thanks and sorry for my english.
Code below.
string url = await GetDocumentURLAsync(...);
bitmapImage.UriSource = new Uri(url);
image.Source = bitmapImage;
image.ImageFailed += (sender, e) =>
{
System.Diagnostics.Debug.WriteLine(e.ErrorException);
};
Related
I'm working on an UWP project and I want to load a WebView with opacity = 0.01f, and only set opacity to 1.0f when WebView_LoadCompleted is called. Until then it is presented by a preview image. But when I'm showing it, it flickers white in like 1 on 20 cases, and I'm testing the same WebView content.
My code looks like this:
Grid grid = new Grid();
//set previewImage as preview of grid content
Image backgroundImage = new Image();
backgroundImage.Source = new BitmapImage(new Uri(#"ms-appdata:///local/" + "some path"));
grid.Children.Add(backgroundImage);
grid.SetValue(Grid.RowProperty, slide.Pos.Y);
grid.SetValue(Grid.ColumnProperty, slide.Pos.X);
MainGrid.Children.Add(grid);
WebView webView = new WebView();
webView.NavigationStarting += WebView_NavigationStarting;
webView.LoadCompleted += WebView_LoadCompleted;
webView.ScriptNotify += WebView_ScriptNotify;
webView.Opacity = 0.01f;
Uri navigationUri = "some local file Uri");
webView.NavigateToLocalStreamUri(navigationUri, myResolver); // myResolver checks if source is allowed to load
webView.Width = 1024;
webView.Height = 768;
Viewbox viewBox = new Viewbox();
viewBox.Stretch = Stretch.Uniform;
viewBox.Child = webView;
grid.Children.Add(viewBox);
And my WebView_LoadCompleted looks like this:
private void WebView_LoadCompleted(object sender, NavigationEventArgs e)
{
WebView webView = (WebView)sender;
webView.Opacity = 1.0f;
}
I was expecting that the WebView will only render its laoded content right away because it is visible (with low opicity) in the ViewBox, and most of the times it is not flickering, but it still appears.
Trying to get a call after WebView_LoadCompleted didn't work yet, I tried some calls like x_LayoutUpdated, x_SizeChanged for the WebView and the ViewBox, but WebView_LoadCompleted is the last called function that runs into a breakpoint.
Setting the WebView.DefaultBackgroundColor to transparent didn't work, it still flickers white.
Placing the WebView below the Image and getting it to the front after a delay for layout time didn't work.
Thanks for your help! I appreciate it!
It looks like there is no proper way to validate that the webview is finished with all possible loading and rendering processes for the webview.
But you can use this answer of another question for other UIElements:
Answer
This question already has an answer here:
Attach Image/ImageBrush from code behind
(1 answer)
Closed 6 years ago.
I would like to set the background image for a button to an image I have from a URL; but the following code does not work:
var button = new Button();
Image image = new Image();
image.Source = new BitmapImage(new Uri("https://cdn4.iconfinder.com/data/icons/ionicons/512/icon-folder-128.png", UriKind.Absolute));
button = image;
Specifically "button = image" doesn't work, because Button isn't Image type.
How should I set an image to be the background image of a button?
You can accomplish this by using WebClient to first download the image locally before displaying it in the Button control
using (WebClient c = new WebClient())
{
c.DownloadFile("https://cdn4.iconfinder.com/data/icons/ionicons/512/icon-folder-128.png", "D:/image.png");
}
button.Image = Image.FromFile("D:/image.png");
Where D:/image.png is the location you would like to save your image to
Ok, I've got a solution.
var button = new Button();
var image = new ImageBrush();
image.ImageSource = new BitmapImage(new Uri(url, UriKind.Absolute));
button.Background = image;
My default background image is "lobby.jpg" and when I click the "Lights" button I want it to swap with "lobby1.jpg" and vice versa. These images are stored in "obj\Debug\Images\".
Also I'd like to implement relative(?) imagesource uris so that I can access the images on any machine (without using the whole uri, just the "obj\Debug\Images\").
Edit: So the main issue seems to be that I tried changing the window background without realising that it was getting "covered" by the grid background of the page. So what I did is I set the main window background to "lobby.jpg", I made the grid background invisible and used the code from the answer to swap between the 2 backgrounds.
You can use AppDomain basepath to exe (this is are simplest way)
var basePath= AppDomain.CurrentDomain.BaseDirectory;
var imageDirPath = $"{basePath}\\Images\\";
Example:
bool clicked = false;
private void button_Click(object sender, RoutedEventArgs e)
{
var basePath = AppDomain.CurrentDomain.BaseDirectory;
var imageDirPath = $"{basePath}\\Images\\";
if (clicked)
image.Source = new BitmapImage(new Uri(imageDirPath+ "lobby.jpg"));
else
image.Source = new BitmapImage(new Uri(imageDirPath + "lobby1.jpg"));
clicked = !clicked;
}
I'm a novice programmer so don't be brutal.
I'm making a game for Windows Store, and I want to animate a run cycle. I made many GIF animations but all have BLACK background, and I need it transparent. So I've decided to make a run cycle using DispatcherTimer. Everything works fine, but the images don't change :/
void timer_Tick(object sender, object e)
{
numer++;
if (numer > 8) numer = 1;
hero.Source.Equals("Assets/Anim/" + nazwa + numer + ".png");
}
Also, When I TAP a different image, it should change the image and other images, but it doesn't... what is wrong?
bool sun = true;
private void Image_Tapped(object sender, TappedRoutedEventArgs e)
{
sun = !sun;
if (sun == false)
{
Image1.Source.Equals("moon.png");
Image2.Source.Equals("ON.png");
}
else
{
Image1.Source.Equals("sun.png");
Image2.Source.Equals("OFF.png");
}
}
The xaml works fine, as the images are shown.
I have checked this question:
ImageTools on Windows Phone 8, changing ImageSource and DataContext
but I get loads of errors. I don't seem to understand how the property changed works.
it seems to be a small mistake. You are using the wrong method.
Image.Source.Equals()
is a boolean method that simply compares the current source with the "source" you give as arguement and will return true or false based on the comparison.
But what you want is to set the source of the image.
So you need to use:
Image1.Source = new BitmapImage(new Uri("moon.png", UriKind.RelativeOrAbsolute));
This will set the source of the Image to the new image you want.
Assuming that "moon.png" is in the main folder in your solution, the two solutions both work:
BitmapImage tn = new BitmapImage();
tn.SetSource(Application.GetResourceStream(new Uri(#"moon.png", UriKind.Relative)).Stream);
Image1.Source = tn;
Or
Image1.Source = new BitmapImage(new Uri("moon.png", UriKind.Relative));
Good morning everyone!
I've been having some issues regarding photos in my Windows Phone app. I'm trying to take a photo and save it to a record, and then load it up again at a different point.
My idea is to take the photo using the code in this tutorial (http://msdn.microsoft.com/en-us/library/windowsphone/develop/hh394006(v=vs.105).aspx)
In my constructor:
cameraCaptureTask = new CameraCaptureTask();
cameraCaptureTask.Completed += new EventHandler<PhotoResult>(cameraCaptureTask_Completed);
lower down..
void cameraCaptureTask_Completed(object sender, PhotoResult e)
{
if (e.TaskResult == TaskResult.OK)
{
//Code to display the photo on the page in an image control named myImage.
//System.Windows.Media.Imaging.BitmapImage bmp = new System.Windows.Media.Imaging.BitmapImage();
//bmp.SetSource(e.ChosenPhoto);
//System.Diagnostics.Debug.WriteLine(e.OriginalFileName);
//string imageLoc = e.OriginalFileName;
//Uri imageUri = new Uri(imageLoc, UriKind.RelativeOrAbsolute);
//StreamResourceInfo resourceInfo = Application.GetResourceStream(imageUri);
//Code I'm using just now which just displays the photograph
System.Windows.Media.Imaging.BitmapImage bmp2 = new System.Windows.Media.Imaging.BitmapImage();
bmp2.SetSource(e.ChosenPhoto);
myImage.Source = bmp2;
}
}
From my code, you can see that the commented out bit returns the location of the image which has just been taken, then attempts to load it up from there. However, when I try that, I get URI path exceptions and the like. What is going wrong here and what method should I use to remedy it?
I'd like to be able to add the file path to a record and then be able to load it back up elsewhere in my app.
Thanks for any help!