dineshwins
asked on
Winforms webbrowser control and loading image directly from stream
I have a requirement where I have to load images in windows application webbrowser control and rather loading them from physical location with path. I have to load them from stream directly(from database).
After searching I found in web we can use handler for this however I am not sure how I can do this in winforms or we can say how to load generic handler in winforms webbrowser control.
Kindly suggest.
Thanks in advance.
After searching I found in web we can use handler for this however I am not sure how I can do this in winforms or we can say how to load generic handler in winforms webbrowser control.
Kindly suggest.
Thanks in advance.
Might it be easier to write the images to a temporary file, or are you not permitted to do that?
ASKER
Yes, Basically we have to create multiple thumbnails of single image may be 20 in one page, hance saving will adversily effect the performance so I am looking for any solution by which we wont save the image physically and retrive and display directly from stream. Is there any way for doing this in winforms application
One way you could do this would be to use data URIs. Basically, you base64-encode your image data and then use a special URI to disseminate the image. Following is a crude example. I am reading the binary data from a file, but you should be able to conceptualize this data coming from a DB instead.
Which, using this image:
...gives something like this:
using System;
using System.Windows.Forms;
namespace _27484075
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
byte[] data = System.IO.File.ReadAllBytes("example.png");
string encoded = Convert.ToBase64String(data);
string url = "<html><body><img src=\"data:image/png;base64," + encoded + "\" /></body></html>";
this.webBrowser1.DocumentText = url;
}
}
}
Which, using this image:
...gives something like this:
Here's what the source of the resulting page looks like:
<html>
<body>
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAASUAAABvCAIAAAAlsUGeAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAagSURBVHhe7ZxPTisxDIffRbgOh+EuHIAFG1YsYMGCW3ABhJBASG/BJXilMG2SyR9nXuN66g+xQmni/Oxv7DhD/3zxgwIooKXAH62FWAcFUOAL3ggCFNBTAN70tGYlFIA3YgAF9BSANz2tWQkF4I0YQAE9BeBNT2tWQgF4IwZQQE8BeNPTmpVQAN6IARTQUwDe9LRmJRSAN2IABfQUgDc9rVkJBeCNGEABPQXgTU9rVkIBeC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dZ2z1KOBG38xPa//OWbCHN3vHJc2fA7GoR3nrohLdlvJ1VjmHt++vfq+ptEEvulBv9lSz82SNWSEv6qVlCk9zar+aye9OV6eFi1Fh4k/MmO799F0uSF4t3VwLtsD7c+a2WFedXapIHh/hQKtd51MhRDPXMC29y7zZLuHCqFnJByqqHdbs/me9YNPuTaY2avcLO3BzG75HBWw9uX/Am521f+4nfqMhRVzjwtO7EZ3ZO58CiMdkB0x9znEyIJgAnFe/G/uAvYil6dB7TUOkCY9BgeDt+HKhd+B5qoSATrumbvwYh1DUtvMFbrwJddXXv5APHd4ExaDC8DXTwofKJpXniCnk9l930Jwl02wq0Xkzb/Ofbig5v8GY72sYc2S1lqrr+rf7qpku5quQGb/BmWoHGTcDaYIM309G2nkQ0UsbG94WNXHpAfTGoBdI1Lf2SlQUND4LFCnSBMWgwvMGbFwUGIdQ1Lbx5ibbFaeFkPtgFxqDB8AZvXhQYhFDXtPDmJdpOJk0t3kgXGIMGwxu8eVFgEEJd08Kbl2hbnBZO5oNdYAwaDG/w5kWBQQh1TTuKty4jGIwCThSANyeOZpsmFIA3E27ACCcKwJsTR7NNEwrAmwk3YIQTBeDNiaPZpgkF4M2EGzDCiQLw5sTRbNOEAvBmwg0Y4UQBeHPiaLZpQgF4M+EGjHCiALw5cTTbNKEAvJlwA0Y4UQDenDiabZpQAN5MuAEjnCgAb04czTZNKABvJtyAEU4UgDcnjmabJhSANxNuwAgnCsCbE0ezTRMKwJsJN2CEEwXgzYmj2aYJBeDNhBswwokC8ObE0WzThALwZsINGOFEAXhz4mi2aUIBeDPhBoxwogC8OXE02zShALyZcANGOFEA3pw4mm2aUADeTLgBI5woAG9OHM02TSgAbybcgBFOFIA3J45mmyYUgDcTbsAIJwr8A5jrZMwtcrlxAAAAAElFTkSuQmCC" />
</body>
</html>
ASKER
thanks for the information.
I will implement this and will check the formats however during searching I have seen this, however it has been mentioned that it is restricted to certain image size. Is this the case and what if i have to use large image. Can you please suggest
I will implement this and will check the formats however during searching I have seen this, however it has been mentioned that it is restricted to certain image size. Is this the case and what if i have to use large image. Can you please suggest
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.