App API Documentation - Gachon-Graduation-work/Muzzle_Detection_Project GitHub Wiki

Function

private void openGallery()

function for when user press Gallery button on our App to select image from Gallery of Phone.

  • parameter: None
  • return: None
  • result: Creates intent to move to Gallery

private void takePhoto()

function for when user press Camera button on our App to take picture.

  • parameter: None
  • return: None
  • result: Creates intent to run Camera and create Image file to save picture user takes.

private File createImageFile()

Make file to use image in our App. it will provide place to save picture we take and get from Server.

  • parameter: None
  • return: saved Image

Networking

connect and get image

public void run() {
try {
    socket = new Socket(SERVER_IP, 8080);
    try {
        dis = new DataInputStream(socket.getInputStream());
        dos = new DataOutputStream(socket.getOutputStream());
        bos = new ByteArrayOutputStream();
        } catch (IOException e) {
            e.printStackTrace();
        }

change image to byte and send to Server

try {
    img.compress(Bitmap.CompressFormat.JPEG, 100, bos);
    bos.flush();
    byte[] array = bos.toByteArray();
    dos.writeInt(array.length);
    dos.write(array);
    dos.flush();

get result image from Server and save it as complete_picture.jpg'

dis = new DataInputStream(socket.getInputStream());
File f = new File(getFilesDir(), "complete_picture.jpg");
FileOutputStream output = new FileOutputStream(f);
bos2 = new BufferedOutputStream(output);

int readdata = 0;
byte[] buf = new byte[1024];

while((readdata = dis.read(buf)) != -1) {
    bos2.write(buf, 0, readdata);
    bos2.flush();
}

mHandler.post(showUpdate);