0

In my app I have implemented full screening of the image when you click on it. In programm it happens in this way: I pass the bitmap from imageviews(images made by camera) to next activity via put extra, next activity accepts it and shows bitmap in imageview. I have lots of imageviews , and problem is for example If I m making pics in vertical state by camera and if next picture I make in horizontal state, full screen image of previouse images becomes compressed in height.

How I pass the bitmap from 1 activity to next:

        Bitmap bitmap = params[0];
        int h = bm.getHeight();
        int w = bm.getWidth();
        bitmap = bitmap.createScaledBitmap(bitmap,w/2,h/2, true);
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        bitmap.compress(Bitmap.CompressFormat.PNG, 50, baos);
        byte[] b = baos.toByteArray();

        Intent intent = new Intent(PhotoAdder.this, FullScreenImage.class);
        intent.putExtra("picture", b);
        startActivity(intent);

How next activity accepts bitmap:

    Bundle extras = getIntent().getExtras();
    byte[] b = extras.getByteArray("picture");

    Bitmap bmp = BitmapFactory.decodeByteArray(b, 0, b.length);
    ImageView image = (ImageView) findViewById(R.id.full);
    image.setImageBitmap(bmp);

The width and height of imageview of next activity is match_parent.

Bek
  • 71
  • 1
  • 9
  • you have already scale bitmap by h/2 . – D.J Oct 19 '16 at 05:49
  • @Dheerubhai, I know, but in next activity depending from last made picture it changes the scale of image, as I wrote before. – Bek Oct 19 '16 at 05:53
  • any ways you will get the path of the image rite you just pass that to the next activity and load the image again using bitmap – nakul Oct 19 '16 at 06:36

2 Answers2

0

For scaling an image you need to fix one parameter (either height or width) and wrap the other parameter , android does that automatically. so set your imageview height and width accordingly. And set the scaletype as well. In addition to that you can also check at run time if width is greater than height programmatically set width as match parent and height as wrapcontent and vice versa.

Ankit

0

Try to avoid keep bitmap in memory.
Try save bitmap to temporary file and pass file path to another activity.

If you want to display portrait image at Horizontal screen, you have to change ImageView scale type properly.

check https://stackoverflow.com/a/25069883/2373466

Community
  • 1
  • 1
Sung Min Lee
  • 154
  • 7
  • I want to show image in its original state, if image made in horizontal state to show it in horizontal state, the same with vertical state. Unfortunately, changing the scaleType didn't help, I ll try to pass bitmap via temporary file. – Bek Oct 19 '16 at 06:33
  • @Bek then check image's exif information and change image scale type. – Sung Min Lee Oct 19 '16 at 06:38