D
D
Dmitry Chizhov2014-12-20 20:38:52
Java
Dmitry Chizhov, 2014-12-20 20:38:52

Why can meta information be lost in a bitmap?

New to android.
The task is this: take an image by uri, resize it to reasonable sections, and send it to the server.
I came across such a moment that meta information is lost during resizing (well, or somewhere around). look pliz more experienced comrades, what's the jamb?

is = cr.openInputStream(uri);
                Bitmap bm = BitmapFactory.decodeStream(is);
                bm = scaleImage(bm, 2000, false);
                ByteArrayOutputStream stream = new ByteArrayOutputStream();
                bm.compress(Bitmap.CompressFormat.PNG, 100, stream);
                byteArray = stream.toByteArray();
                // Потом прикрепляю этот массив к AsyncHttpClient
                params.put("image", new ByteArrayInputStream(byteArray));

Next is a function from the open spaces, it should resize the image
public static Bitmap scaleImage(Bitmap realImage, float maxImageSize,
                                   boolean filter) {
        float ratio = Math.min(
                (float) maxImageSize / realImage.getWidth(),
                (float) maxImageSize / realImage.getHeight());

        int width = Math.round((float) ratio * realImage.getWidth());
        int height = Math.round((float) ratio * realImage.getHeight());

        Bitmap newBitmap = Bitmap.createScaledBitmap(realImage, width,
                height, filter);

        return newBitmap;
    }

But the server receives a file without meta information. Google provides no information. Poke your nose pliz, where is the meta information lost?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
maaGames, 2014-12-20
@maaGames

Because this is not a resize of an existing image, but the creation of a new one, based on the old one. Those. the meta-information remained in the original image, and no one copied it into the new bitmap.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question