Skip to content

Commit

Permalink
[+]Init Readme
Browse files Browse the repository at this point in the history
  • Loading branch information
hi-manshu committed Jul 29, 2019
1 parent 029c445 commit cde8ca1
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 22 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
### Screenshot - Take Screenshot Programmatically
3 changes: 1 addition & 2 deletions app/src/main/java/com/mindorks/sample/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ class MainActivity : AppCompatActivity() {

Screenshot.with(this)
.setView(view)
.setQuality(Quality.AVERAGE)
.setRotation(Rotate.DEGREE_180)
.setQuality(Quality.HIGH)
.setFlip(Flip.HORIZONTALLY)
.getScreenshot()
)
Expand Down
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/ic_android_black_24dp.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#33cccc"
android:pathData="M6,18c0,0.55 0.45,1 1,1h1v3.5c0,0.83 0.67,1.5 1.5,1.5s1.5,-0.67 1.5,-1.5L11,19h2v3.5c0,0.83 0.67,1.5 1.5,1.5s1.5,-0.67 1.5,-1.5L16,19h1c0.55,0 1,-0.45 1,-1L18,8L6,8v10zM3.5,8C2.67,8 2,8.67 2,9.5v7c0,0.83 0.67,1.5 1.5,1.5S5,17.33 5,16.5v-7C5,8.67 4.33,8 3.5,8zM20.5,8c-0.83,0 -1.5,0.67 -1.5,1.5v7c0,0.83 0.67,1.5 1.5,1.5s1.5,-0.67 1.5,-1.5v-7c0,-0.83 -0.67,-1.5 -1.5,-1.5zM15.53,2.16l1.3,-1.3c0.2,-0.2 0.2,-0.51 0,-0.71 -0.2,-0.2 -0.51,-0.2 -0.71,0l-1.48,1.48C13.85,1.23 12.95,1 12,1c-0.96,0 -1.86,0.23 -2.66,0.63L7.85,0.15c-0.2,-0.2 -0.51,-0.2 -0.71,0 -0.2,0.2 -0.2,0.51 0,0.71l1.31,1.31C6.97,3.26 6,5.01 6,7h12c0,-1.99 -0.97,-3.75 -2.47,-4.84zM10,5L9,5L9,4h1v1zM15,5h-1L14,4h1v1z"/>
</vector>
16 changes: 8 additions & 8 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" android:layout_marginTop="32dp" android:layout_marginBottom="8dp"
app:layout_constraintBottom_toTopOf="@+id/view"/>
<FrameLayout android:layout_width="match_parent"
android:id="@+id/view"
android:background="#3c3c3c"
android:layout_height="200dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent">
<ImageView android:layout_width="match_parent"
android:id="@+id/view"
android:src="@drawable/ic_android_black_24dp"
android:layout_height="200dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent">

</FrameLayout>
</ImageView>
</androidx.constraintlayout.widget.ConstraintLayout>
20 changes: 8 additions & 12 deletions library/src/main/java/com/mindorks/utils/BitmapUtils.kt
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package com.mindorks.utils

import android.graphics.Bitmap
import android.graphics.BitmapFactory
import android.graphics.Canvas
import android.graphics.Matrix
import android.graphics.*
import android.view.View
import com.mindorks.properties.Flip
import com.mindorks.properties.Quality
import com.mindorks.properties.Rotate
import java.io.ByteArrayOutputStream
import java.io.OutputStream

/**
* @BitmpaUtils have all the bitmap properties and operations
Expand Down Expand Up @@ -53,18 +51,16 @@ object BitmapUtils {
* @param flip
*/
fun getScreenshot(view: View, rotate: Rotate, quality: Quality, flip: Flip): Bitmap {

val stream = ByteArrayOutputStream()
val returnedBitmap = Bitmap.createBitmap(view.width, view.height, Bitmap.Config.ARGB_8888)
val canvas = Canvas(returnedBitmap)
view.background.also {
it.draw(canvas)
}
view.run {
draw(canvas)
}

val bgDrawable = view.background
if (bgDrawable != null) bgDrawable.draw(canvas)
else canvas.drawColor(Color.WHITE)
view.draw(canvas)
returnedBitmap.run {
compress(Bitmap.CompressFormat.JPEG, quality.quality, stream)
compress(Bitmap.CompressFormat.JPEG, quality.quality, stream as OutputStream?)
}
val byteArray = stream.toByteArray()
val bitmapAfterFlip = flip(BitmapFactory.decodeByteArray(byteArray, 0, byteArray.size), flip)
Expand Down

0 comments on commit cde8ca1

Please sign in to comment.