How to resize a Bitmap image in Android
12,168
Using Bitmap may help you. Use like this:
Bitmap nameYourBitmap;
Bitmap resized = Bitmap.createScaledBitmap(nameYourBitmap, newWidth, newHeight, true);
You can also do like this:
resized = Bitmap.createScaledBitmap(nameYourBitmap,(int)(nameYourBitmap.getWidth()*0.8), (int)(nameYourBitmap.getHeight()*0.8), true);
Refer to this: How to resize Image in Android?
For XML, the scale attributes are defined for ScaleDrawables, and they can scale another drawable. Please refer to this developer site: https://developer.android.com/guide/topics/resources/drawable-resource.html#Scale
Related videos on Youtube
Author by
Program-Me-Rev
Love programming. Java, C, C++ are my first languages. Others include, among others, PHP, JavaScript, Python. Frameworks: Spring, Apache Camel, JQuery, React / R.N, including Node.js environment.
Updated on June 04, 2022Comments
-
Program-Me-Rev almost 2 years
<?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android" android:paddingLeft="32dp" android:paddingTop="10dp" android:paddingRight="0dp" android:paddingBottom="10dp"> <item android:bottom="3dp"> <bitmap android:gravity="center_vertical|left" android:src="@drawable/ic_publish_black_24dp" /> <shape android:shape="rectangle"> <stroke android:width="0dp" android:color="#37474f" /> </shape> </item> </layer-list>
This is how I call it:
TextView aboutBags = new TextView( mContext ); aboutBags.setText("Compose"); aboutBags.setTextAppearance( R.style.RevStyleHelpAbout ); aboutBags.setBackgroundResource( R.drawable.rev_item_h_border_left );
I've tried border attributes
android:width="22dp" android:height="22dp"
all over the XML, but the image doesn't get resized.How can I resize the bitmap image?
Vielen dank im voraus.
-
Program-Me-Rev almost 7 yearsThank you for the reply @Animesh Patra. Can I do it inside the XML.
-
Animesh Patra almost 7 years@Program-Me-Rev You are welcome. If my answer was any help, you may accept it for future reference to others.