Last active
December 25, 2017 14:07
-
-
Save motornyimaksym/5e5b1f87ae221f27d89a3b36750fbec4 to your computer and use it in GitHub Desktop.
change photo on the fly
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | |
package="com.example.app.myapplication"> | |
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> | |
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> | |
<application | |
android:name="com.example.app.App" | |
android:allowBackup="true" | |
android:icon="@mipmap/ic_launcher" | |
android:label="@string/app_name" | |
android:roundIcon="@mipmap/ic_launcher_round" | |
android:supportsRtl="true" | |
android:theme="@style/AppTheme"> | |
<activity android:name="com.example.app.view.main.MainActivity"> | |
<intent-filter> | |
<action android:name="android.intent.action.MAIN"/> | |
<category android:name="android.intent.category.LAUNCHER"/> | |
</intent-filter> | |
</activity> | |
<service android:name="com.example.app.PhotoService" /> | |
<receiver | |
android:name="com.example.app.CameraReceiver" | |
android:enabled="true" > | |
<intent-filter> | |
<action android:name="com.android.camera.NEW_PICTURE" /> | |
<action android:name="android.hardware.action.NEW_PICTURE" /> | |
<category android:name="android.intent.category.DEFAULT" /> | |
<data android:mimeType="image/*" /> | |
</intent-filter> | |
</receiver> | |
</application> | |
</manifest> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CameraReceiver : BroadcastReceiver() { | |
override fun onReceive(context: Context, intent: Intent) { | |
Log.i("INFO", "Enter BroadcastReceiver") | |
val cursor = context.contentResolver.query(intent.data, null, null, null, null) | |
cursor.moveToFirst() | |
val photoPath = cursor.getString(cursor.getColumnIndex("_data")) | |
var bmp = BitmapFactory.decodeFile(photoPath) | |
val matrix = Matrix() | |
matrix.postRotate(90F) | |
bmp = Bitmap.createBitmap(bmp, 0, 0, bmp.width, bmp.height, matrix, true) | |
val fOut: FileOutputStream | |
try { | |
fOut = FileOutputStream(photoPath) | |
bmp.compress(Bitmap.CompressFormat.JPEG, 85, fOut) | |
fOut.flush() | |
fOut.close() | |
} catch (e: Exception) { | |
e.printStackTrace() | |
} finally { | |
cursor.close() | |
Toast.makeText(context, "Rotated Photo is Saved as : " + photoPath, Toast.LENGTH_LONG).show() | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment