We have been trying to set a picture in our app, using a bitmap fecthed from a server. Problem is, the app keeps crashing on every operation we use on this Bitmap. `
String jsonInString = img;
image = gson.fromJson(jsonInString, Bitmap.class);
}
`
Is the code where we get the bitmap.
Then if we try to resize the Bitmap or set an ImageView with it, the app closes out, providing no errors. We have looked at the unfiltered part of the log aswell.
We have tried setting the ImageView to null, among other things, but it seems the error is in the bitmap.
I want to take a picture in my App, so if I click on my ImageView/QuickBagde on my Fragment.
I'm able to take a picture, after that, I crop it and it return to my App. This is not a big deal and it's working well.
But how can I refresh the ImageView/QuickBadge to show up the taken picture?
I tried with:
//get the returned data
Bitmap thePic = data.getExtras().getParcelable("data");
profilePic.setImageBitmap(thePic);
But it doesn't work.
you can try this
Bitmap bitmap=BitmapFactory.decodeFile(imagepath);
imageview.setImageBitmap(bitmap);
I know this has been asked here, but my problem is a bit different. I read other answers related to this topic on SO but they did not solve my problem.
So in my app, I have 2 activities. In the first one, there are 20 imageviews (and I am planning to add more) and in the second activity, there is a custom view which is actually a zoom image class. Basically, when the user will click on any imageview in the first acivity he will be taken to the 2nd activity where he can zoom that particular image.
What I want to do in the coding part is that get the image that is displayed on the clicked imageview and pass it to the next activity. To achieve that, I have used the below given code but it's not working. What could be wrong?
Activity_one
Intent startzoomactivity = new Intent(Activity_one.this, Activity_two.class);
Bitmap img_res = img.getDrawingCache();
Bundle extras = new Bundle();
extras.putParcelable("imagebitmap", img_res);
startzoomactivity.putExtras(extras);
startActivity(startzoomactivity);
Activity_two
Intent startzoomactivity = getIntent();
Bundle extras = getIntent().getExtras();
Bitmap bmp = (Bitmap) extras.getParcelable("imagebitmap");
TouchImageView img = new TouchImageView(this); // TouchImageView is the class that enables zoom feature on the imageview.
img.setImageResource(i);
img.setMaxZoom(5f);
you cannot pass the ImageView to the other activity. Views are directly tied to the activity they belong and cannot be passed around.
What you're trying to achieve in the code is to get a drawing cache copy of the ImageView as a bitmap, which even after you make it work (it's missing the view.setDrawingCache), it will give you a very bad result, specially after zooming-in.
What you need to do is find the original image (if it came from the internet the URL, or the location in your disk cache, if it's from your resources folder, the int resId that draw that image, and pass this value (string or int) to the next activity. Then you let the next activity create its own ZoomableImageView and set the original resource (link, file, resource) to it.
I understand what you want to achieve but your way is totally wrong. Instead of passing ImageView Bitmap pass the ImageView URL or Path (and if drawable then ResId) where this image coming from and pass that URL or Path or ResId to the Next Activity and load this image as a Bitmap onto ZoomableImageView.
You can get the image from imageview as a bitmap, then compress it using http://developer.android.com/reference/android/graphics/Bitmap.html#compress(android.graphics.Bitmap.CompressFormat, int, java.io.OutputStream) api. then covert the outputstream object to byte array and since that is parcelable you can put this object in an intent and pass to your second activity
I've created a bitmap from canvas. Save it to my "/sdcard/folder/subfolder/file.png"
I want to get this png file into imageview after saving it. I tried this by using BitmapFactory.decodeFile("/sdcard/folder/subfolder/file.png"); method. But it returned nothing. There is no image on imageview.
Do you have any idea?
Try using
String filePath = Environment.getExternalStorageDirectory()+"/folder/subfolder/file.png";//or "folder/subfolder.."
I am a high school student looking for help saving a bitmap image creating using a modified version of the "Sensor Graph" tutorial available here: http://code.google.com/p/amarino/downloads/detail?name=SensorGraph_02.zip&can=2&q=
This creates an oscilloscope graph based on external sensor activity, and I need to save the image (currently a bitmap) as a JPEG to the Android phone Image Gallery. I would like to do so using a button.
I have enabled OnClickListener in my SensorGraph class, an extension of the Activity class; however, the actual bitmap is created in the View class.
I would appreciate if someone could provide some code to help me save the bitmap.
I can also use a general "OnClick" command in the main.xml file; however, I believe that the method specified there would just refer back to the Activity class, so I still do not know how to save a bitmap created in the View class using a method in the Activity class.
Thank you very much.
Please try following code,
ImageView v1 = (ImageView)findViewById(R.id.mImage);
v1.setDrawingCacheEnabled(true);
Bitmap bm = v1.getDrawingCache();