I'm trying to load several images from URLs to a pictureBox.
My problem is that "pictureBox.Load(URL)" or "pictureBox.ImageLocation = URL" doesn't work.
I don't know why, I think it is because the URL doesn't have an extension like .jpg.
private void button3_Click(object sender, EventArgs e)
{
string URL = "https://internetmarke.deutschepost.de/internetmarke/franking/image/view/1403556118.do";
pictureBox1.ImageLocation = URL;
}
The URL works in Firefox and the picture is shown. But in IE it doesn't work and I think that's the same reason why it's not working in .NET.
IE says "unknown filetype" and wants to download a "1403556118.do" file.
In C# I only get a red X in the pictureBox.
When I first try to load it in IE, it works in the pictureBox (IE cache?)
Does somebody knows another possibility to load this images to a pictureBox?
EDITED: Added sample code.
Today I've tested the code on three different computers and with different Internet connections; Home DSL, Company DSL and a UMTS/3G Surf-Stick. All without any proxies and also tested without virusscan.
In every single scenario it didn't work, same as I wrote in my first post.
After I accessed some of the URLs in Firefox or IE, the images of these URLs showed up in my application. All others remained a red X.
Is there any different (old-school^^) method to load these images, like downloading the HTTP-Stream into a byte array and then copy this into pictureBox.Image or something?
Dino
pictureBox1.ImageLocation = "http://www.micoequipment.com/products/large/MF_260_l.jpg"; //should work
Make sure that image is accessible via web browser (test it before). Also, please make sure that you are calling correct picture box :)
It works for me.
#Andrew:
pictureBox1.ImageLocation = "http://www.micoequipment.com/products/large/MF_260_l.jpg";
This Works!
pictureBox1.ImageLocation = "https://internetmarke.deutschepost.de/internetmarke/franking/image/view/1403556118.do";
This doesn't work!
Your link and my link both work in Firefox. But my link doesn't work in IE and it doesn't work in .NET and in the pictureBox.
This should work since you're loading an image from a remote URL:
pictureBox1.Load(URL);
Related
I just use simple code to load image in asp.net image control, it works fine in IE but firefox does't show image. the line of code is:
string path = "F:\\Image\\";
string img = "header-firefox.PNG";
Image1.ImageUrl = path + img;
and the error is:
The address wasn't understood
Firefox doesn't know how to open this address, because the protocol (f) isn't associated with any program.
even file:///F:/Image/header-firefox.PNG path is not working in code even.
Do you mean that is the path you see in the HTML? I understand that the backslashes are escaped in C# but surely in the HTML the path should be "\\192.172.60.05\Users\4133.Png"?
Have you tried navigating to \192.172.60.05\Users\4133.Png directly in Firefox?
I am developing a C# web project. I run it on the local web server.
I draw. I show image as follows:
bitmap.Save(Server.MapPath("diagram.jpg"), ImageFormat.Jpeg);
Image1.ImageUrl = ResolveUrl("diagram.jpg");
I don't see new image. Only old one, which I had after changing image name
(Say, I change diagram.jpg to diagram2.jpg).
Browser is Firefox.
The design page in C# is simple. Just Image and few TextBoxes on the page.
No UpdatePanel and such.
Something with caching... But how to fight with that...
But how to fight with that.
Always use a separate path / name. Pug a GUID somewhere. Simple like that. Different file can not be cached.
I'm not sure what ResolveUrl does, but try adding a querystring to the image url so that the page always gets a "fresh" file. Something like this:
Image1.ImageUrl = ResolveUrl(string.Format("diagram.jpg?v={0}", Guid.NewGuid()));
You can alternative write the image file as
diagram.jpg?ver=2
to keep the same image file, but force the browser to update it.
If Image has Same name and URL browser picks the image from the cache and displays the same for faster loading of the pages.
Even if you change the image server side the same cached image is displayed until you clear the cache of the browser. You can use query string to change image url like below.
Image1.ImageUrl = ResolveUrl("diagram.jpg?" + DateTime.Now.Ticks.ToString());
I'm trying to display a local PDF file in a WebBrowser-Control. I didn't want to use the Adobe-Libraries, because they don't support 64-bit. Now I already have the code to display a PDF, but only if it is not on the local HDD. When I right-clicked on the WebBrowser-Control and displayed the SourceCode of the HTML, I saved it as an HTML-File to check, if the HTML-Code is correctly working. Well, it works.
My window only consists of a maximized WebControl. I think the problem are the Security Settings of the local Internet Explorer. I read that a custom IInternetSecurityManager could solve the problem, but I don't know how to implement it... :/
I'm using C# with .NET Framework 4.0
Here is my code:
void MainWindow_Loaded(object sender, RoutedEventArgs e)
{
string url = "C:/test.pdf";
string html = "<!-- saved from url=(0014)about:internet -->\n<html>\n<body>\n<embed src=\"" + url + "\" width=\"100%\" height=\"100%\"/>\n</body>\n</html>";
webBrowser.NavigateToString(html); // System.Windows.Controls.WebBrowser
}
I the "saved from URL" part does only work if I directly open the HTML-Code in IE, so please tell me what to do, to get this code work... Maybe you have a better solution for my problem. Thanks for your help!
Regards,
Chris
Just use
webBrowser.Navigate("file:///" + url);
For a project I'm working I would like the user (admin) to be able to change the picture on the page he is currently on. I managed to upload the image to "the server" using interlink. This basicly uploads it to a given folder on a server, in my case being: Interlink/Uploads.
But now I don't really know how can I tell my website to replace the source of the image that is currently shown with the source of the uploaded image.
Another something I would like to do is create a simple image gallery with all the images in that folder, once again I don't know how to do this.
I hope somebody can help me, Thanks.
Thomas
Edit: Just so clarify, the application is written in silverlight (XAML, C#). I apologise for any inconvenience.
I take it that the "Silverlight" portion of this question is related only to Interlink (your file uploader), and not to the page itself, which I presume is straight HTML.
If that's the case, you've got several options for changing the local image. The simplest way is simply to wait until you know that your file upload has finished (presumably Interlink has some way of notifying you that this is the case), and then run something like this bit of JavaScript:
<script type='text/javascript'>
function changeImage(newImageSource) {
document.getElementById('myTargetImage').setAttribute('src', newImageSource);
}
</script>
As far as displaying a simple image gallery with all the images in the folder, my recommendation would be to look into one of the numerous jquery plugins that handle this sort of thing, e.g.:
http://www.1stwebdesigner.com/css/fresh-jquery-image-gallery-display-solutions/
EDIT: Silverlight Options
You basically have the same options, except you're doing them in C# instead of JavaScript. For instance, when Interlink tells you that the new image has been uploaded, run this:
string imageName = "something.jpeg";
var ub = new UriBuilder(HtmlPage.Document.DocumentUri);
ub.Path = "/Interlink/Uploads/" + imageName;
img.Source = new BitmapImage(ub.Uri);
And for an image carousel, something like this:
http://3dimagecarousel.codeplex.com/
You'll just need to provide the URL's of all the images. The easiest way to do that is probably to expose a web service method that lists them all.
Hi there
I am working with visual web developer and would a) like to know how I could programatcally add a picture to the website, instead of going to Website and then add existing item. The idea I have is to upload the picture using the file upload control but then I want to have it added so that it can be accessed using a gridview.
b)I would also like to know how to size the picture using C# code obviously so that is displayed at the correct size.
best regards
arian
here is a full project with source code to manipulate images, including resize.
http://www.codeproject.com/KB/web-image/ASPImaging1.aspx
And a sample code only for resize
http://weblogs.asp.net/gunnarpeipman/archive/2009/04/02/resizing-images-without-loss-of-quality.aspx
You can use GetThumbnailImage to easily create a smaller verson of the uploaded image. The code looks something like (it's free typed without a compiler, so there may be some errors):
System.Drawing.Image pic = new System.Drawing.Bitmap(sourceFilename);
System.Drawing.Image thumb = pic.GetThumbnailImage(targetXSize,targetYSize,
new System.Drawing.Image.GetThumbnailImageAbort(this.GetThumbnailImageAbort),
IntPtr.Zero);
thumb.Save(thumbPathName);
I believe the Image implements IDisposable, so you need to remember to Dispose of them when you're done.
The abort parameter can be a function that simply does this (can't remember off the top of my head when it gets called):
bool GetThumbnailImageAbort() {
return false;
}