CLR: .Net / Mono / Boo / Otros CLR > C#

 Problemas con metodo Save Imagenes.

(1/1)

Painkiller:
Que tal, pues he estado haciendo una aplicaci÷on que imprime la pantalla y la guarda como imagen png, el problema es que recientemente me empezo a dar problemas debido a que no guarda la extension especificada:

--- Código: C# ---public static byte[] takeScreenShot(){   // Set the bitmap object to the size of the screen   bmpScreenShot = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, PixelFormat.Format32bppArgb);   // Create a graphics object from the bitmap   gfxScreenShot = Graphics.FromImage(bmpScreenShot);  // Take the screenshot from the upper left corner to the right bottom corner  gfxScreenShot.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y, 0, 0, Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy);  // Save the screenshot to the specified path that the user has chosen  bmpScreenShot.Save("Imagen" + index.ToString(), System.Drawing.Imaging.ImageFormat.Png);  byte[] size = getFileSize("Imagen" + index.ToString() + ".png") ;  byte[] name = System.Text.ASCIIEncoding.ASCII.GetBytes("|Imagen" + index.ToString() + ".png");  index++;  bmpScreenShot.Dispose();  gfxScreenShot.Dispose();  return joinByteArray(size, name);} Como dije la aplicación no arroja excepción alguna, pero al momento de mandar llamar a la funcion getFileSize arroja la excepción FileNotFoundException, algo que he notado es que esto siempre pasa en la tercera llamada a esta función, es decir el directorio se ve asi:
.
..
CapturaPantalla.exe
Imagen0.png
Imagen1.png
Imagen2
Imagen3

y asi sucesivamente, despues de ese punto, no importa cuantas veces se llame ya no agrega la extension, mas sin embargo los datos están ahi, ya que al agregarse la extension en el nombre se ve perfectamente. ¿Alguien sabe por que puede pasar esto?

Jeysscarr:
Porque no pruebas con esto...
Lo hice con mi form... creo que para capturar toda la pantalla es aun mas sencillo si usas Screen.primaryScreen.Bounds

Obviamente deberas validar si ya existe un archivo llamado igual y todas esas cosas pero pienso que es mas sencillo este codigo


--- Código: C# ---  //variable global int cont = 0;         void GuardarPantalla()        {            Graphics gr = this.CreateGraphics();            SizeF Tamaño = this.Size;            Bitmap bm = new Bitmap((int)Tamaño.Width, (int)Tamaño.Height);            Graphics gr2 = Graphics.FromImage(bm);            gr2.CopyFromScreen((int)this.Location.X, (int)this.Location.Y, 0, 0, Tamaño.ToSize());            bm.Save("Imagen"+ cont +".Png", System.Drawing.Imaging.ImageFormat.Png);            cont++;        }         private void button2_Click(object sender, EventArgs e)        {            GuardarPantalla();        }  

Navegación

[0] Índice de Mensajes

Ir a la versión completa