I found out how to generate an image in code-behind based on some input from a webform, great. now i want to put that image back onto the form after the postback. All the samples i found use the Response to send the image back out to the browser with a stream.
Is there anyway to specify that the image generated in the code behind, be the source of a image control (or placeholder or whatever)?
If there is a way of doing this is there way of doing it without saving the image to the disk?
thanks
The web browser has to be able to retrieve the image somehow. If you don't want to save it, then it will require sending it with a Response stream.
You can create an HTTP Handler (ashx) and based on query string parameters generate and return an image. This would allow you to specify the image objects "ImageUrl" property as "~/MyImageHandler.ashx?param1=value1"
The http://imageresizing.net library can dynamically process images, as well as generate them. Could you provide more detail about what you are trying to do?
Related
I am using one of Telerik's ASP.NET controls the RadEditor, and I need to be able to get the data content out as a ByteArray so that I can then attach it to an email. I was wondering if that is possible to do?
There is a built in function that allows you to export the content in a PDF file format to the browser by calling myEditor.ExportToPDF(). The problem is that this is a void method that just outputs to the browser so I can not use that. There is also an OnExportContent event on the server-side but I am not sure if I can get the content as a ByteArray from this event? There is also the problem that it would still output to the browser as that event is called after you call the export function.
http://www.telerik.com/help/aspnet-ajax/editor-export-to-pdf.html - the documentation will show you how. About halfway in the middle you will see how to take the output and redirect the page back to itself to avoid the pdf streaming to the browser.
I have an Web-application in which I capture Image using EdgeCamShots Sample Application
Saving Silverlight 4 Webcam
how can I use this capture image to be used in Next Page without saving Image.
A view model object reference (created from the application's MainPage) would be an object that both pages would have access to. Pass a reference to the pages on navigation changed event. That view model might make a good container for the stream and would give both pages access to the stream.
You can simply pass the stream (mentioned in the code example on the link you provided) to the next page using REST (adding the variable in the URL e.g. http://mysite/page2.aspx?stream=dstStream).
From there on, you can use the variable to show your picture.
I am currently trying to create a custom server control in asp.net c# and am using VS2010.
I am trying to create a custom server control that can load images straight into a separate web project. E.g. Custom Server Control and a separate web project where I can drag and drop my control onto it with minimal installation and config. The point being it can be re used anywhere on other web projects.
I have created a basic custom control, but I need to be able to load images directly through the custom server control and display them in my separate web project. The images will be coming from a static location for the time being.
So basically I have an image, I want to load and pass that image into the control and then display it on a webpage where the custom control is placed. I have investigated image handlers, and having separate generic handlers but am not having any luck.
Image location --> Custom Control --> Web page displaying image that has been passed into custom control.
Anyone have any idea how to do this, or go about this?
UPDATE:
I am sorry I was not clear enough first time round.
I have two projects, one custom control project, and one asp.net website project. The first project (Custom Control) takes a byte stream from a webservice and converts it to an Image object. At this point I want the control to add that image to a webpage in the website. The custom control is then registered with the asp.net website and the controls I have added are rendered to the page. However I want to render the image I have recovered from the buffer, then converted to a file locally onto the web page.
I have no problem getting the image from the bytestream, and storing the image in a directory. The issue I am having is that I want the image to be rendered on the webpage, without having the image stored in the web project at first. I have thought about storing the image in a web directory so when I run the project I can set an image url to localhost/images/myimagefrombystream.jpg but am unsure whether this is the correct approach.
Any ideas?
We have a server controls library that contains some images that are reused across a number of other web projects.
The approach we took was to mark the each images build action as Embedded Resource. Then in the AssemblyInfo file we have lines like the following:
[assembly: WebResource("AssemblyName.SubDirectory.ImageName.png", "image/png")]
Where AssemblyName is the actual project name, the SubDirectory is the directory in the project the image(s) are located in, etc.
This project also emits CSS files; which are also Embedded Resources. The CSS files refer to these images using:
.someImage {
height: 85px;
background-image: url(<%=WebResource("AssemblyName.SubDirectory.Image.png") %>);
background-repeat: repeat-x;
margin: 0px;
padding: 0px;
}
In the class code, we'll refer to those css files like:
HtmlLink cssLink = new HtmlLink();
cssLink.Href = Page.ClientScript.GetWebResourceUrl(this.GetType(), "AssemblyName.css.SomeCssFile.css");
cssLink.Attributes.Add("rel", "stylesheet");
cssLink.Attributes.Add("type", "text/css");
We could just as easily refer to the images directly using something like the above.
At this point the assembly is 100% portable. All of the CSS files and required images are embedded into it so you don't have to worry if the calling application has those same images at all.
Incidentally, this is how a number of control vendors do things; at least the better ones.
I don't know why you're complicating. Simply, add ImageUrl property (not public field) to your custom control, expect the client-code of your control to set it, and if not null, in CreateChildControls add an Image control to the control tree. Alternatively, add the image to control-tree always, but make it visible/invisible from within the setter of that property (or elsewhere you see fit). I didn't understand half of what you said related to your envisioned solution, to be honest - so, I hope I didn't miss the topic here :)
I'm not sure I understood the question, but let me try anyway.
As far as I understood you have two projects, in one you want to upload an image to a certain location, in the other one you want to show that image.
I would simply have a file upload control in the 1st application, and use it to upload the image to the desired location.
In the other application you can use a generic handler. The handler can get the image file name from the 1st application using query string parameters, then it will locate the image on disk and return a response with a proper header, for example:
response.ContentType = "image/jpeg";
response.OutputStream.Write(image, 0, (int)request.InputStream.Length);
response.Flush();
response.End();
I assume that you have created this custom control in a class library. of the image source is static (some fixed base url) and just that image name changes you can expose a ImageUrl property (string) and render a tag based on the attributes (all can be default) with the custom ImageUrl as the src attribute of the tag.
Hope that helps!
I'm using an asp:FileUpload control to give the user the chance to look for an image on the hard drive, once the user has chosen the image, after a button is pressed, I want to display the image in an asp:Image control.
I've been trying to get the full path of the file but I can't get it, I'm using Path.GetFullPath(FileUpload.FileName) but I'm getting a totally different path, not the path to the image that the user selected.
I was reading that I need to set the src attribute of the asp:Image control to be an aspx page which is going to return the image, and then I have to write the bytes from the image to the response but I'm not sure how to do this (I'm a newbie in web development), I don't know what should I put in my event, in the code behind, or what code should I place on the aspx page that will return the image, neither how to call the aspx page with the image from the event handler.
Can anyone show me a good example on how to achieve this please?
The issue here is the file being uploaded resides on the client computer where the asp:image control is looking for an image on the server computer.
What you should be doing is on the form submit/button click save the file into the application folder then reference that file with your asp:image control.
You can use the project mentioned below to preview the image before uploading. Working sample is also attached.
http://www.dotnetspider.com/resources/40858-Preview-Image-before-uploading-using.aspx
This uses AjaxControlToolKit's AsyncFileUploadControl and HTTPHandler to upload the image.
On my Form Load event I am creating a bitmap using System.Drawing classes, and I want to display this image on my WebForm. How can I do that?
Thanks!
You can't create this bitmap directly in your webform. You will need to implement custom HttpHandler that will render this image separately.
Serving Dynamic Content with HTTP Handlers
HTTP Handlers for Images in ASP.NET
Use Custom HTTP Handlers in Your ASP.NET Applications
Instead of creating the image in the code behind for your page, what you should do is create a URL for the image that somehow describes or defines the image's content (perhaps along with session state or a cookie if you need to), and attach that URL to a regular <img> (or <asp:Image>) tag.
Then, when the browser requests that URL, your code determines the parameters from the query string or cookies or whatever, generates and sends the response, and returns it with the correct MIME type. That's usually best done from a Generic HttpHandler (*.ashx).