开发者

crop image directly from byte array

I have a byte array, which contains an image... i'd like to save it cropped.

My working method was: get the byte[] convert it into a bitmap with BitmapFactory.decodebytearray make another bitmap from it with createbitmap(sourceBitmap, x1, y1, whileX, whileY) recycle the first (uncropped one) save out the second, then recycle that too

the problem is that for a while it exists 2 bitmap, the original and th开发者_如何学JAVAe cropped one, and thats why i cant use this method with larger images (over 3MP)

is there a way to crop image directly from the byte array? I saw that there is a decodeByteArray(dataArray, offset, length, options), but i couldn't make an image from it (the remaining data was not an image)... could someone help maybe?


The method decodeByteArray(dataArray, offset, length, options) is not intended to crop an image but to parse an image from a byte buffer that contains more data than the image itself. The typical use of this is to extract images from complex binary data structures that include images among other things.

To my knowledge there is no way to crop an image without creating a new one. To me the best you can do is what you are currently doing.


For JPEG (the ubiquitous picture format on mobile devices), it is possible to decode only some specific rectangle. This requires some discipline in writing C code on top of generic software decoder, especially if you want to do it as fast as possible, and waste not extra RAM.

Support in libjpeg-turbo was been added five years after this question had been asked.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜