Changeset View
Changeset View
Standalone View
Standalone View
src/org/kde/kdeconnect/Helpers/ImagesHelper.java
Show All 21 Lines | |||||
22 | 22 | | |||
23 | import android.graphics.Bitmap; | 23 | import android.graphics.Bitmap; | ||
24 | import android.graphics.Canvas; | 24 | import android.graphics.Canvas; | ||
25 | import android.graphics.drawable.BitmapDrawable; | 25 | import android.graphics.drawable.BitmapDrawable; | ||
26 | import android.graphics.drawable.Drawable; | 26 | import android.graphics.drawable.Drawable; | ||
27 | 27 | | |||
28 | public class ImagesHelper { | 28 | public class ImagesHelper { | ||
29 | 29 | | |||
30 | public static Bitmap drawableToBitmap (Drawable drawable) { | 30 | public static Bitmap drawableToBitmap(Drawable drawable) { | ||
31 | if (drawable instanceof BitmapDrawable) { | 31 | if (drawable instanceof BitmapDrawable) { | ||
32 | return ((BitmapDrawable)drawable).getBitmap(); | 32 | return ((BitmapDrawable) drawable).getBitmap(); | ||
33 | } | 33 | } | ||
34 | 34 | | |||
35 | Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888); | 35 | Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888); | ||
36 | Canvas canvas = new Canvas(bitmap); | 36 | Canvas canvas = new Canvas(bitmap); | ||
37 | drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight()); | 37 | drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight()); | ||
38 | drawable.draw(canvas); | 38 | drawable.draw(canvas); | ||
39 | 39 | | |||
40 | return bitmap; | 40 | return bitmap; | ||
41 | } | 41 | } | ||
42 | 42 | | |||
43 | } | 43 | } |