Reputation: 985
I have write below codes in c# to display an image in PictureBox
but when run the application, nothing shown...
Please help me to fix that.
here is my code:
private void button1_Click(object sender, EventArgs e)
{
PictureBox p =new PictureBox();
p.ImageLocation = "1.jpg"
p.Location = new Point(100, 75);
}
Upvotes: 3
Views: 54564
Reputation: 1
public static async Task<PictureBox> CargarImagenDesdeUnDirectorioAsync()
{
PictureBox pbImage
try
{
openFileDialog.Title = "Open Image";
openFileDialog.Filter = "Imagen (*.jpg)|*.jpg|Imagen (*.png)|*.png";
openFileDialog.InitialDirectory = Environment.GetFolderPath (Environment.SpecialFolder.MyPictures);
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
// pbImage.ImageLocation = openFileDialog.FileName;
pbImage.Image = new Bitmap(openFileDialog.FileName);
await Task.Delay(200);
}
}
catch (Exception e)
{
MessageBox.Show("Error al cargar la imagen, mensaje del error: " + e.Message);
}
return pbImage;
}
Upvotes: 0
Reputation: 11
It's possible that the PictureBox size is small and your image is too big (check the SizeMode property to "StrechImage") I was using a high res PNG icon with transparent background and took a little time to figure out.
Upvotes: 1
Reputation: 10965
PictureBox.Image = new Bitmap("yourImage.jpg");
The formats supported
are: BMP, EMF, EXIF, GIF, ICON, JPEG, PNG, TIFF and WMF.
Upvotes: 6