Note that there are some explanatory texts on larger screens.

plurals
  1. POTrouble in retrieving the JPEG image from inputstream socket in Android
    primarykey
    data
    text
    <p>I want to retrieve the JPEG image from a inputstream socket in Android. Can I actually use Bitmap method and straight away convert input stream to JPG or should I convert the inputstream to byte array and then convert it to a JPG?</p> <p>The code that I'm actually trying is:</p> <pre><code> private final BluetoothSocket mmBTSocket; private final InputStream mmBTInStream; private final OutputStream mmBTOutStream; public ConnectedThread(BluetoothSocket socket) { Log.d(BTTAG, "create ConnectedThread"); mmBTSocket = socket; InputStream tmpIn = null; OutputStream tmpOut = null; // Get the BluetoothSocket input and output streams try { tmpIn = socket.getInputStream(); tmpOut = socket.getOutputStream(); } catch (IOException e) { Log.e(BTTAG, "temp sockets not created", e); } mmBTInStream = tmpIn; mmBTOutStream = tmpOut; } public void run() { Log.i(BTTAG, "BEGIN mBTConnectedThread"); byte[] inBTBuffer = new byte[1024]; boolean BTFileEndOne = false; byte[] mBTimageBuffer = new byte[15360]; // 15KB reserved int bytes; bytes = mmBTInStream.read(inBTBuffer); for (int i = 0; i &lt; bytes; i++) { mBTimageBuffer[mBTfileIndex] = inBTBuffer[i]; mBTfileIndex++; // start = System.currentTimeMillis(); // Log.i(BTTAG, bytes+"="+String.format("%02X", // inBTBuffer[i])); if (i &gt; 0) { if (inBTBuffer[i] == (byte) 0xD9) { BTFileEndOne = true; Log.i(BTTAG, "BTFileEndOne = true"); if (inBTBuffer[i - 1] == (byte) 0xFF) { //if (SaveImagetoSD() == true) { //byte[] readBuf = (byte[]) msg.obj; Bitmap bitmap = BitmapFactory.decodeStream(mmBTInStream); bitmap.compress(CompressFormat.JPEG, 80, mmBTOutStream); String writeTo = new File(Environment.getExternalStorageDirectory()+ File.separator + "motoduino.jpg") .toString(); FileOutputStream output = null; try { output = new FileOutputStream(writeTo); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); }` </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload