2

My app let the user take a picture with the camera and return a byte array containing the image data (jpeg at the moment but can be modified).

If we know the width and height of the picture, is it possible to use

BitmapFactory.decodeByteArray(data, offset, length)

To decode the picture from specified offset to get a squared picture ?

The image is in high res (portrait) and I only need the squared bottom of this picture still in high res for image processing.

x offset = 0
y offset = height - width
width = width
height = width

I have seen this answer but I still was wondering if this was possible. I could compress image data with another format if needed

My guess was to compute the number of bytes used to store n rows of pixels (using known dimensions), where n = maxRows - pictureWidth

and then start from computed offset

Community
  • 1
  • 1
Jerec TheSith
  • 1,932
  • 4
  • 32
  • 41

1 Answers1

0

First decode to small size

BitmapFactory.Options opt = new BitmapFactory.Options();
    opt.inSampleSize = 4;  //inSampleSize == 4 returns an image that is 1/4 the width/height of the original, and 1/16 the number of pixels

BitmapFactory.decodeByteArray(data, offset, length, opt)

ANd Then

bitMap1 = Bitmap.createScaledBitmap(bitMap, width, height, true);

try this

Siva
  • 446
  • 2
  • 9
  • 24
  • but to use this function I must load my image into a bitmap, and as the file is large (3mb+) I can't load it into a bitmap without downscaling it (an the method to use would rather be `Bitmap.createBitmap(sourceBmp, x, y, width, height)` – Jerec TheSith Dec 28 '12 at 10:41
  • I need to have to highest resolution available for the bottom part of the image for precessing, so I can't down downsample the source image – Jerec TheSith Dec 28 '12 at 11:10
  • then give opt.inSampleSize = 1; which give same resolution – Siva Dec 28 '12 at 11:14