file android closed,Android(onPreviewFrame):将NV21数据保存为JPEG文件(Android (onPreviewFrame): Saving NV21 d...

Android(onPreviewFrame):将NV21数据保存为JPEG文件(Android (onPreviewFrame): Saving NV21 data as JPEG File [closed])

我有onPreviewFrame()回调的以下代码。 它现在能够将数据保存为JPEG文件,我可以在浏览器中查看,但不能在Windows图片查看器中查看。 我的代码有问题吗?

YuvImage im = new YuvImage(data, ImageFormat.NV21, size.width,

size.height, null);

Rect r = new Rect(0,0,size.width,size.height);

ByteArrayOutputStream baos = new ByteArrayOutputStream();

im.compressToJpeg(r, parameters.getJpegQuality(), baos);

try{

FileOutputStream output = new FileOutputStream(String.format(

"/sdcard/%s_%d.jpg", strPrevCBType, System.currentTimeMillis()));

output.write(baos.toByteArray());

output.flush();

output.close();

}catch(FileNotFoundException e){

}catch(IOException e){

}

谢谢,

artsylar

I have the following code for onPreviewFrame() Callback. It is now able to save the data as a JPEG file and I can view it in a browser but not in Windows Picture Viewer. Is there something wrong with my code?

YuvImage im = new YuvImage(data, ImageFormat.NV21, size.width,

size.height, null);

Rect r = new Rect(0,0,size.width,size.height);

ByteArrayOutputStream baos = new ByteArrayOutputStream();

im.compressToJpeg(r, parameters.getJpegQuality(), baos);

try{

FileOutputStream output = new FileOutputStream(String.format(

"/sdcard/%s_%d.jpg", strPrevCBType, System.currentTimeMillis()));

output.write(baos.toByteArray());

output.flush();

output.close();

}catch(FileNotFoundException e){

}catch(IOException e){

}

Thanks,

artsylar

原文:https://stackoverflow.com/questions/6677429

更新时间:2019-12-17 12:48

最满意答案

我的代码现在正在运行。 我不知道昨天发生了什么,但唯一的区别是我现在正在使用adb命令来提取文件,昨天我使用的是Eclipse File Explorer。

但是,如果有更好的方法来编写此代码,请告诉我。

My code is working now. I don't know what happened yesterday but the only difference is I'm using adb command now to pull files and yesterday I was using the Eclipse File Explorer.

But just in case there is a better way to write this code, please let me know.

2011-07-14

相关问答

好吧,我弄清楚我在哪里乱了。 我最初做了这样的事情: public void surfaceChanged(SurfaceHolder holder, int format, int width,

int height) {

this.width = width; this.height = height;

params.setPreviewSize( width, height );

camera.setParameters( params );

...

我最终最终直接用C ++调整了我的图像(作为OpenCV.Mat)。 这样更方便,更快捷。 Size size(correctedWidth, correctedHeight);

Mat dst;

resize(image, dst, size);

I finally end up resizing my image (as a OpenCV.Mat) directly in C++. This was way easier and faster. Size size(correctedWidt

...

我的代码现在正在运行。 我不知道昨天发生了什么,但唯一的区别是我现在正在使用adb命令来提取文件,昨天我使用的是Eclipse File Explorer。 但是,如果有更好的方法来编写此代码,请告诉我。 My code is working now. I don't know what happened yesterday but the only difference is I'm using adb command now to pull files and yesterday I was

...

我认为您的问题可能是当您尝试根据摄像机的旋转设置setPreviewSize() 。 请确保将其设置为parameters.getSupportedPreviewSizes()包含的受支持的预览大小,而不交换维度。 我怀疑你的问题是你正在尝试交换支持的(宽度,高度)对并将其设置为摄像机并且它被作为捕获参数拒绝,但在告知new YuvImage(...)时它仍然被错误地使用new YuvImage(...)构造函数如何解释图像字节数组。 I think your problem might be w

...

谢谢Alex Cohn帮助我更快地完成此转换。 我实现了你的建议方法(RenderScript intrinsics)。 该代码由RenderScript intrinsics制作,将YUV图像转换为位图约5倍。 以前的代码需要100-150毫秒。 在三星Note 3上,这需要15-30左右。 如果有人需要执行相同的任务,请使用以下代码: 这些将被使用: private RenderScript rs;

private ScriptIntrinsicYuvToRGB yuvToRgbIntrins

...

我不知道这是否是预期的结果,但你应该尝试这个命令: display \

-size 640x480 \

-depth 8 \

-sampling-factor 4:2:0 \

-colorspace srgb \

Image0.yuv

结果: I don't know if this is the expected result, but you should try this co

...

在具有奇数尺寸的图像(即W或H中的一个,WxH图像中的一个是奇数)的情况下,您希望Y平面一如既往地被完全采样,使用WxH样本,然后是2(⌈W/ 2⌉x⌈H/2⌉)色度样本,我们将每个图像维度除以2但是向上舍入而不是向下舍入。 因此,图像边缘处的一些像素具有仅对应于1或2个原始像素的色度样本,而不是4.我希望这是有意义的。 您可以在此链接中看到,其他几个库以前在YUV图像中处理奇数尺寸时遇到了问题。 对于你的第二个问题,我还没有看到官方规范,但我在android框架中看到了一些处理这种格式的代码,我

...

例: public class Camera {

public interface PreviewReadyCallback {

void onPreviewFrame(String value1, int value2, Double value3, Float value4, Bitmap value5); // Any value you want to get

}

PreviewReadyCallback mPreviewReadyCallback = null;

publ

...

看起来有一个关于MJPEG文件播放所需的jpeg质量的阈值。 改变, im.compressToJpeg(r, 5, jpegByteArrayOutputStream);

至, im.compressToJpeg(r, 75, jpegByteArrayOutputStream);

得到一个有效的MJPEG文件。 It appears that there is a threshold with regards to jpeg quality that is required for a

...

好的,在仔细重复我通过android文档阅读之后想出了几件事。 显然预览[尺寸|格式]与图片[尺寸/格式]完全不同,我认为它们之前是同一个。 因此,这修复了由于不正确的数据格式导致的渲染问题和崩溃。 它还自动澄清了我对相机参数变化的困惑。 整个例子现在正在运作。 但是,我看到两层预览,一个是由相机直接渲染的,另一个是我渲染的onDraw。 我不确定我是否应该看到他们两个。 以下是固定代码。 感谢任何可能花时间在此的人。 现在,我将努力将整个onPreviewFrame逻辑移动到本机代码以加快速度!

...

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值