Results 1 to 4 of 4

Thread: 0 Byte when saving the image[resolved]

  1. #1

    Thread Starter
    Hyperactive Member fret's Avatar
    Join Date
    Sep 2004
    Posts
    472

    Arrow 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.

  2. #2

    Thread Starter
    Hyperactive Member fret's Avatar
    Join Date
    Sep 2004
    Posts
    472

    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?

  3. #3
    Fanatic Member
    Join Date
    Jan 2005
    Location
    Cebu
    Posts
    607

    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);
    		}

  4. #4

    Thread Starter
    Hyperactive Member fret's Avatar
    Join Date
    Sep 2004
    Posts
    472

    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
  •  



Click Here to Expand Forum to Full Width