Comments (4)
This issue is stale because it has been open 20 days with no activity. Remove stale label or comment or this will be closed in 4 days.
from photoeditor.
I was facing same error then it was solved by code below
create new class and paste this code,
import android.content.Context
import android.graphics.Bitmap
import android.graphics.BitmapFactory
import android.graphics.Matrix
import android.media.ExifInterface
import android.net.Uri
import android.os.Build
import java.io.IOException
@Throws(IOException::class)
public fun hanleImageRotation(context: Context, selectedImage: Uri?): Bitmap? {
val MAX_HEIGHT = 1024
val MAX_WIDTH = 1024
val options = BitmapFactory.Options()
options.inJustDecodeBounds = true
var imageStream = context.contentResolver.openInputStream(selectedImage!!)
BitmapFactory.decodeStream(imageStream, null, options)
imageStream!!.close()
options.inSampleSize = calculateInSampleSize(options, MAX_WIDTH, MAX_HEIGHT)
options.inJustDecodeBounds = false
imageStream = context.contentResolver.openInputStream(selectedImage)
var img = BitmapFactory.decodeStream(imageStream, null, options)
img = rotateImageIfRequired(context, img!!, selectedImage)
return img
}
private fun calculateInSampleSize(
options: BitmapFactory.Options,
reqWidth: Int, reqHeight: Int
): Int {
val height = options.outHeight
val width = options.outWidth
var inSampleSize = 1
if (height > reqHeight || width > reqWidth) {
val heightRatio = Math.round(height.toFloat() / reqHeight.toFloat())
val widthRatio = Math.round(width.toFloat() / reqWidth.toFloat())
inSampleSize = if (heightRatio < widthRatio) heightRatio else widthRatio
val totalPixels = (width * height).toFloat()
val totalReqPixelsCap = (reqWidth * reqHeight * 2).toFloat()
while (totalPixels / (inSampleSize * inSampleSize) > totalReqPixelsCap) {
inSampleSize++
}
}
return inSampleSize
}
@Throws(IOException::class)
private fun rotateImageIfRequired(context: Context, img: Bitmap, selectedImage: Uri): Bitmap? {
val input = context.contentResolver.openInputStream(selectedImage)!!
val ei: ExifInterface
if (Build.VERSION.SDK_INT > 23) ei = ExifInterface(input) else ei = ExifInterface(selectedImage.path!!)
val orientation: Int = ei.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL)
return when (orientation) {
ExifInterface.ORIENTATION_ROTATE_90 -> rotateImage(img, 90)
ExifInterface.ORIENTATION_ROTATE_180 -> rotateImage(img, 180)
ExifInterface.ORIENTATION_ROTATE_270 -> rotateImage(img, 270)
else -> img
}
}
private fun rotateImage(img: Bitmap, degree: Int): Bitmap? {
val matrix = Matrix()
matrix.postRotate(degree.toFloat())
val rotatedImg = Bitmap.createBitmap(img, 0, 0, img.width, img.height, matrix, true)
img.recycle()
return rotatedImg
}
And in EditImageActivity change this with onActivityResult()
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (resultCode == RESULT_OK) {
when (requestCode) {
CAMERA_REQUEST -> {
mPhotoEditor.clearAllViews()
val photo = data?.extras?.get("data") as Bitmap?
mPhotoEditorView.source.setImageBitmap(photo)
}
PICK_REQUEST -> try {
mPhotoEditor.clearAllViews()
val uri = data?.data
val bitmap = MediaStore.Images.Media.getBitmap(
contentResolver, uri
)
mPhotoEditorView.source.setImageBitmap(hanleImageRotation(this, uri))
} catch (e: IOException) {
e.printStackTrace()
}
}
}
}
from photoeditor.
This issue is stale because it has been open 20 days with no activity. Remove stale label or comment or this will be closed in 4 days.
from photoeditor.
This issue was closed because it has been stalled for 5 days with no activity.
from photoeditor.
Related Issues (20)
- Make ViewState public, and return back the final Bitmap after saveAsFile HOT 9
- How to scale source image to fit the space HOT 6
- After save image, the width and height of new saved image was shrink, not like original image size. HOT 2
- After Applying Filter (save image showing black) HOT 2
- Ability to make collage HOT 3
- Android 10 saveAsFile failed to save File cause by open failed: EACCES (Permission denied) HOT 6
- Trying to draw too large bitmap HOT 2
- mPhotoEditor.addImage(bitmap) is not resovled or found in the latest version HOT 2
- Share to PhotoEditor HOT 2
- Open app on blank slate HOT 2
- Adjustable/customizable filters HOT 2
- Edit and resize shape HOT 2
- Initial set image is appearing smaller than the original size HOT 1
- help for install HOT 2
- Can I Apply Colors On Photo Editor View HOT 3
- How to know that undo and redo option is available HOT 3
- Add Button-Controlled Image Rotation Feature HOT 5
- make a list of layers HOT 3
- Is there a way to save the modifications made to an image, but not the result image itself? HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from photoeditor.