Android studio NDK开发,图像处理,会出错
private ImageView img;//用于显示图像,共两个
private ImageView pic;
public native int getPicFromJNI( byte[] src,int w,int h ,byte[] dst);//NDK实现的函数
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
img = (ImageView)findViewById(R.id.img);
pic = (ImageView)findViewById(R.id.pic);
Bitmap src = BitmapFactory.decodeResource(getResources(), R.drawable.genie);//获取图像资源
pic.setImageBitmap(src);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
src.compress(Bitmap.CompressFormat.JPEG, 100, baos);
int w = src.getWidth();
int h = src.getHeight();
byte[] info = baos.toByteArray();
byte[] dst=new byte[w*h/4];//计算之后的输入图像dst只有原图的一半,所以除以了4
getPicFromJNI(info ,w,h,dst);//NDK函数
Bitmap resultInt = BitmapFactory.decodeByteArray(dst, 0, dst.length);//将byte转化为bitmap
img.setImageBitmap(resultInt);
这个代码执行会出现错误。。
谢谢