解决方案 »
- eclipse上android开发时 debug问题
- ADK相关问题
- 手机上的来电通流量监控怎么实现的
- java.lang.RuntimeException: Unable to instantiate application com.aaa.sc.app.bb
- 关于通知的声音播放
- 应用程序中添加广告的问题,有经验者指导一下
- 求带式运输机两级闭式齿轮传动装置
- eclipse 集成 android 开发环境,创建新项目出问题?
- viewpagerAdapter的优化
- 安卓类似于朋友圈的评论功能,当点击评论是从底部弹出输入框,求大家指点下。
- 关于动态获取一个布局高度的疑问
- 我是一名技术小白,求一枚师傅。
Camera.Parameters parameters=camera.getParameters();
int imageFormat=parameters.getPreviewFormat();
if(imageFormat==ImageFormat.NV21){
YuvImage img=new YuvImage(data,ImageFormat.NV21,screenWidth,screenHeight,null);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
img.compressToJpeg(new Rect(0,0,screenWidth,screenHeight), 100, baos);
bitmapPicture = BitmapFactory.decodeByteArray(baos.toByteArray(), 0, baos.size());
Log.i("info", bitmapPicture.toString());
}
这是callback里的代码, 然后在外边再写一个方法对bitmapPicture保存到SD卡。
然后你外边调用bitmapPicture的时候就null了?
final int w = size.width; //宽度
final int h = size.height;
final YuvImage image = new YuvImage(mData, ImageFormat.NV21, w, h, null);
ByteArrayOutputStream os = new ByteArrayOutputStream(mData.length);
if(!image.compressToJpeg(new Rect(0, 0, w, h), 100, os)){
Log.i("info", "return null");
return null;
}
byte[] tmp = os.toByteArray();
bitmapPicture = BitmapFactory.decodeByteArray(tmp, 0,tmp.length);
是因为这几句代码的执行速度太慢了,外边调用的时候,这个每次还没有执行完毕。 请问这个可以优化下吗
final int w = size.width; //宽度
final int h = size.height;
final YuvImage image = new YuvImage(mData, ImageFormat.NV21, w, h, null);
ByteArrayOutputStream os = new ByteArrayOutputStream(mData.length);
if(!image.compressToJpeg(new Rect(0, 0, w, h), 100, os)){
Log.i("info", "return null");
return null;
}
byte[] tmp = os.toByteArray();
bitmapPicture = BitmapFactory.decodeByteArray(tmp, 0,tmp.length);
是因为这几句代码的执行速度太慢了,外边调用的时候,这个每次还没有执行完毕。 请问这个可以优化下吗
典型的多线程设计错误,把需要你这个bitmapPicture结果的部分安排在此代码结束之后再运行。