gpt4 book ai didi

android - 在不使用位图的情况下裁剪相机拍摄的图像

转载 作者:搜寻专家 更新时间:2023-11-01 08:45:33 25 4
gpt4 key购买 nike

我正在开发一个图像处理应用程序,我需要将拍摄的照片分成四个区域,但是使用 BitmapFactoy 会占用太多资源和时间并且会减慢我的速度,我想使用原始字节 [] 数据来做到这一点 public void onPictureTaken(byte[] data, Camera camera) 给我。现在这就是我所做的,我想改进它以使用 byte[] 来加速它:

public void onPictureTaken(byte[] data, Camera camera) {
new AsyncImageAnalyzer(data).execute();
data = null;
}

public AsyncImageAnalyzer(byte[] d) {
mData = d;
surfaceView = null;
}



@Override
protected Void doInBackground(Void... params) {

FileOutputStream fos2 = null;
try {

String fileName = Long.toString(Calendar.getInstance().getTimeInMillis())+".jpg";
String storageState = Environment.getExternalStorageState();
if (storageState.equals(Environment.MEDIA_MOUNTED)) {
File file = new File(/*"/sdcard/XXX"*/Environment.getExternalStorageDirectory().getAbsolutePath()+File.separator+"XXX",
fileName);
/*file.createNewFile();*/
fos2 = new FileOutputStream(file);
fos2.write(mData,0,mData.length);
fos2.flush();
fos2.close();
/*fos2.write(mData);*/
/*fos2.close();*/

if(extrasReceived.equals("1")){
spe.putString("FirstPicPath","/"+fileName).commit();
}else {
spe.putString("SecondPicPath","/"+fileName).commit();
}
}
} catch (Exception e) {
e.printStackTrace();
Log.e("ISA exception",e.getMessage() );
}finally {
try {
if (fos2 != null) {
fos2.close();
}
} catch (IOException e) {
e.printStackTrace();
}

}

final BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = sp.getInt("compression_ratio",1);
bitmap = BitmapFactory.decodeByteArray(mData, 0, mData.length,options);
mData = null;


t1G = Bitmap.createBitmap(bitmap, 0, (bitmap.getHeight() / 2) - 1, bitmap.getWidth() / 2, bitmap.getHeight() / 2);
t2G = Bitmap.createBitmap(bitmap, (bitmap.getWidth() / 2) - 1, (bitmap.getHeight() / 2) - 1, bitmap.getWidth() / 2, bitmap.getHeight() / 2);
t1R = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth() / 2, bitmap.getHeight() / 2);
t2R = Bitmap.createBitmap(bitmap, (bitmap.getWidth() / 2) - 1, 0, bitmap.getWidth() / 2, bitmap.getHeight() / 2);



try {
t2RtoInt = getDominantColor(t2R);
t1RtoInt = getDominantColor(t1R);
t1GtoInt = getDominantColor(t1G);
t2GtoInt = getDominantColor(t2G);
} catch (Exception e) {
e.printStackTrace();
Log.e("exception", e.getMessage());
}

return null;
}

此外,如果我提出任何可以加快这些操作速度的建议,我们将不胜感激。

最佳答案

有没有想过BitmapRegionDecoder (目前只支持JPEG和PNG格式)?如果您使用 API 级别 10 及更高级别开发应用,则可以使用此 API 来加速大型位图处理。

    boolean isShareable = false;
try {
InputStream is = new FileInputStream("/mnt/sdcard/test.png");
Rect rect = new Rect();
BitmapFactory.Options options = new BitmapFactory.Options();
BitmapRegionDecoder.newInstance(is, isShareable).decodeRegion(rect, options);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

关于android - 在不使用位图的情况下裁剪相机拍摄的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28727705/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com