|
-
Feb 28th, 2006, 08:24 PM
#1
Thread Starter
Hyperactive Member
0 Byte when saving the image[resolved]
Hi guys,
I have here an already exists code that read an image file from the database which saved into a binary(I think) I'm not familiar with it, now when I try to read the file and put in the picturebox, it shows the image perfectly, now when I try to save it to something like..."C:\blah blah..." it gives a 0 byte which gives a no image at all, now I'm having problem where to trace it since this is not my code.
Here's some code:
Reading from the database
Code:
while (dreader.Read())
{
Photo =(byte[])dreader["pb1"];
Stream myStream = new MemoryStream(Photo, true);
index = int.Parse(dreader["flag"].ToString());
myStream.Write(Photo, 0, Photo.Length);
pb[index].Image = new Bitmap(myStream);
myStream.Close();
}
dreader.Close();
Save and Preview the image
Code:
private void b1_Click(object sender, System.EventArgs e)
{
string flpath = "C:\\Temp\\pct.bmp";
int pcounter = 0;
Rectangle rect=new Rectangle();
rect = Screen.GetWorkingArea(this);
try
{
for ( int counter = 0;counter<p.Length; counter++)
{
pcounter = counter;
if (sender.Equals(p[counter]))
break;
}
filename.Text = flpath;
pb[pcounter].Image.Save(flpath);
System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo(flpath);
psi.Verb = "Print";
System.Diagnostics.Process.Start(psi);
}
catch (Exception ex)
{
MessageBox.Show("Cannot Show an empty Frame.","Warning",
MessageBoxButtons.OK,MessageBoxIcon.Warning);
}
}
Last edited by fret; Mar 2nd, 2006 at 04:21 AM.
-
Feb 28th, 2006, 10:27 PM
#2
Thread Starter
Hyperactive Member
Re: 0 Byte when saving the image
Ok, I have to twist the situation, is there anyone guide me on how to save binary files into image("jpg/bmp") files?
-
Mar 2nd, 2006, 12:30 AM
#3
Fanatic Member
Re: 0 Byte when saving the image
Could be
Code:
public static Image ToImage(byte[] byteArray)
{
MemoryStream ms = new MemoryStream(byteArray, 0, byteArray.Length);
ms.Write(byteArray, 0, byteArray.Length);
return Image.FromStream(ms, true);
}
-
Mar 2nd, 2006, 04:20 AM
#4
Thread Starter
Hyperactive Member
Re: 0 Byte when saving the image
Ok, I got it.
Code:
Bitmap bm = new Bitmap(pb[pcounter].Image);
bm.Save(flpath);
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|