I am using C# ASP.NET. I generate user friendly image names and use rewrite to find the correct image name. Normally in firefox when i right click an image and hit view image i get the image in my browser. However these images are acting like downloads, why?
global.asax:
void Application_BeginRequest(Object sender, EventArgs e)
{
lazy(Context, HttpContext.Current.Request);
}
file.cs:
void lazy(...)
{
...
context.RewritePath(sz);
//sz = "/user/username/type/image.png"
}
Likely because the correct MIME type is not being sent along with the image.
The mime-type of the image is probably being reset by the RewritePath call. If so, FireFox then thinks that the image is just a binary stream and doesn't know what to do with it so it just attempts to download it.
Related
I managed to display the binary image from database to image control using generic handler. I want to open the image on new tab or copy it's link address using right click from the mouse. But the URL used is the address of the generic handler
(http://localhost:1948/admin/imghndlr.ashx?serial=qwertyuiop). I tried searching but didn't get any results, maybe wrong keywords used. Below is the screenshot of the image in new tab.
How are you displaying the image?
Your View File should look something like this, of course you need to change data:image/jpeg on what file extension your using.
<img alt="" src="data:image/jpeg;base64,iVBORw0KGgoAAAANSUhEUgAAAsMAAAGhCAIAAAALOi7ZAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH3QgLEhM6PUSGrwAAIABJREFUeNq8vcuSLEmWHKZ6jnlEZt5761Z3T/eAHAICAYRcEALsuOCWPzbzDfwP/gKXWJACoRDCBSkEBgPhADKY7qnu+4wIdztHuThmHh55q2t6ho+SlpaqyMwID3ez89CjqsY//dM//bM/+zMc/pGE3//PT/z09/1I0t/1Rz/x+o9+0I++vv/n8fU/8MW/9U9+9JVvL/v/u1cy86cv5ttfePXKq//8fTfhp+/qT3/oq8v+6V/+Ay/v25/+4X/46nqO"/>
Also if its a byte file dont forget to Convert it.
Convert.ToBase64String(Foto);
You need add data mime-type to make browser know what type does you responsed data is. added code look like below:
public void ProcessRequest(HttpContext context)
{
//image/png is png mime
context.Response.ContentType = "image/png";
//read buffer from database
context.Response.BinaryWrite(buffer);
}
I'm creating a image as a signature for Outlook, so im creating a template that my co-workers can edit to their own personal information.
But i want the company site, personal linkedin, and company facebook in the document as links. So when you click on it it sends you to the site (a link usually does that )
This is what the image looks like when i convert it to an image:
As you can see in the image you have a couple of thinks that should be filled in by the person using the application. The image is a panel that is converted with this code:
private void ConvertToImageButton_Click(object sender, EventArgs e)
{
Bitmap bmp = new Bitmap(BackgroundPanel.Width, BackgroundPanel.Height);
BackgroundPanel.DrawToBitmap(bmp, BackgroundPanel.Bounds);
bmp.Save(#"C:\Users\collin-k\repo\test.png", ImageFormat.Png);
}
**Question: **
How can i add links to the image on a specific place, lets say the place of the website label.
Is this even possible or do you have another idea for a signature that looks like this. The image is a easy way because you can easily edit it.
Having a bit of trouble getting started on making a simple HTTP image browser. I am doing this in C# and using a Windows Form Application. The requirements included are that I prompt the user for a URL of an image which is inputted in a textbox (I believe I have to use an HTTPwebRequest, but not sure), and then click a button and display the image in a picturebox. I'm used to writing console applications, and am brand new to the Windows Forms commands, which is why I'm looking for some help.
**In addition, but not necessary, is the inclusion of a status code of the image, as well as associated headers that are returned by google's web server, which are displayed in textboxes. Sorry if this is too vague, I am just completely lost, and anything would help.
If you drop a TextBox, a Button and a PictureBox onto your form, you can use the code below to download an image from the internet, convert it to an image and show it in the PictureBox.
m_urlTextBox is the TextBox the user can use to enter the image URL.
m_downloadButton is the button that the user clicks to initiate the download.
m_pictureBox is the PictureBox used to draw the downloaded image.
The code for the Click event handler for the download button is shown below.
private void m_downloadButton_Click(object sender, EventArgs e)
{
using (var client = new WebClient())
{
var imageData = client.DownloadData(m_urlTextBox.Text);
var converter = new ImageConverter();
var image = (Image)converter.ConvertFrom(imageData);
m_pictureBox.Image = image;
}
}
I've made no attempt to handle errors or conversion failures, but this should give you the gist of what is required. If you need to inspect the headers associated with the image, you should look into WebRequest.Create / GetResponse / GetResponseStream etc. instead of using WebClient.
I'm currently trying to look at a directory, and then preview a .jpeg from a list box. I have the list box populating with the contents of the directory and only showing Jpegs, but I can't think of what to do to get the jpeg preview in a picture box. I'm using an asp .net application on Visual Studio 2010.
This is the code I have
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
DirectoryInfo infoDir = new DirectoryInfo(#"G:\Test_Directory");
FileInfo[] infoFile = infoDir.GetFiles("*.jpeg");
foreach( FileInfo file in infoFile )
{
lstDirectory.Items.Add(file.Name);
}
}
protected void lstDirectory_SelectedIndexChanged(object sender, EventArgs e)
{
}
}
I'm under the understanding Postback needs to be used. If anyone is able to help, that would be great.
The file which is in the G: Drive, is a jpeg, which can be seen in the list box is : jpegimage.jpeg
Thanks.
How about something like this?
I think you could do this mostly in Javascript, with two additional ASP.NET page.
First, create a new web page. We'll call this A.aspx. This page will be passed the image name in the query string. It will be very simple: it will just fetch the contents of the file from "G:\TestDirectory" and write it to the Response stream. There are quite a few questions and answers on Stack Overflow on how to do this, if you haven't done it before.
Then, create another web page. We'll call this B.aspx. This will have an image control with height and width set appropriately. It will also take the image name from its query string. The code-behind will build a URL to use as the ImageSource property on the image control. The URL will be that of A.aspx, with the (URL-encoded) image name appended as a parameter.
On your ASP.NET page, hook up an event handler to your listbox. When the selected index on the list box changes, on the client side, build a URL, based on the URL to B.aspx with the image name from the list box appended as a parameter. Then open a window, using the URL you just built, pointing to B and passing the desired file name.
So: when the list box selected index changes (or when you double click, or whatever event you pick), the javascript will open a window with page B.aspx. Page B will have an image control, set to the URL to A.aspx. A.aspx will stream the image contents to the image control, which will appear in your new window.
I am developing a web application that has an interactive feedback tool for users. In this application users can click a send feedback button. The button puts up an overlay over their current web page and allows them to drag highlight area DIVs to emphasize certain areas. Once they submit their feedback the HTML of the entire page is passed via AJAX back to the server.
Once on the server I now have a string containing the HTML of the page. From here I would like to run this string through some sort of engine that renders the HTML and builds an image. A sort of round about way of taking a screenshot if you will.
How might one accomplish something like this? Are there engines available that are written in C# and can build up the HTML and render an image?
Check out this framework - http://awesomium.com/
This is exactly what you need.
Set the base URL, this will be needed to resolve any relative URLs
WebCore.SetBaseDirectory("C:\\MyApplication\\MyBaseDirectory");
Then load the HTML -
myWebView.LoadHTML("<p>Hello World!</p>");
Then use the .Render() method, and you'll be able to save the rendered content to an image.
You can consider usin LLMozLib if you want to go by Gecko.
See more details here
EDIT
There's an ActiveX control to embed Gecko on Windows.
Sample here
EDIT
I got it working on a Windows Forms application.
Using these resources.
It is a csharp wrapper to Gecko ...
That's my sample code ...
public partial class Form1 : Form
{
public Form1()
{
Xpcom.Initialize(#"C:\Users\esouza\Downloads\xulrunner"); //Tell where are XUL bin
InitializeComponent();
//geckoWebBrowser1 is an instance of GeckoWebBrowser control that I've dragged on the Form1
geckoWebBrowser1.DocumentCompleted += new EventHandler(geckoWebBrowser1_DocumentCompleted);
}
private void button1_Click(object sender, EventArgs e)
{
geckoWebBrowser1.Navigate("http://www.google.com");
}
void geckoWebBrowser1_DocumentCompleted(object sender, EventArgs e)
{
Bitmap b = new Bitmap(geckoWebBrowser1.Width, geckoWebBrowser1.Height);
geckoWebBrowser1.DrawToBitmap(b, new Rectangle { X = 0, Y = 0, Width = 800, Height = 600 });
b.Save("file.bmp");
}
}
Very interesting question and I've not got a silver bullet for you.
You're surely going to need a browser engine of some description and then capture the rendered output as a bitmap.
I see from this question that there was a COM wrapper developed for WebKit. Maybe that's a good starting point.