1
Answer

change a picturebox image

Photo of wooi83

wooi83

21y
2.6k
1
i want to ask how to change the picturebox image and the image is in my C:/

Answers (1)

1
Photo of Padmalatha Dronamraju
NA 218 3.5k 7y

Attachment Files.zip

Hi hemalatha,
I just tested with Image Control and a sample bitmap image in sample asp.net web application. It is displaying the image of extension .bmp.
 
I think this is not the problem with Image Control. It is supporting .bmp files.
 
I am attaching sample for your reference. 
 
Thank you. 
 
 
 
 
0
Photo of Srikant Maruwada
NA 501 4.4k 7y
  1. Convert Image to Bytes.  
  2.   
  3. public static byte[] ImageToByte2(Image img)  
  4. {  
  5.     byte[] byteArray = new byte[0];  
  6.     using (MemoryStream stream = new MemoryStream())  
  7.     {  
  8.         img.Save(stream, System.Drawing.Imaging.ImageFormat.Png);  
  9.         stream.Close();  
  10.   
  11.         byteArray = stream.ToArray();  
  12.     }  
  13.     return byteArray;  
  14. }  
  15.   
  16. In the code behind use   
  17.   
  18. Convert BMP file to img.  
  19.   
  20. System.Drawing.Image img = null;   
  21. img = System.Drawing.Image.FromFile(Server.MapPath(_ImageUrl));  
  22.   
  23. var imgArr= ImageToByte2(img);  
  24.   
  25. string base64String = Convert.ToBase64String(imgArr= , 0, imgArr= .Length);  
  26. Image1.ImageUrl = "data:image/jpeg;base64," + Convert.ToBase64String(base64String)  
0
Photo of Yogesh Vedpathak
NA 331 3.6k 7y
add this code
  1. protected void Page_Load(object sender, EventArgs e)  
  2. {  
  3. Bitmap bitmapimg = new Bitmap(120, 120, PixelFormat.Format32bppArgb);  
  4. Graphics grph = Graphics.FromImage(bitmapimg);  
  5. SolidBrush br = new SolidBrush(Color.Green);  
  6. grph.FillEllipse(br, 4, 4, 110, 110);  
  7. Response.ContentType = "image/gif";  
  8. bitmapimg.Save(Response.OutputStream, ImageFormat.Gif);  
  9. bitmapimg.Dispose();  
  10. }  
0
Photo of hema latha
NA 27 448 7y
I am sry but system.Drawing.Bitamp doesnt exists ,shown as it is included in system.Drawing name space.Sry if iam wrong
0
Photo of Yogesh Vedpathak
NA 331 3.6k 7y
try this 
system.Drawing.Bitamp 
0
Photo of hema latha
NA 27 448 7y
even that is not displaying the bmp images
0
Photo of Yogesh Vedpathak
NA 331 3.6k 7y
check namespaces 
System.Drawing  
 
 
0
Photo of hema latha
NA 27 448 7y
I am not getting any error its not displaying the image it is showing blank for bmp images
0
Photo of Yogesh Vedpathak
NA 331 3.6k 7y
code is reflect correctly can you please check your image type
.and which line you get an error
0
Photo of hema latha
NA 27 448 7y
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
//Image1.ImageUrl = Server.MapPath("~/bin") + "\\Images\\4.bmp";
}
}
protected void Timer1_Tick(object sender, EventArgs e)
{
SetImages();
// Image1.ImageUrl=
}
private void SetImages()
{
try
{
NameValueCollection list = new NameValueCollection();
list.Add("1", Server.MapPath("~/bin") + "\\Images\\1.bmp");//~/bin/Images/1.bmp");
list.Add("2", Server.MapPath("~/bin") + "\\Images\\2.jpg");//"~/bin/Images/2.bmp");
list.Add("3", Server.MapPath("~/bin") + "\\Images\\3.jpg");//"~/bin/Images/3.bmp");
list.Add("4", Server.MapPath("~/bin") + "\\Images\\4.bmp");//"~/bin/Images/4.bmp");
list.Add("5", Server.MapPath("~/bin") + "\\Images\\5.bmp");//"~/bin/Images/5.bmp");
list.Add("6", Server.MapPath("~/bin") + "\\Images\\6.bmp");//"~/bin/Images/5.bmp");
list.Add("7", Server.MapPath("~/bin") + "\\Images\\7.bmp");//"~/bin/Images/5.bmp");
Random rad = new Random();
int i = rad.Next(0, 7);
Image1.ImageUrl = list[i].ToString();
}
catch (Exception)
{
throw;
}
}
 aspx page code  I am using ajax timer,update panel
 
 
 
 
 
<html xmlns="http://www.w3.org/1999/xhtml">
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Timer ID="Timer1" runat="server" OnTick="Timer1_Tick" Interval="2000"></asp:Timer>
<asp:Image ID="Image1" runat="server" />
</ContentTemplate>
</asp:UpdatePanel>
</form>
</body>
</html>
 
0
Photo of Yogesh Vedpathak
NA 331 3.6k 7y
HI Hema we need to see your code first