Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

question how to save photo as byte array #49

Closed
yp25 opened this issue Jun 29, 2017 · 2 comments
Closed

question how to save photo as byte array #49

yp25 opened this issue Jun 29, 2017 · 2 comments
Assignees

Comments

@yp25
Copy link

yp25 commented Jun 29, 2017

Hi, I want to know how to save photo captured as byte array directly.
In this sample code :
`private void takePicture() {
PhotoResult photoResult = fotoapparatSwitcher.getCurrentFotoapparat().takePicture();

    photoResult.saveToFile(new File(
            getExternalFilesDir("photos"),
            "photo.jpg"
    ));

    photoResult
            .toBitmap(scaled(0.25f))
            .whenAvailable(new PendingResult.Callback<BitmapPhoto>() {
                @Override
                public void onResult(BitmapPhoto result) {
                    ImageView imageView = (ImageView) findViewById(R.id.result);

                    imageView.setImageBitmap(result.bitmap);
                    imageView.setRotation(-result.rotationDegrees);
                }
            });
}

`

I can read from photo.jpg and then save to byte array variable . But how to directly read the photo data as byte array? Thank you

@dmitry-zaitsev
Copy link
Member

PhotoResult actually delivers photo as a byte array, and then toBitmap converts it to actual Bitmap. So, what you can do:

photoResult
    .toPendingResult()
    .whenAvailable(photo -> {
        // photo.encodedImage - that's your byte array
        // pay attention to photo.rotationDegrees parameter
    });

@ElyDantas
Copy link

PhotoResult actually delivers photo as a byte array, and then toBitmap converts it to actual Bitmap. So, what you can do:

photoResult
    .toPendingResult()
    .whenAvailable(photo -> {
        // photo.encodedImage - that's your byte array
        // pay attention to photo.rotationDegrees parameter
    });

Should be in the README :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants