Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Open Source License 

import java.io.ByteArrayOutputStream;

import android.graphics.Bitmap;
import android.graphics.Bitmap.CompressFormat;

public class Main {
    /**
     * Converts and Android bitmap file to an array of raw bytes that are ready to be sent over bluetooth,
     * wifi, usb, etc.
     * 
     * @param bitmap The bitmap to translate
     * @param format The format of the bitmap
     * @return The raw byte representation of the bitmap
     */
    public static byte[] bitmapToRawBytes(Bitmap bitmap, CompressFormat format) {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        bitmap.compress(format, 100, baos);
        byte[] result = baos.toByteArray();
        return result;
    }
}