imageview

Android get image from gallery into ImageView

℡╲_俬逩灬. 提交于 2019-11-26 12:14:06
I'm trying to add a photo from galery to a ImageView but I get this error: java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1, result=-1, data=Intent { dat=content://media/external/images/media/1 }} to activity {hotMetter.pack/hotMetter.pack.GetPhoto}: java.lang.NullPointerException This is my code: Intent intent = new Intent(); intent.setType("image/*"); intent.setAction(Intent.ACTION_GET_CONTENT); startActivityForResult(Intent.createChooser(intent,"Select Picture"), SELECT_PICTURE); } Bitmap bitmap=null; public void onActivityResult(int requestCode, int

How to make an image fit into a circular frame in android

喜你入骨 提交于 2019-11-26 12:07:31
问题 I have a ListView in which there is an ImageView , the image in the ImageView gets loaded dynamically after its fetched from the server. Now, I want these images, of any size, to fit into a circular frame, how to do that? Here\'s a sample pic of what I want 回答1: With the help of previous answer I came up with this solution.Hope it help others: import android.app.Activity; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Canvas; import android

How to get the Dimensions of a Drawable in an ImageView? [duplicate]

天大地大妈咪最大 提交于 2019-11-26 12:04:03
问题 This question already has answers here : How to get the width and height of an android.widget.ImageView? (10 answers) Closed 3 years ago . What is the best way to retrieve the dimensions of the Drawable in an ImageView? My ImageView has an Init-Method where i create the ImageView: private void init() { coverImg = new ImageView(context); coverImg.setScaleType(ScaleType.FIT_START); coverImg.setImageDrawable(getResources().getDrawable(R.drawable.store_blind_cover)); addView(coverImg); } At some

Get Bitmap attached to ImageView

浪尽此生 提交于 2019-11-26 11:59:56
Given ImageView image = R.findViewById(R.id.imageView); image.setImageBitmap(someBitmap); Is it possible to retrieve the bitmap? Bitmap bitmap = ((BitmapDrawable)image.getDrawable()).getBitmap(); Sarwar Erfan This will get you a Bitmap from the ImageView . Though, it is not the same bitmap object that you've set. It is a new one. imageView.buildDrawingCache(); Bitmap bitmap = imageView.getDrawingCache(); === EDIT === imageView.setDrawingCacheEnabled(true); imageView.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));

Changing ImageView source

ぐ巨炮叔叔 提交于 2019-11-26 11:49:03
问题 I have an ImageView with a source image set in the xml using the following syntax: <ImageView android:id=\"@+id/articleImg\" style=\"@style/articleImgSmall_2\" android:src=\"@drawable/default_m\" /> Now I need to change this image programmatically. What I need to do is delete the old image and add a new one though. What I have done is this: myImgView.setBackgroundResource(R.drawable.monkey); It works but I noticed android stacks the new image on top of the old one (dont ask me how I found out

How to add a shadow and a border on circular imageView android?

天涯浪子 提交于 2019-11-26 11:39:35
I created a CircularImageView with this question: Create circular image view in android Download project on GitHub 1) This is the CircularImageView class : public class CircularImageView extends ImageView { public CircularImageView(Context context) { super(context); } public CircularImageView(Context context, AttributeSet attrs) { super(context, attrs); } public CircularImageView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } @Override protected void onDraw(Canvas canvas) { Drawable drawable = getDrawable(); if (drawable == null) { return; } if

How to set tint for an image view programmatically in android?

对着背影说爱祢 提交于 2019-11-26 11:30:46
Need to set tint for an image view... I am using it the following way: imageView.setColorFilter(R.color.blue,android.graphics.PorterDuff.Mode.MULTIPLY); But it doesn't change... Hardik You can change the tint, quite easily in code via: imageView.setColorFilter(Color.argb(255, 255, 255, 255)); // White Tint If you want color tint then imageView.setColorFilter(ContextCompat.getColor(context, R.color.COLOR_YOUR_COLOR), android.graphics.PorterDuff.Mode.MULTIPLY); For Vector Drawable imageView.setColorFilter(ContextCompat.getColor(context, R.color.COLOR_YOUR_COLOR), android.graphics.PorterDuff.Mode

Android - ViewRootImpl$CalledFromWrongThreadException

喜欢而已 提交于 2019-11-26 11:29:16
问题 I was using this, to DISPLAY IMAGES FROM THE INTERNET but it throws an error as below: 04-12 13:45:05.337: E/AndroidRuntime(27897): Caused by: android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views. public class Order extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); new DownloadFilesTask().execute(); } private class DownloadFilesTask extends AsyncTask

Resizing images to fit the parent node

岁酱吖の 提交于 2019-11-26 11:24:29
问题 How do I get an image in an ImageView to automatically resize such that it always fits the parent node? Here is a small code example: @Override public void start(Stage stage) throws Exception { BorderPane pane = new BorderPane(); ImageView img = new ImageView(\"http://...\"); //didn\'t work for me: //img.fitWidthProperty().bind(new SimpleDoubleProperty(stage.getWidth())); pane.setCenter(img); Scene scene = new Scene(pane); stage.setScene(scene); stage.show(); } 回答1: @Override public void

Resizing ImageView to fit to aspect ratio

北城以北 提交于 2019-11-26 11:12:08
问题 I need to resize an ImageView such that it fits to the screen, maintains the same aspect ratio. The following conditions hold: Images are a fixed width (size of the width of screen) Images are downloaded from the Internet, i.e. size can only be determined later Aspect ratio for each image will vary; some are tall, some are square, some are flat ImageView\'s height needs to change, either bigger or smaller based on the aspect ratio of the Excess height is cropped, can\'t have a lot of empty