473,805 Members | 1,995 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to open an image file and display in picturebox?

Seems simple but Im missing something. In a C# form Ive got a picturebox
and a button

I have the File Open dialog linked to the button, but Im drawing a blank on
how to take the stream and push the thing onto the picturebox.

Here is the code, tia

OpenFileDialog fileChooser = new OpenFileDialog( );

DialogResult result = fileChooser.Sho wDialog();

string filename; //name of file containint data

if (result == DialogResult.Ca ncel)

return;

filename = fileChooser.Fil eName;

if (filename == "" || filename == null)

MessageBox.Show ("Hey, thats a not a what I want a see", "Error",
MessageBoxButto ns.OK, MessageBoxIcon. Error);

else

{

input = new FileStream(file name, FileMode.Open, FileAccess.Read );

}

try {

pictureBox1.Ima ge = input; //NO WAY, IT HAS AN ERROR THAT SAYS

cannot implicity convert type system.io.files tream to system.drawing. image

}

catch( Exception ex )
Nov 16 '05 #1
2 20561
Image img = Image.FromFile( filename);

pictureBox1.Ima ge = img;

"Bradley123 4" <so*****@yahoo. com> ha scritto nel messaggio
news:wjvpd.9717 $5v1.749@trnddc 06...
Seems simple but Im missing something. In a C# form Ive got a picturebox
and a button

I have the File Open dialog linked to the button, but Im drawing a blank on how to take the stream and push the thing onto the picturebox.

Here is the code, tia

OpenFileDialog fileChooser = new OpenFileDialog( );

DialogResult result = fileChooser.Sho wDialog();

string filename; //name of file containint data

if (result == DialogResult.Ca ncel)

return;

filename = fileChooser.Fil eName;

if (filename == "" || filename == null)

MessageBox.Show ("Hey, thats a not a what I want a see", "Error",
MessageBoxButto ns.OK, MessageBoxIcon. Error);

else

{

input = new FileStream(file name, FileMode.Open, FileAccess.Read );

}

try {

pictureBox1.Ima ge = input; //NO WAY, IT HAS AN ERROR THAT SAYS

cannot implicity convert type system.io.files tream to system.drawing. image

}

catch( Exception ex )

Nov 16 '05 #2
Thanks, that worked!

"CiccioPall a" <Ci*********@NO SPAMxiansoft.ne t> wrote in message
news:Of******** ******@TK2MSFTN GP10.phx.gbl...
Image img = Image.FromFile( filename);

pictureBox1.Ima ge = img;

"Bradley123 4" <so*****@yahoo. com> ha scritto nel messaggio
news:wjvpd.9717 $5v1.749@trnddc 06...
Seems simple but Im missing something. In a C# form Ive got a picturebox and a button

I have the File Open dialog linked to the button, but Im drawing a blank

on
how to take the stream and push the thing onto the picturebox.

Here is the code, tia

OpenFileDialog fileChooser = new OpenFileDialog( );

DialogResult result = fileChooser.Sho wDialog();

string filename; //name of file containint data

if (result == DialogResult.Ca ncel)

return;

filename = fileChooser.Fil eName;

if (filename == "" || filename == null)

MessageBox.Show ("Hey, thats a not a what I want a see", "Error",
MessageBoxButto ns.OK, MessageBoxIcon. Error);

else

{

input = new FileStream(file name, FileMode.Open, FileAccess.Read );

}

try {

pictureBox1.Ima ge = input; //NO WAY, IT HAS AN ERROR THAT SAYS

cannot implicity convert type system.io.files tream to system.drawing. image
}

catch( Exception ex )


Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
57342
by: yaya via DotNetMonster.com | last post by:
Hi, I have a picture box with circles and rectangles, and I wana save all the images into a jpg file, i tried pictureBox1.Image.Save(@"c:\1.jpg"); but I got and error "System.NullReferenceException: Object reference not set to an instance of an object." Can anyone help? Thanks... --
3
63450
by: Tom | last post by:
I have a picturebox on my VB.NET form. The picturebox size mode is set to stretched. I then load an image into that form and display it. As the user moves the mouse over the form, I want to get and display (in the status bar) the image coordinates of the mouse location. However, if I use the picturebox's MouseMove event, I am getting the coordinates of the mouse over the PICTUREBOX, not the actual image underneath that (which is stretched)....
4
2576
by: John Swan | last post by:
Hello. I'm trying to create a simple program that amongst other things creates a thumbnail of an image (Bitmap) to a set size determined by the user in pixels? The problem is: All of the examples I have seen so far are in c#. Can anyone please provide reference to a c++ managed version. Thanks. John
1
4255
by: MrNobody | last post by:
I have browsed the Net and found some library called DevIL which was ported to C# by some fellow but apparantly while itloads some tga files many times it fails, not sure why- no errors thrown just no image displayed in my PictureBox. And this is using the reference app that they made as well. Do you know any other library out there (free) that does this?
7
3795
by: Ben | last post by:
Hi We are looking for a component that offers that offers the below for Tiff files: Image clean-up (deskew, despeckle) Printing capabilities from VB The ability to add text to image, e.g. time / date Nice to have:
1
2200
by: Jeff Williams | last post by:
I have a picture (jpg) displaying in a picture box but I find that the file handle is still open to the image on disk. I think I need the following to happen 1. Load image from file on disk 2. Copy the loaded image to another object. 3. Close the file on disk 4. Display the image in the picture box as a thumbnail. 5. Allow user to rotate image if necessary by reloading the file
3
22548
by: Andrzej | last post by:
I have a picturebox on my C# .NET form. The picturebox size mode is set to zoom. I then load an image into that form and display it. As the user moves the mouse over the form, I want to get and display (in the status bar) the image coordinates of the mouse location. However, if I use the picturebox's MouseMove event, I am getting the coordinates of the mouse over the PICTUREBOX, not the actual image underneath that (which is zoomed). i.e....
1
3532
by: nanaalwi | last post by:
Hi, Currently I'm developing a software using VB.net that can grab an image using Matrox Morphis card and display it in a PictureBox. The software can grab the image already and display it in the form (Imports Matrox.ActiveMil). But the problem is I need to display the image in the PictureBox but I don't know how. The coding to grab the image is as follows: ActiveMILApplication = CreateObject("MIL.Application")
1
3547
by: Rishi Boparai | last post by:
Hi, in Visual Studios there's this tool called PictureBox rite...but in Visual Web developer i can't seem to find it.. i'm using Visual Web Developer...VB language..to make a watermarking script so firstly i need to be able to load the picture i want to the page first.. in VS the code is
0
9716
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10607
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10359
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10364
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10104
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9182
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6875
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5541
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3843
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.