Created
March 25, 2016 08:18
-
-
Save palmerabollo/14244c813b67464e9b71 to your computer and use it in GitHub Desktop.
YuvImage in Android
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public void uploadImage(byte[] data, int width, int height) { | |
| final Context context = contextWeakReference.get(); | |
| YuvImage yuvimage = new YuvImage(data, ImageFormat.NV21, width, height, null); | |
| try { | |
| final File outputFile = FileUtils.createExternalFile(Environment.DIRECTORY_DCIM, ".jpeg"); | |
| final BufferedOutputStream os = new BufferedOutputStream(new FileOutputStream(outputFile)); | |
| yuvimage.compressToJpeg(new Rect(0, 0, width, height), 90, os); // compress level = 90 | |
| TransferObserver observer = transferUtility.upload("mybucket", "myfile", outputFile); | |
| observer.setTransferListener(new TransferListener() { | |
| @Override | |
| public void onStateChanged(int id, TransferState state) { | |
| } | |
| @Override | |
| public void onProgressChanged(int id, long bytesCurrent, long bytesTotal) { | |
| } | |
| @Override | |
| public void onError(int id, Exception ex) { | |
| } | |
| }); | |
| } catch (final IOException e) { | |
| if (Constants.DEBUG) Log.e(TAG, "IOException", e); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment