According to my understanding, you did not assign the PictureBox Image property, so it returns null for the cast type.
The PictureBox property automatically converts the image format, and if you see a tooltip for the Image property, it displays System.Drawing.Bitmap. Check your image property correctly assigned.
Check it out, it works on my side.
private void button1_Click(object sender, EventArgs e) { Bitmap bmp = (Bitmap)pictureBox1.Image; } private void TestForm12_Load(object sender, EventArgs e) { pictureBox1.Image = Image.FromFile("c:\\url.gif"); }
/// Using the BitMap class
Bitmap bmp = new Bitmap(pictureBox2.Image);
You can directly use pictureBox2.Image for Bitmap, how you do it, and also use the Bitmap class to convert to an object of the Bitmap class.
Link: Raster constructor (image) .
Here you can find more options with a raster class.
Niranjan kala
source share