|
|
@ -27,10 +27,13 @@ class PicturePreviewActivity : AppCompatActivity() { |
|
|
|
override fun onCreate(savedInstanceState: Bundle?) { |
|
|
|
override fun onCreate(savedInstanceState: Bundle?) { |
|
|
|
super.onCreate(savedInstanceState) |
|
|
|
super.onCreate(savedInstanceState) |
|
|
|
setContentView(R.layout.activity_picture_preview) |
|
|
|
setContentView(R.layout.activity_picture_preview) |
|
|
|
val result = pictureResult ?: run { |
|
|
|
|
|
|
|
|
|
|
|
if (pictureResult == null || (pictureResult?.data?.size ?: 0) <= 0) { |
|
|
|
finish() |
|
|
|
finish() |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
val result = requireNotNull(pictureResult) |
|
|
|
|
|
|
|
|
|
|
|
val imageView = findViewById<ImageView>(R.id.image) |
|
|
|
val imageView = findViewById<ImageView>(R.id.image) |
|
|
|
val captureResolution = findViewById<MessageView>(R.id.nativeCaptureResolution) |
|
|
|
val captureResolution = findViewById<MessageView>(R.id.nativeCaptureResolution) |
|
|
|
val captureLatency = findViewById<MessageView>(R.id.captureLatency) |
|
|
|
val captureLatency = findViewById<MessageView>(R.id.captureLatency) |
|
|
@ -46,13 +49,13 @@ class PicturePreviewActivity : AppCompatActivity() { |
|
|
|
result.toBitmap(1000, 1000) { bitmap -> imageView.setImageBitmap(bitmap) } |
|
|
|
result.toBitmap(1000, 1000) { bitmap -> imageView.setImageBitmap(bitmap) } |
|
|
|
} catch (e: UnsupportedOperationException) { |
|
|
|
} catch (e: UnsupportedOperationException) { |
|
|
|
imageView.setImageDrawable(ColorDrawable(Color.GREEN)) |
|
|
|
imageView.setImageDrawable(ColorDrawable(Color.GREEN)) |
|
|
|
Toast.makeText(this, "Can't preview this format: " + result.getFormat(), Toast.LENGTH_LONG).show() |
|
|
|
Toast.makeText(this, "Can't preview this format: " + result.format, Toast.LENGTH_LONG).show() |
|
|
|
} |
|
|
|
} |
|
|
|
if (result.isSnapshot) { |
|
|
|
if (result.isSnapshot) { |
|
|
|
// Log the real size for debugging reason. |
|
|
|
// Log the real size for debugging reason. |
|
|
|
val options = BitmapFactory.Options() |
|
|
|
val options = BitmapFactory.Options() |
|
|
|
options.inJustDecodeBounds = true |
|
|
|
options.inJustDecodeBounds = true |
|
|
|
BitmapFactory.decodeByteArray(result.data, 0, result.data.size, options) |
|
|
|
BitmapFactory.decodeByteArray(result.data, 0, requireNotNull(result.data).size, options) |
|
|
|
if (result.rotation % 180 != 0) { |
|
|
|
if (result.rotation % 180 != 0) { |
|
|
|
Log.e("PicturePreview", "The picture full size is ${result.size.height}x${result.size.width}") |
|
|
|
Log.e("PicturePreview", "The picture full size is ${result.size.height}x${result.size.width}") |
|
|
|
} else { |
|
|
|
} else { |
|
|
@ -76,13 +79,13 @@ class PicturePreviewActivity : AppCompatActivity() { |
|
|
|
override fun onOptionsItemSelected(item: MenuItem): Boolean { |
|
|
|
override fun onOptionsItemSelected(item: MenuItem): Boolean { |
|
|
|
if (item.itemId == R.id.share) { |
|
|
|
if (item.itemId == R.id.share) { |
|
|
|
Toast.makeText(this, "Sharing...", Toast.LENGTH_SHORT).show() |
|
|
|
Toast.makeText(this, "Sharing...", Toast.LENGTH_SHORT).show() |
|
|
|
val extension = when (pictureResult!!.format) { |
|
|
|
val extension = when (requireNotNull(pictureResult).format) { |
|
|
|
PictureFormat.JPEG -> "jpg" |
|
|
|
PictureFormat.JPEG -> "jpg" |
|
|
|
PictureFormat.DNG -> "dng" |
|
|
|
PictureFormat.DNG -> "dng" |
|
|
|
else -> throw RuntimeException("Unknown format.") |
|
|
|
else -> throw RuntimeException("Unknown format.") |
|
|
|
} |
|
|
|
} |
|
|
|
val file = File(filesDir, "picture.$extension") |
|
|
|
val destFile = File(filesDir, "picture.$extension") |
|
|
|
CameraUtils.writeToFile(pictureResult!!.data, file) { file -> |
|
|
|
CameraUtils.writeToFile(requireNotNull(pictureResult?.data), destFile) { file -> |
|
|
|
if (file != null) { |
|
|
|
if (file != null) { |
|
|
|
val context = this@PicturePreviewActivity |
|
|
|
val context = this@PicturePreviewActivity |
|
|
|
val intent = Intent(Intent.ACTION_SEND) |
|
|
|
val intent = Intent(Intent.ACTION_SEND) |
|
|
|