I have an image in thumbnail in my application and I want to display full screen image like it shows, when you click on any image in gallery and it displays in full screen.
How can i achieve that?
You could launch the gallery app itself to view the image using below code snippet
You could give this a try.
Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse(file.getAbsolutePath()),"image/*");
startActivity(intent);
I would suggest in onClick method of your thumbnail, you can start a new Activity in fullscreen mode:
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
and pass the image uri or something which indicate the image source to the new activity :
Intent intent = new Intent(YouActivity.this, FullImage.class);
intent.putExtra("imageUri", R.drawable.yourImage); // or the path to your image : "/sdcard/MyImages/image.png"
and than just show it in imageView of FullImage Activity like this :
ImageView icon = (ImageView) findViewById(R.id.myImage);
BitmapFactory.Options options = new BitmapFactory.Options();
options.inTempStorage = new byte[3*1024];
Bitmap ops = BitmapFactory.decodeFile(path, options);
icon.setImageBitmap(ops); // where icon is the imageView in your xml file
Related
I have requirement like I have a custom Horizontal ScrollView with text and image(image which is invisible) and button to start camera intent.
When I select any item I am getting Id of that scroll item. When I click on button to capture photo my code is taking photo and getting the path from sdcard.but image view is not getting visibility even when I use imageView.setVisibility(View.VISIBLE); this line code.
ImageView I declared globally in main class.
Please give me an idea in this issue.
=============================================================================
This is the code I done after capturing photo inside on
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 5;
bb = BitmapFactory.decodeFile(imageFile.getAbsolutePath(),
options);
MediaStore.Images.Media.insertImage(getContentResolver(),
bb, null, null);
System.out.println("Bitmap is : " + bb);
System.out.println("Tab Id to keep photo is : " + tabId);
imageView.setImageBitmap(bb);
imageView.setVisibility(View.VISIBLE);
filePath = imageFile.getAbsolutePath();
Thanks,
UdaySekhar
I have several images stored in content://media/external/images/media. I would like to display by using ImageView and add the image view to the table. here is my code.
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 24;
final Bitmap b = BitmapFactory.decodeFile("content://media"+getFileLocation(), options);
ImageView milestoneImageView = new ImageView(this);
milestoneImageView.setImageBitmap(b);
recordRow.addView(milestoneImageView);
When I print out the getFileLocation(), it says "/external/images/media/62". So I added "content://media" to make a full path, but it is not working...
Can someone point out why the code above is not working?
I think "/external/images/media/62" its a Uri not a real file path..
So instead of
final Bitmap b = BitmapFactory.decodeFile("content://media"+getFileLocation(), options);
Just try
final Bitmap b = BitmapFactory.decodeStream(getContentResolver().openInputStream("content://media"+getFileLocation()), null,options);
And let me know what happen..
I am making an android app in which i need to enlarge the image size on click.
I am getting these images downloaded from server and then adding these images programmatically in the activity and hence setting id of images programmatically. Now my problem is that when i send the imageid o another activity to enlarge it it is taking only the id of last image.
and hence gives the following exception.
Unable to start activity ComponentInfo{com.emx.OnDaMove/com.emx.OnDaMove.FullImageActivity}: android.content.res.Resources$NotFoundException: Resource ID #0x5
i am using the following code for making images and adding them to table rows.
imageUrl = "http://ondamove.it/English/images/users/";
imageUrl = imageUrl + listObject.get(j).getImage();
image = new ImageView(this);
image.setPadding(20, 10, 0, 0);
image.setId(j+1);
imageId=image.getId();
tr.addView(image);
and the following method for clickliastener:
private OnClickListener clickImageListener = new OnClickListener() {
public void onClick(View v) {
Intent fullScreenIntent = new Intent(v.getContext(),FullImageActivity.class);
fullScreenIntent.putExtra(ProfilePageNormalUser.class.getName(),imageId) ;
ProfilePageNormalUser.this.startActivity(fullScreenIntent);
}
};
and the activity in which images are to be enlarged is:
ImageView myimage = (ImageView) findViewById(R.id.imageviewEnlarged);
Intent intent = getIntent();
int imageId = (Integer) intent.getExtras().get(ProfilePageNormalUser.class.getName());
System.out.println("********"+imageId +"**********");
InputStream is = this.getResources().openRawResource(imageId);
Bitmap originalBitmap = BitmapFactory.decodeStream(is);
Matrix imageMatrix = new Matrix();
imageMatrix.postRotate(90);
Bitmap scaledBitmap = Bitmap.createBitmap(originalBitmap, myimage.getWidth(), myimage.getHeight(), originalBitmap.getWidth(), originalBitmap.getHeight(), imageMatrix, false);
myimage.setImageBitmap(scaledBitmap);
myimage.setScaleType(ScaleType.FIT_XY);
Ya surely it will give the last Id since the value of imageId will be update on every loop. This will store the last known value during looping.
You should use array instead of simple variable.
or you can use v.getId in onClick method. (simpler one)
ImageButton avatarButton = (ImageButton) findViewById(R.id.ImageButton_Avatar);
avatarButton.setImageResource(R.drawable.avatar);
strAvatarFilename = "Image.jpg";
final Uri imageUriToSaveCameraImageTo = Uri.fromFile(new File(Environment.getExternalStorageDirectory()+"/Folder/"+strAvatarFilename));
avatarButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent pictureIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
pictureIntent.putExtra( MediaStore.EXTRA_OUTPUT, imageUriToSaveCameraImageTo );
startActivityForResult(Intent.createChooser(pictureIntent, strAvatarPrompt), TAKE_AVATAR_CAMERA_REQUEST);
Editor editor = Preferences.edit();
editor.putString(PREFERENCES_AVATAR, imageUriToSaveCameraImageTo.getPath());
editor.commit();
}
});
I have this code. It takes a photo and then stores it in two locations, the default location on the SDcard and the /folder/ file i want the photo to be stored in also. Once taken i refresh the screen using this...
ImageButton avatarButton = (ImageButton) findViewById(R.id.ImageButton_Avatar);
String strAvatarUri = Preferences.getString(PREFERENCES_AVATAR, "");
Uri imageUri = Uri.parse(strAvatarUri);
avatarButton.setImageURI(null);
avatarButton.setImageURI(imageUri);
This refreshes the image button so the user can see the image they have taken. However, this is appears very big and fills the screen. Is there any way i can compress or downsize the image so the user can see it at a reasonable size? thanks
Bitmap thumb = Bitmap.createScaledBitmap (BitmapFactory.decodeFile(photoPath), 96, 96, false);
Where the second and third parameters to createScaledBitmap are the width and height respectively.
http://developer.android.com/reference/android/graphics/Bitmap.html#createScaledBitmap%28android.graphics.Bitmap,%20int,%20int,%20boolean%29
EDIT: It now occurred to me that you can do this in a faster, more efficient way, using BitmapFactory.Options and the inSampleSize option:
BitmapFactory.Options opts = new BitmapFactory.Options ();
opts.inSampleSize = 2; // for 1/2 the image to be loaded
Bitmap thumb = Bitmap.createScaledBitmap (BitmapFactory.decodeFile(photoPath, opts), 96, 96, false);
This way you will save even more memory and the downsizing should take less time.
You can mess with the ImageButton's scaleType properties (to fitXY for example, or cropCenter), and by setting a fixed size to LayoutPreferences (height and width) you'll be all set.
The Android Library SiliCompressor provide this functionality for you to compress your images while keeping the image quality.
For some reason, when I create a bitmap from an image in asset, it does not display fullscreen. When I take an image from drawable, resId, the image shows fullscreen. Why is this?
//the image is not fullscreen
ImageView iv = new ImageView(getBaseContext());
iv.setImageBitmap(bitmapFileFromAssetorSD);
//this makes the image fullscreen
//iv.setBackgroundResource(resId);
iv.setLayoutParams(
new LayoutParams(
android.view.ViewGroup.LayoutParams.MATCH_PARENT, android.view.ViewGroup.LayoutParams.MATCH_PARENT
)
);
Try setting the appropriate ImageView.ScaleType
ImageView.setScaleType(ImageView.ScaleType.CENTER_CROP)