Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/221.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 从字节数组裁剪图像_Android_Bitmap_Bytearray - Fatal编程技术网

Android 从字节数组裁剪图像

Android 从字节数组裁剪图像,android,bitmap,bytearray,Android,Bitmap,Bytearray,我的应用程序允许用户使用相机拍照,并返回包含图像数据的字节数组(目前为jpeg格式,但可以修改) 如果我们知道图片的宽度和高度,是否可以使用 BitmapFactory.decodeByteArray(data, offset, length) 要从指定偏移量解码图片以获得方形图片 这张图片是高分辨率的(纵向),我只需要这张图片的方形底部仍然是高分辨率的,以便进行图像处理 x offset = 0 y offset = height - width width = width height =

我的应用程序允许用户使用相机拍照,并返回包含图像数据的字节数组(目前为jpeg格式,但可以修改)

如果我们知道图片的宽度和高度,是否可以使用

BitmapFactory.decodeByteArray(data, offset, length)
要从指定偏移量解码图片以获得方形图片

这张图片是高分辨率的(纵向),我只需要这张图片的方形底部仍然是高分辨率的,以便进行图像处理

x offset = 0
y offset = height - width
width = width
height = width
我已经看到了答案,但我仍然想知道这是否可能。如果需要,我可以用另一种格式压缩图像数据

我的猜测是计算用于存储
n
像素行(使用已知维度)的字节数,其中
n=maxRows-pictureWidth


然后从计算的偏移量开始,首先解码到较小的大小

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)
然后

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

尝试此功能

但要使用此功能,我必须将图像加载到位图中,并且由于文件很大(3mb+),如果不缩小其大小,我无法将其加载到位图中(使用的方法是
bitmap.createBitmap(sourceBmp,x,y,width,height)
我需要为图像的底部部分提供最高的分辨率进行处理,因此我不能对源图像进行向下采样,然后给出opt.inSampleSize=1;这会给出相同的分辨率请参见