Skip to content

Instantly share code, notes, and snippets.

@palmerabollo
Created March 25, 2016 08:18
Show Gist options
  • Select an option

  • Save palmerabollo/14244c813b67464e9b71 to your computer and use it in GitHub Desktop.

Select an option

Save palmerabollo/14244c813b67464e9b71 to your computer and use it in GitHub Desktop.
YuvImage in Android
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