drawable

Bitmaps on ICS are loaded with wrong pixel format

安稳与你 提交于 2019-11-28 10:58:52
I encountered the following problem. When any bitmap is loaded from resources by an application running on Ice Cream Sandwich, it will likely be rendered incorrectly as if it has been decoded to the format, which differs from the current window format, with no dither applied. However, both, the decoding format and window format have been explicitly set: BitmapFactory.Options opts = new BitmapFactory.Options(); opts.inPreferredConfig = Bitmap.Config.RGBA_8888; and getWindow().setFormat(PixelFormat.RGBA_8888); getWindow().addFlags(WindowManager.LayoutParams.FLAG_DITHER); Here are screenshots of

Get absolute path of android drawable image

烈酒焚心 提交于 2019-11-28 10:13:35
问题 I need to get the absolute path or the File object of my drawable image in android application. Is there any way to do this? Drawable is as following context.getResources().getDrawable(R.drawable.back_button) 回答1: If you app is insalled on sdcard try this code : Bitmap bitMap = BitmapFactory.decodeResource(getResources(),R.id.img1); File mFile1 = Environment.getExternalStorageDirectory(); String fileName ="img1.jpg"; File mFile2 = new File(mFile1,fileName); try { FileOutputStream outStream;

Convert GradientDrawable to Bitmap

雨燕双飞 提交于 2019-11-28 09:48:09
问题 I have the following gradient (generated dynamically): GradientDrawable dynamicDrawable = new GradientDrawable(); dynamicDrawable.setGradientType(GradientDrawable.LINEAR_GRADIENT); dynamicDrawable.setUseLevel(false); int colors[] = new int[3]; colors[0] = Color.parseColor("#711234"); colors[1] = Color.parseColor("#269869"); colors[2] = Color.parseColor("#269869"); dynamicDrawable.setColors(colors); and I want to set that drawable in a view using onDraw method. When I want to assign a Drawable

Set Image on Left side of EditText in Android

人走茶凉 提交于 2019-11-28 08:26:33
I am having one contact form in which I would like to add some icons to my edit text for a better look. I want to create EditText something like below. I have EditText like below. And I got the result something like. I want the image to be absolutely on the left side as it is in the above image. I know that internally EditText is using Nine Patch image and i think that is why the result is some what different. Can anyone know how to resolve this? <EditText android:id="@+id/name" android:layout_width="fill_parent" android:layout_height="51dip" android:hint="@string/name" android:inputType="text

android programmatically blur imageview drawable

一曲冷凌霜 提交于 2019-11-28 06:04:48
I want to programmatically blur and unblur images in Android. I hear that android flag "blur" is no longer supported after API 14 , but I wanted to use Java methods anyway. My main problem is manipulating the bitmap from an Imageview drawable. How would I get the bitmap from an imageview and manipulate it (will probably use gaussian blur) and set it back to the imageview? I think the process involves extracting the drawable, converting the drawable to a bitmap, doing my blur method on that bitmap and then doing the reverse till it is set to the imageview again but I would like that process

Drawable vs Single reusable Bitmap better with memory?

余生长醉 提交于 2019-11-28 05:25:53
As I understand it (not that I'm correct) Drawables are generally correctly removed from memory when the application is finished with them. Bitmaps however need to be manually recycled, and sometimes even have a special class written to handle them properly. My question is, in regards to memory and leaks, is it more beneficial to simply stick with Drawables like such: myView.setBackgroundDrawable(getResources().getDrawable(R.drawable.my_image)); myView1.setBackgroundDrawable(getResources().getDrawable(R.drawable.my_image1)); myView2.setBackgroundDrawable(getResources().getDrawable(R.drawable

Is it possible to load a drawable from the assets folder?

﹥>﹥吖頭↗ 提交于 2019-11-28 05:13:51
Can you load a drawable from a sub directory in the assets (not the drawable folder) folder? Hope this help: Drawable d = Drawable.createFromStream(getAssets().open("Cloths/btn_no.png"), null); I recommend to use this Drawable.createFromResourceStream(resources,new TypedValue(), resources.getAssets().open(filename), null) which returns properly scaled drawable thanks to resources ... Here's a class with static method to get the drawable from the assets. It also closes the inputstream. import android.content.Context; import android.graphics.drawable.Drawable; import java.io.IOException; import

Invert colors of drawable Android

一个人想着一个人 提交于 2019-11-28 05:04:10
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! Carlos Pereira 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, 0, 255, // green 0, 0, -1.0f, 0, 255, // blue 0, 0, 0, 1.0f, 0 // alpha }; drawable

How to programmatically set drawableRight on Android Edittext?

无人久伴 提交于 2019-11-28 04:36:57
I know about set drawableRight in XML. but i required to do it programmatically because it is change as per some condition. You can use the function below: editText.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.drawableRight, 0); The order of params corresponding to the drawable location is: left, top, right, bottom Rethinavel Pillai Find Further here EditText myEdit = (EditText) findViewById(R.id.myEdit); myEdit.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.icon, 0); // where params are (left,top,right,bottom) You can also set drawable padding programmatically: myEdit

Apply an Animation on a Drawable in Android

雨燕双飞 提交于 2019-11-28 03:26:10
问题 I am adding a glow animation effect to a logo. So far, I have managed to get the glow image behind the logo, using a LayeredDrawable, but I can't figure out how to animate it. I have found that AlphaAnimation would achieve the desired effect, but unfortunately I can only apply it on Views, not Drawables. How can I achieve this effect? 回答1: Android 3.0 introduced Property Animations. Unfortunately, this is limited to Android 3.0 and up which won't get on phones any time soon. 回答2: Simple