Add link to image in specific area of image - c#

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.

Related

itextsharp hyperlink a image and have it open in default viewer when picked

I have a pdf file created with itextsharp with images in the file. I would like to put a hyperlink in the file that if you pick the picture it will open that picture in a picture viewer. I can set a hyperlink to a web address but have no idea how to get it to open a file. Below is the code, yes I know that c:\test.jpg is a bad hardcoded file name but it is just a test. When you click the picture it does nothing but I have no idea how to tell it what to do.
iTextSharp.text.Image pic =TextSharp.text.Image.GetInstance(comment.examplePic);
pic.ScaleToFit(200f, 200f);
Chunk cImage = new Chunk(pic, 0, 0, false);
Anchor anchor = new Anchor(cImage);
anchor.Reference = "c:\\test.jpg";
doc.Add(pic);
doc.Add(anchor);
A PDF is self-contained. This means that all the resources needed to show the PDF are (usually) stored inside the PDF (exceptions are for instance fonts that can be retrieved from the operating system).
When you have an image that is shown on a PDF page, the bytes of that image are stored in what we call an Image XObject. An XObject is an object that is external to the page, but that is stored as a separate object inside the PDF file.
You are asking to serve the image bytes stored inside this separate object to a viewer on the operating system. This is impossible. I don't know of any viewer that can take those bytes and somehow forward them to an image viewer.
I can think of three possible workarounds. I don't know if any of these workarounds is acceptable to you.
1. Serve the image online
You could put the image on a server and use the code you have in your snippet to link to that online image. Of course: this will only work if the person viewing the document is online and clicks OK when his viewer asks him if it's OK to link to a resources on the internet.
2. Serve the image as an annotation
In this case, you create an annotation for which you create an appearance that renders that same image XObject in the annotation layer (all annotations are shown on top of the page content). You can easily change the visibility status of an annotation to make it invisible (in your case, this would be the default status) or visible (in your case, this would be triggered by a JavaScript action when clicking the link).
There's an example of such an annotation here: Advertisement. If you open advertisement.pdf, you see an image with a button that says "Close this advertisement". Once you click that, the status of the annotation will be changed to invisible. You could do something similar, but the other way round: click a link to make it visible instead of invisible.
This solution doesn't depend on an external viewer, the image is shown in the PDF viewer.
3. Add the image as optional content
Starting with PDF 1.5, PDF supports optional content. See for instance the OptionalContentExample. In this example, we have some questions and answers, but the answers are not visible by default. See layer_actions.pdf. There are links "on / off / toggle" to make the answers visible or invisible.
You could do the same with images: you could add them to a layer that is invisible by default, but that can be made visible if somebody clicks a link. However: this requires a viewer that supports OCG (optional content groups) and the actions to change the status of these OCGs. For instance: if you would try the layer_actions.pdf example in the PDF viewer in Chrome, it won't work, but if you download the PDF and open it in Adobe Reader, you'll see the behavior I described.
Summarized:
You are asking something that is impossible, but there are workarounds. Please post another question if you have chosen a workaround and you don't succeed in making that workaround word (but please take into account that not all viewers support every workaround).
no offence but too much knowledge sometimes makes you ignorant of small things.
simple solution to this problem is here
http://kuujinbo.info/iTextSharp/imageAnchor.aspx
sample code that i implemented works like charm
PdfPCell p1 = new PdfPCell();
p1 = new PdfPCell();
p1.Padding = 0;
p1.Border = 0;
PdfPTable nav = new PdfPTable(1);
nav.WidthPercentage = 100;
nav.SpacingAfter = 12;
navbarImg.Annotation= new Annotation(0, 0, 0, 0, ur);
p1.Image = navbarImg;
nav.AddCell(p1);
_doc.Add(nav);

How to display image with user input URL?

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.

Image Preview from on click event c# asp .net

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.

How to render a string containing HTML into an image in C#?

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.

Why are image acting as downloads?

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.

Categories