Author Topic: bit map does not appear after save.  (Read 2099 times)

0 Members and 1 Guest are viewing this topic.

BillZndl

  • Guest
bit map does not appear after save.
« on: April 08, 2015, 09:45:14 AM »
Hi,
When I ran this code on my machine (using a button click),
it works perfectly. Produced the bitmap and sent it to the printer on a share.

When we net load it on another machine here,
it goes to the catch block, shows no error (using innerException) and no bitmap found in the C: drive.

Anything I should look for?

Code - C#: [Select]
  1. try
  2.             {
  3.                 Rectangle bounds = this.Bounds;
  4.  
  5.                 using (Bitmap bmp = new Bitmap(bounds.Width, bounds.Height))
  6.                 {
  7.                     using (Graphics g = Graphics.FromImage(bmp))
  8.                     {
  9.                         g.CopyFromScreen(new Point(bounds.Left, bounds.Top), Point.Empty, bounds.Size);
  10.                     }
  11.  
  12.                     bmp.Save("C://test.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);                    
  13.                 }
  14.  
  15.                 File.Copy("C:\\test.jpg", @"\\bcnymprtp01\NYM_Proto_Copier_Color", true);
  16.  
  17.                 label28.Text = "Image sent to Printer:";
  18.                 label28.Refresh();
  19.             }
  20.             catch (System.Exception ex)
  21.             {
  22.                 label28.Text = "Print screen Failed:";
  23.                 label28.Refresh();
  24.  
  25.                 MessageBox.Show("\nCan't print to screen ---> " + ex.StackTrace);
  26.             }
  27.             finally
  28.             {
  29.                 System.Threading.Thread.Sleep(2000);
  30.                 label28.Text = "";                
  31.             }
  32.  

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: bit map does not appear after save.
« Reply #1 on: April 08, 2015, 10:03:27 AM »
I've seen issues like this when writing files to the root directory of the C: drive.

Jeff H

  • Needs a day job
  • Posts: 6150
Re: bit map does not appear after save.
« Reply #2 on: April 08, 2015, 11:05:50 AM »
I've seen issues like this when writing files to the root directory of the C: drive.
Same here,
Add catches below before Systems.Exception ex
Code - C#: [Select]
  1.                     catch (IOException ex)
  2.                     {
  3.                         label28.Text = ex.Message;
  4.                     }
  5.                     catch (SecurityException se)
  6.                     {
  7.                         label28.Text = se.Message;
  8.                     }
  9.  

Think its security exception accessing C:\ as Jeff mentioned 

BillZndl

  • Guest
Re: bit map does not appear after save.
« Reply #3 on: April 08, 2015, 03:10:28 PM »
Thanks!

Never would've thought writing to the C: drive would cause that to happen.

I'll save the file to the network with a name that contains the users loginname, to prevent the minute possibility of 2 persons colliding.

I couldn't duplicate the error with the security exception on my machine.

And we haven't tested the new code on the other machines but that will come up with normal use in the next day or two.