Display image on Bitmap
-
i am trying to pick a image file from open dialog box and send to other user in C#.net
private System.Windows.Forms.OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.RestoreDirectory = true;
openFileDialog1.FileName = "";
openFileDialog1.Filter = "Graphic Interchange Format (*.gif)|*.gif|" +
"JPEG File Interchange Format (*.jpg;*.jpeg)|*.jpg;*.jpeg";
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
string filename = openFileDialog1.FileName.Substring(openFileDialog1.FileName.LastIndexOf("\\") + 1);
File.Copy(openFileDialog1.FileName, Application.StartupPath + "\\Temp\\" + filename, true);
string fname = Application.StartupPath + "\\Temp\\" + filename;
if(File.Exists(fname))
WhiteBoard1.iSelected = fname;FileInfo info = new FileInfo(WhiteBoard1.iSelected);
long filesize = info.Length;
if(filesize>0)
{WhiteBoard1.strConfid = strConfid;
WhiteBoard1.LoadImage();
}
}In whiteboard class
public void LoadImage()
{
try
{
Graphics grphs = CreateGraphics();if(File.Exists(iSelected))
{
Image img1 = Image.FromFile(iSelected);
pict.Image=img1;
}
}
catch(OutOfMemoryException)
{MessageBox.Show(msg.ToString());
}
}I get exception as OutofMemory Exception
-
i am trying to pick a image file from open dialog box and send to other user in C#.net
private System.Windows.Forms.OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.RestoreDirectory = true;
openFileDialog1.FileName = "";
openFileDialog1.Filter = "Graphic Interchange Format (*.gif)|*.gif|" +
"JPEG File Interchange Format (*.jpg;*.jpeg)|*.jpg;*.jpeg";
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
string filename = openFileDialog1.FileName.Substring(openFileDialog1.FileName.LastIndexOf("\\") + 1);
File.Copy(openFileDialog1.FileName, Application.StartupPath + "\\Temp\\" + filename, true);
string fname = Application.StartupPath + "\\Temp\\" + filename;
if(File.Exists(fname))
WhiteBoard1.iSelected = fname;FileInfo info = new FileInfo(WhiteBoard1.iSelected);
long filesize = info.Length;
if(filesize>0)
{WhiteBoard1.strConfid = strConfid;
WhiteBoard1.LoadImage();
}
}In whiteboard class
public void LoadImage()
{
try
{
Graphics grphs = CreateGraphics();if(File.Exists(iSelected))
{
Image img1 = Image.FromFile(iSelected);
pict.Image=img1;
}
}
catch(OutOfMemoryException)
{MessageBox.Show(msg.ToString());
}
}I get exception as OutofMemory Exception
How big is the file ?
asma_panjabi wrote:
string filename = openFileDialog1.FileName.Substring(openFileDialog1.FileName.LastIndexOf("\\") + 1);
getting file name ? Use
System.IO.Path.GetFileName()
All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia How to use google | Ask smart questions
-
How big is the file ?
asma_panjabi wrote:
string filename = openFileDialog1.FileName.Substring(openFileDialog1.FileName.LastIndexOf("\\") + 1);
getting file name ? Use
System.IO.Path.GetFileName()
All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia How to use google | Ask smart questions
It doesnt work for any size of file
-
i am trying to pick a image file from open dialog box and send to other user in C#.net
private System.Windows.Forms.OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.RestoreDirectory = true;
openFileDialog1.FileName = "";
openFileDialog1.Filter = "Graphic Interchange Format (*.gif)|*.gif|" +
"JPEG File Interchange Format (*.jpg;*.jpeg)|*.jpg;*.jpeg";
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
string filename = openFileDialog1.FileName.Substring(openFileDialog1.FileName.LastIndexOf("\\") + 1);
File.Copy(openFileDialog1.FileName, Application.StartupPath + "\\Temp\\" + filename, true);
string fname = Application.StartupPath + "\\Temp\\" + filename;
if(File.Exists(fname))
WhiteBoard1.iSelected = fname;FileInfo info = new FileInfo(WhiteBoard1.iSelected);
long filesize = info.Length;
if(filesize>0)
{WhiteBoard1.strConfid = strConfid;
WhiteBoard1.LoadImage();
}
}In whiteboard class
public void LoadImage()
{
try
{
Graphics grphs = CreateGraphics();if(File.Exists(iSelected))
{
Image img1 = Image.FromFile(iSelected);
pict.Image=img1;
}
}
catch(OutOfMemoryException)
{MessageBox.Show(msg.ToString());
}
}I get exception as OutofMemory Exception
sometimes it executes for .jpg but it never takes .gif file. Please some solution for it.
-
i am trying to pick a image file from open dialog box and send to other user in C#.net
private System.Windows.Forms.OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.RestoreDirectory = true;
openFileDialog1.FileName = "";
openFileDialog1.Filter = "Graphic Interchange Format (*.gif)|*.gif|" +
"JPEG File Interchange Format (*.jpg;*.jpeg)|*.jpg;*.jpeg";
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
string filename = openFileDialog1.FileName.Substring(openFileDialog1.FileName.LastIndexOf("\\") + 1);
File.Copy(openFileDialog1.FileName, Application.StartupPath + "\\Temp\\" + filename, true);
string fname = Application.StartupPath + "\\Temp\\" + filename;
if(File.Exists(fname))
WhiteBoard1.iSelected = fname;FileInfo info = new FileInfo(WhiteBoard1.iSelected);
long filesize = info.Length;
if(filesize>0)
{WhiteBoard1.strConfid = strConfid;
WhiteBoard1.LoadImage();
}
}In whiteboard class
public void LoadImage()
{
try
{
Graphics grphs = CreateGraphics();if(File.Exists(iSelected))
{
Image img1 = Image.FromFile(iSelected);
pict.Image=img1;
}
}
catch(OutOfMemoryException)
{MessageBox.Show(msg.ToString());
}
}I get exception as OutofMemory Exception
asma_panjabi wrote:
string filename = openFileDialog1.FileName.Substring(openFileDialog1.FileName.LastIndexOf("\\") + 1); File.Copy(openFileDialog1.FileName, Application.StartupPath + "\\Temp\\" + filename, true); string fname = Application.StartupPath + "\\Temp\\" + filename;
Whats all this part about? Why not just use the path that the OpenFileDialog gets? Also, why do you have a
Graphics grphs = CreateGraphics();
it doesn't get used in the code you posted and idealy you shouldn't be using it anyway. If you want to draw to your form you should do it in the OnPaint event. I mean, that Graphics object could be the thing causing your problems, try moving it out of the try block and see what happens.My current favourite word is: I'm starting to run out of fav. words!
-SK Genius
-
asma_panjabi wrote:
string filename = openFileDialog1.FileName.Substring(openFileDialog1.FileName.LastIndexOf("\\") + 1); File.Copy(openFileDialog1.FileName, Application.StartupPath + "\\Temp\\" + filename, true); string fname = Application.StartupPath + "\\Temp\\" + filename;
Whats all this part about? Why not just use the path that the OpenFileDialog gets? Also, why do you have a
Graphics grphs = CreateGraphics();
it doesn't get used in the code you posted and idealy you shouldn't be using it anyway. If you want to draw to your form you should do it in the OnPaint event. I mean, that Graphics object could be the thing causing your problems, try moving it out of the try block and see what happens.My current favourite word is: I'm starting to run out of fav. words!
-SK Genius
I need to send the image from one user to other so i have to copy the file to my drive. So
File.Copy(openFileDialog1.FileName, Application.StartupPath + "\\Temp\\" + filename, true);
string fname = Application.StartupPath + "\\Temp\\" + filename;I have removed Graphics grphs = CreateGraphics(); from try catch but no gain in that. Plz help
-
i am trying to pick a image file from open dialog box and send to other user in C#.net
private System.Windows.Forms.OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.RestoreDirectory = true;
openFileDialog1.FileName = "";
openFileDialog1.Filter = "Graphic Interchange Format (*.gif)|*.gif|" +
"JPEG File Interchange Format (*.jpg;*.jpeg)|*.jpg;*.jpeg";
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
string filename = openFileDialog1.FileName.Substring(openFileDialog1.FileName.LastIndexOf("\\") + 1);
File.Copy(openFileDialog1.FileName, Application.StartupPath + "\\Temp\\" + filename, true);
string fname = Application.StartupPath + "\\Temp\\" + filename;
if(File.Exists(fname))
WhiteBoard1.iSelected = fname;FileInfo info = new FileInfo(WhiteBoard1.iSelected);
long filesize = info.Length;
if(filesize>0)
{WhiteBoard1.strConfid = strConfid;
WhiteBoard1.LoadImage();
}
}In whiteboard class
public void LoadImage()
{
try
{
Graphics grphs = CreateGraphics();if(File.Exists(iSelected))
{
Image img1 = Image.FromFile(iSelected);
pict.Image=img1;
}
}
catch(OutOfMemoryException)
{MessageBox.Show(msg.ToString());
}
}I get exception as OutofMemory Exception
Please itz urgent