Squatcher
Member
- Joined
- Mar 1, 2023
- Messages
- 5
- Programming Experience
- Beginner
Good afternoon,
I want to add a group of web based images to ImageList, so that I can then use the ImageList with a pictureBox to rotate which images using a timer. But I it seems to be having issues.
Any suggestions on where I can find a tutorial or suggestions where I am messing up?
I want to add a group of web based images to ImageList, so that I can then use the ImageList with a pictureBox to rotate which images using a timer. But I it seems to be having issues.
Any suggestions on where I can find a tutorial or suggestions where I am messing up?
C#:
public void Solar_Image()
{
try
{
string imageUrl = @"https://sdo.gsfc.nasa.gov/assets/img/latest/latest_512_0094.jpg";
string saveLocation = @"C:\Users\richa\source\repos\Ham_Radio\latest_512_0094.jpg";
//string imageUrl2 = @"https://sdo.gsfc.nasa.gov/assets/img/latest/latest_512_0193.jpg";
//string saveLocation2 = @"C:\Users\richa\source\repos\Ham_Radio\Solar_0193_Image.jpg";
byte[] imageBytes;
HttpWebRequest imageRequest = (HttpWebRequest)WebRequest.Create(imageUrl);
WebResponse imageResponse = imageRequest.GetResponse();
Stream responseStream = imageResponse.GetResponseStream();
using (BinaryReader br = new BinaryReader(responseStream))
{
imageBytes = br.ReadBytes(500000);
br.Close();
}
responseStream.Close();
imageResponse.Close();
FileStream fs = new FileStream(saveLocation, FileMode.Create);
BinaryWriter bw = new BinaryWriter(fs);
try
{
bw.Write(imageBytes);
imageList1SolarImages.Images.Add(Image.FromStream(fs));
pbSolarImage.Image = imageList1SolarImages.Images[0];
}
finally
{
fs.Close();
bw.Close();
}
}
catch (Exception ex)
{
MessageBox.Show("Error" + ex);
}
}
Timer:
private void timer1_Tick(object sender, EventArgs e)
{
// pbSolarImage.Image = imageList1SolarImages.Images[0];
pbSolarImage.Image = imageList1SolarImages.Images[0];
if (intImgNum == imageList1SolarImages.Images.Count - 1)
{
intImgNum = 0;
}
else
{
intImgNum++;
}
}