I took a picture using the camera app and when I stored it using a Bitmap this is what it looks like:
Why is the image so blurry? Is there another way to capture the image without distorting the quality?
Edit: Code for how the image is being captured and previewed
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (requestCode == CAMERA_REQUEST_CODE) {
val foodBitmap = Objects.requireNonNull(Objects.requireNonNull(data)!!.extras)!!["data"] as Bitmap
food_image.setImageBitmap(foodBitmap)
}
}
Related
I want to crop selected image from gallery to square image. I have button select_photo and image_view that displays photo. When user click on button it opens user gallery. I have tried several options that I have found on the web.
This is my code that create Intent and open gallery.
private fun choosePhotoFromGallary() {
val galleryIntent = Intent(Intent.ACTION_PICK)
galleryIntent.apply {
type = "image/*"
putExtra("crop", "true")
putExtra("outputX", 250)
putExtra("outputY", 250)
putExtra("scale", true)
putExtra("aspectX", 1)
putExtra("aspectY", 1)
putExtra("return-data", true)
}
startActivityForResult(galleryIntent, GALLERY_REQUEST_CODE)
}
I use onActivityResult() to get my data back from the Intent.
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (requestCode == GALLERY_REQUEST_CODE) {
if(resultCode == Activity.RESULT_OK) {
photoImageView.setImageURI(data?.data)
}
}
}
But i have no "cropping menu" available. So chosen photo is unchanged. I want it to be square so i need cropping.
How can i launch "cropping menu" so user can crop the image?
I am using intents to launch the camera app on Android. The problem is on Samsung Note 9 I am seeing that the preview images is rotated upside down. However the bitmap obtained in onActivityResult is fine.
I want to fix the preview image screen using the Intent approach.
private fun dispatchTakePictureIntent() {
Intent(MediaStore.ACTION_IMAGE_CAPTURE).also { takePictureIntent ->
takePictureIntent.resolveActivity(packageManager)?.also {
startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE)
}
}
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) {
val imageBitmap = data?.extras?.get("data") as Bitmap
ivTest.setImageBitmap(imageBitmap)
}
}
Sorry, but you have no means of controlling the preview behavior of a third-party camera app.
I have a problem using Glide load image android.I will present it simply as follows:
First I load image using glide
I want to choose image using Intent.ACTION_PICK but when I using image.setImageBitmap on onActivityResult but it not working
Glide.with(context!!).load(url).centerCrop().error(R.drawable.avata_boy).into(imgAvata)
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (requestCode == PICK_IMAGE_REQUEST && resultCode == Activity.RESULT_OK
&& data != null && data.data != null
) {
filePath = data.data
try {
val bitmap = BitmapFactory.decodeStream(activity!!.contentResolver.openInputStream(filePath!!))
imgAvata.setImageBitmap(bitmap)
Glide.with(context!!)
.load(bitmap)
.placeholder(R.drawable.avata_boy)
.diskCacheStrategy(DiskCacheStrategy.NONE)
.skipMemoryCache(true)
.into(imgAvata)
} catch (e: IOException) {
}
Try this!!
val myBitmap = BitmapFactory.decodeFile(filePath!!.getAbsolutePath())
imgview.setImageBitmap(myBitmap)
I'm want to do something like whatsapp, when user capture an image or select an image from gallery, they can edit the image/ draw something on the image.
Any help will be appreciated.
There are so many libraries for that.
Just try this Whatsapp like photo editor
Checkout the sample and library
ImageEditor.Builder(this, imagePath)
.setStickerAssets("stickers")
.disable(ImageEditor.EDITOR_TEXT) //to disable something
.open()
You will get the result in onActivityResult
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
when (requestCode) {
ImageEditor.RC_IMAGE_EDITOR ->
if (resultCode == Activity.RESULT_OK && data != null) {
val imagePath: String = data.getStringExtra(ImageEditor.EXTRA_EDITED_PATH)
edited_image.setImageBitmap(BitmapFactory.decodeFile(imagePath))
}
}
}
I started screen capture intent according to MediaProjectionManager:
var intent = mediaProjectionManager.createScreenCaptureIntent()
startActivityForResult(intent, 0)
... but I have no idea how to stop screen capture. Sample projects for API 21 are still not available.
ok, found solution, firstly save result to MediaProjection instance:
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent) {
super<Activity>.onActivityResult(requestCode, resultCode, data)
if (resultCode == Activity.RESULT_OK) {
mediaProjection = mediaProjectionManager.getMediaProjection(resultCode, data)
}
}
and to stop simply execute:
mediaProjection.stop()