drawable

Get the displayed size of an image inside an ImageView

99封情书 提交于 2019-11-27 07:53:49
The code is simple: <ImageView android:layout_width="fill_parent" android:layout_height="fill_parent" android:src="@drawable/cat"/> Notice the ImageView used fill_parent for width and height. The image cat is a small image and it will be zoomed in to fit the ImageView, and keep the width/height ratio at the same time. My question is how to get the displayed size of the image? I tried: imageView.getDrawable().getIntrinsicHeight() But which it the original height of the image cat . I tried: imageView.getDrawable().getBounds() But which returns Rect(0,0,0,0) . fsegaux the following will work: ih

BitmapDrawable deprecated alternative

北慕城南 提交于 2019-11-27 07:02:07
I have the following code that will rotate a drawable by a set amount of degrees. public Drawable rotateDrawable(float angle, Context context) { Bitmap arrowBitmap = BitmapFactory.decodeResource(context.getResources(), R.drawable.generic2rb); // Create blank bitmap of equal size Bitmap canvasBitmap = arrowBitmap.copy(Bitmap.Config.ARGB_8888, true); canvasBitmap.eraseColor(0x00000000); // Create canvas Canvas canvas = new Canvas(canvasBitmap); // Create rotation matrix Matrix rotateMatrix = new Matrix(); rotateMatrix.setRotate(angle, canvas.getWidth()/2, canvas.getHeight()/2); //Draw bitmap

Changing gradient background colors on Android at runtime

拟墨画扇 提交于 2019-11-27 06:55:22
I'm experimenting with Drawable backgrounds and have had no problems so far. I'm now trying to change the gradient background color at runtime. Unfortunately, there's no API to change it at runtime, it seems. Not even by trying to mutate() the drawable, as explained here: Drawable mutations The sample XML looks like this. It works, as expected. <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <gradient android:startColor="#330000FF" android:endColor="#110000FF" android:angle="90"/> </shape> Sadly, I want a list with various colors, and they'd have to

how to add animation to textView drawable

空扰寡人 提交于 2019-11-27 06:41:02
问题 I have used this line too add image in my textView : android:drawableLeft="@drawable/ic_launcher" in my xml file. <TextView android:id="@+id/textView1" android:layout_width="match_parent" android:layout_height="wrap_content" android:drawablePadding="5dp" android:gravity="center_vertical" android:text="@string/hello_world" android:textSize="14sp" android:textStyle="bold" android:drawableLeft="@drawable/ic_launcher" > </TextView> Now I want to add animation to this drawable. I dont know how can

Drawable to byte[]

二次信任 提交于 2019-11-27 06:35:50
I have an image from the web in an ImageView . It is very small (a favicon) and I'd like to store it in my SQLite database. I can get a Drawable from mImageView.getDrawable() but then I don't know what to do next. I don't fully understand the Drawable class in Android. I know I can get a byte array from a Bitmap like: Bitmap defaultIcon = BitmapFactory.decodeStream(in); ByteArrayOutputStream stream = new ByteArrayOutputStream(); defaultIcon.compress(Bitmap.CompressFormat.JPEG, 100, stream); byte[] bitmapdata = stream.toByteArray(); But how do I get a byte array from a Drawable ? Cristian

Get URI from drawable image

…衆ロ難τιáo~ 提交于 2019-11-27 06:03:59
问题 How can I get the URI of image saved in drawable. I have tried following formats, but everytime it cannot load the image. imageURI= Uri.parse("android.resource://" + getPackageName() + "/" + R.drawable.indoor_thumbnail1); imageURI=Uri.parse("android.resource://"+getPackageName()+"/drawables/imageName"); imageURI=Uri.parse("android.resource://"+getPackageName()+"/drawables/imageName.png"); imageURI = Uri.parse("android.resource://"+ getResources().getResourceTypeName(R.drawable.indoor

Invert colors of drawable Android

99封情书 提交于 2019-11-27 05:32:45
问题 Is it possible to "invert" colors in a Drawable? Kind of what you have in a negative, you know? I know it's possible to change a Drawable to black and white... what about inverting colors? Thank you! 回答1: After some research I found out that solution is much simpler than I thought. Here it is: /** * Color matrix that flips the components (<code>-1.0f * c + 255 = 255 - c</code>) * and keeps the alpha intact. */ private static final float[] NEGATIVE = { -1.0f, 0, 0, 0, 255, // red 0, -1.0f, 0,

Drawable => grayscale

给你一囗甜甜゛ 提交于 2019-11-27 05:19:48
问题 What would be the right way to turn a color Drawable into a grayscale one (to indicate disabled state)? EDIT: B/W => grayscale 回答1: I know this question was asked a while ago, but I came across a simpler solution that works if you have a Drawable and you just want to display that same drawable in grayscale. No need to have a canvas or a painter... protected Drawable convertToGrayscale(Drawable drawable) { ColorMatrix matrix = new ColorMatrix(); matrix.setSaturation(0); ColorMatrixColorFilter

LayerDrawable programmatically

主宰稳场 提交于 2019-11-27 04:50:46
问题 Since my application's color theme is dynamic i can only create background drawables using colors and shapedrawables, i want to build a edittext background drawable with colors and shapes as shown below. But i want to do this programatically How to build this same drawable programatically? <item> <shape> <solid android:color="@android:color/yellow" /> </shape> </item> <!-- main color --> <item android:bottom="1dp" android:left="1dp" android:right="1dp"> <shape> <solid android:color="@android

How to place pin mark image over an image in android?

家住魔仙堡 提交于 2019-11-27 04:40:19
问题 I am new to Android. I am developing a project where I will get the Radio signal values(I can get the values from API). I have a floor plan. The floor plan has kitchen,hall,bedroom sections.. If I click the Kitchen section, I need to place an Pin Image in that section with Radio signal values. Once I click Save, I need to lock the Image(with values) in that particular section. Similarly I can place many Pin images based on the requirement. Please give me some related link or sample codes to