Skip to content

Instantly share code, notes, and snippets.

@rajat1saxena
Last active June 24, 2018 06:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rajat1saxena/d9bb40104a17a05f2bdce541bd791720 to your computer and use it in GitHub Desktop.
Save rajat1saxena/d9bb40104a17a05f2bdce541bd791720 to your computer and use it in GitHub Desktop.
// Get the image's Uri from shared intent etc.
val imageSelected: Uri = intent.getParcelableExtra(Intent.EXTRA_STREAM)
try {
// get the raw file data of the photo
val mInputPFD = contentResolver.openFileDescriptor(imageSelected, "r")
val mContentFileDescriptor = mInputPFD.fileDescriptor
val fIS = FileInputStream(mContentFileDescriptor)
val mGraphicBuffer = ByteArrayOutputStream()
val buf = ByteArray(1024)
while (true) {
val readNum = fIS.read(buf)
if (readNum == -1) break
mGraphicBuffer.write(buf, 0, readNum)
}
// Generate the checksum
mChecksum = generateChecksum(mGraphicBuffer)
} catch (e: Exception) {
e.printStackTrace()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment