How to add System.Drawing.Image object to Asp:Image Control but I dint have imageId in my table.Image field is in another table..i retrieve image from database in Image object.i want to display it in asp:Image control or grid view.how to do it?? pls send reply... C#
The Image class and <asp:image> control are completely different thing.
You need to have a page or http handler to write the Image object as an image file such as .jpg / .png / .gif. And then use the <asp:image> control to access the URL of your page or http handler to get the image file you generated and display it. <asp:image> basically only render a HTML <img> tag with the URL of the image.
You can use this ASP.NET module and the SqlReader plugin to serve images directly from the database.
You can then reference the images like so:
<asp:Image runat="server" ImageUrl="/sqlimages/[imageidhere]" />
Related
so started using a new method for dynamicly displaying images inserted into my database. This is the asp.net code
<asp:ImageButton ID="ImageButton1" ImageUrl='<%#Eval ("ImageUrl", "~/img/{0}") %>' Width="200px" PostBackUrl='<%#Eval ("ProductID", "Product.aspx?ProductID={0}") %>' runat="server" />
now, as you can see what it does is getting the "ImageUrl" from my database depending on what the ProductID is, and then shows that as the image url. Example in my folder /img/ i have a picture called "pic.jpg" then this code would make the image url "~/img/Pic.jpg" now how would i add a new image into the table from the backend? i would have to make a flileupload control upload the file to the "img" folder and then insert only the file name as the "ImageUrl" in the database table. How is this done? do you have any examples or can point me in the right direction?
thanks!
all answers appreciated!
ImageButton is actually a html input type image. So you should not use it for just display purposes. You can use Image control or even use html img tag.
Check this link for FileUpload control
http://asp.net-tutorials.com/controls/file-upload-control/
Check this link for Image control
http://www.w3schools.com/aspnet/showaspx.asp?filename=demo_image
Below is my html image control:
<img alt="" src="C:\Users\hkalidindi\Desktop\Feedback.jpg" style="height: 19px; width: 20px"/>
But after debugging it is not showing me any image:
I am new to dotnet..please help me to solve this issue...I know how to display image in image control but i am bit confused about the html image control...
Use image only from the content of your website. So copy the image in your website folder say Images and access your image as <img alt="" src="..\images\Feedback.jpg" style="height: 19px; width: 20px"/>. Or you could use Asp.NET Image control and set image path in Server code using
myImage.ImageUrl=Server.MapPath("Images\Feedback.jpg");
"C:\Users\hkalidindi\Desktop\"
Is only local, try uploading it to a website such as http://imageshack.us, http://tinypic.com, grab the direct link and put that in the source.
<img src="URL">
Here URL = The url of the image.
Possible values (for src):
An absolute URL - points to another web site (like src="http://www.example.com/image.gif")
A relative URL - points to a file within a web site (like src="image.gif")
Refer: HTML src Attribute
You are trying to call the image in your local folder. Add the image to the 'Images' folder in your solution and link to that.
Make sure the image is being referenced from a folder that is in your websites application/dir. Then you can reference it simply by using a tag like so:
<asp:Image id="imgFeedback" runat="server" ImageUrl="~/_common/img/feedback.jpg" />
Or set the image path on the server side:
this.imgFeedback.ImageUrl = Server.MapPath("\_common\img\feedback.jpg\");
I need to use the asp control "ImageButton" in order to have access to the properties "OnClick" and "OnClientClick"
The problem is i cannot give any ImageURL since my Image is in Database.
I used this previously :
<telerik:RadBinaryImage runat="server" ID="RadBinaryImage1" DataValue='<%#Eval("Image") %>'
AutoAdjustImageControlSize="false" Width="90px" Height="110px" Enabled="true" AlternateText="pas d'image"/>
But i don't have any Datavalue property in ImageButton control...
How can i manage to do this using ImageButton?
thanks in advance
You can use a Generic Handler file and call that as your ImageUrl like:
<asp:ImageButton ImageUrl='<%# String.Format("Image.ashx?id={0}", eval("ID")) %>' />
Read more on how to do this here:
http://www.dotnetcurry.com/ShowArticle.aspx?ID=129
The fact its an ImageButton makes no difference. It's the fact you want to render an image from image data type. I believe generating the image on the fly using a Generic Handler file is the most common way.
You can use handler for creating image from database or from binary format and this handler you can call from your imagebutton -> imageURL and it will show the image on the page.
You may provide a method that will return an image as stream. Your URL may be:
http://www.yourwebsite.com/Application/Images/GetImage?name=myImageName&format=png
Inside your site you'll provide a GetImage page to query the database and write in the output stream the image data (do not forget to set the mime type).
I have made a program to download an image automatically. I pass the html code ,I see the SRC attribute of the IMG html element is not the exact image file url ,it is like the following:
<img id="door2img" width="450" height="50"
src="/pincode/pin1.php?lang=zh&r=1309587154480&rule">
It is confusing, I am using c# webcontrol for programming. I can get the img html element,how can I dowload the image in such a situation,because there's not the image url?
Extract the value of the src attribute and append it to the base url (i.e. in http://some.site.com/section/page?id=5 the base url would be http://some.site.com). Pass that string to WebClient.DownloadFile or WebClient.DownloadData and you'll get what you need.
In .NET(C#), I'm loading an image. The src of the image is stored in the database.
I currently retrieve text from my db using this:
TextBox4.Text = reader["descr"].ToString(); // snippet
However, I want to know, how would I display an image?
Image1.Text= reader["img1"].ToString();
and then in my WebForm:
<asp:Image ID="Image1" runat="server" />
Use the ImageUrl property instead.
Try
Image1.ImageUrl = reader["img1"].ToString();
Have you tried Image1.ImageUrl = reader["img1"].ToString();
This one has been answered many times on so:
Basically you need to create an image handler to load the binary stream of the image to the browser. Also if you are going this route, please remember to use the cache header for each image so you are not pulling data from your database on every request.
ASP.NET [Image Handler]
Enjoy!