Go Down

Topic: Save photos of serial cam to hard disk (Read 2 times) previous topic - next topic

maveck

Yes Dhunt that's right, but I don't know the buffer size of the image and I don't know if I have to program an special line to the arduino to send the image data, because when I run java or the visual c (where I program the receive file software) it doesn't show anything, maybe the buffer is storing information that doesn't correspond to the picture

PaulS

Quote
maybe the buffer is storing information that doesn't correspond to the picture

No, but you are sending picture data and a bunch of other junk to the serial port. If you are writing all that stuff to one file, it is no wonder the file does not represent a picture.

maveck

Do you know how to remove that segment of serial data that I don't need to show a coherent image ?, I forgot to say something, when I open my C# 2010 program, the  media of the program only shows "empty file".

PaulS

Quote
when I open my C# 2010 program

You appear to have 3 or more distinct problems. First, you are sending a bunch of stuff from the Arduino that you shouldn't be sending. // will take care of that.

Second, you seem to have some C# code that is collecting the data into a file, that you have not shown us, that appears not to be working.

Third, you have some C# code that is trying to use that data to display an image. You haven't shown us that code, either.

You really can't expect us to help you fix code we haven't seen.

maveck

#9
Feb 16, 2012, 03:28 am Last Edit: Feb 16, 2012, 03:32 am by maveck Reason: 1
Ok, thank you for the response, here is the visual c# 2010 two button program that open the serial port (COM 2) and pretends "to show the image":

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Diagnostics;


namespace WindowsFormsApplication1
{
   public partial class Form1 : Form
   {
       public Form1()
       {
           InitializeComponent();
       }

       private void serialPort2_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
       {
           List<byte> recibido = new List<byte>(); //byte receive

           int bytes = serialPort2.BytesToRead;

           byte[] buffer = new byte[bytes];

           serialPort2.Read(buffer, 0, bytes);
           foreach (byte elem in buffer)
           {
               recibido.Add(elem); //here "it receives the file"
           }

       }

       private void button1_Click(object sender, EventArgs e)
       {
           List<byte> recibido = new List<byte>();
           serialPort2.Open();
           recibido.Clear();

       }

       private void button2_Click(object sender, EventArgs e) //with this button I pretend to show the image after the computer receive it.
       {
           List<byte> recibido = new List<byte>(); //list receive
           serialPort2.Close();

           //Guarda todo en archivo, here It suppose to save everything inside the archive
           if (File.Exists("Prueba.jpg"))
               File.Delete("Prueba.jpg");
           FileStream archivoP = new FileStream("Prueba.jpg",
               FileMode.OpenOrCreate, FileAccess.Write);
           BinaryWriter escribirP = new BinaryWriter(archivoP);
           foreach (byte elem in recibido)
           {
               escribirP.Write(elem);
           }
           escribirP.Close();
           archivoP.Close();
           Process.Start("Prueba.jpg");


       }
   }
}



But when open the Windows gallery, It says that is an empty file.

Go Up