Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/202.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_Image_Bmp - Fatal编程技术网

Android:位图图像解码中的问题

Android:位图图像解码中的问题,android,image,bmp,Android,Image,Bmp,在我的项目中,我有一张图片,通过程序,我提取像素,处理这些像素,然后将其保存在我的包中。我保存它的方式是: private void createPicture() { System.out.println("Inside createPicture"); System.out.println(contextPath); try{ FileOutputStream fos = new FileOutputStream(contextPath + "/" +

在我的项目中,我有一张图片,通过程序,我提取像素,处理这些像素,然后将其保存在我的包中。我保存它的方式是:

private void createPicture()
{
    System.out.println("Inside createPicture");
    System.out.println(contextPath);
    try{
        FileOutputStream fos = new FileOutputStream(contextPath + "/" + picName);
        DataOutputStream dos = new DataOutputStream(fos); 

        for(int i=0; i<splitedPixel.length; i++)
            dos.writeByte(splitedPixel[i]);

        dos.flush();
        dos.close();
    }
    catch(IOException e){
        System.out.println("IOException : " + e);
    }
    System.out.println("Picture Created.");
}
程序在此崩溃。logcat表示映像的结果为null,并且当程序达到getWidth时崩溃

这些书写和阅读的方法正确吗? 我可以通过emulator进入目录检查是否创建了此图片吗


谢谢

我想你应该在
createPicture()
方法中关闭
fos

BitmapFactory.decode*()
方法在出现错误时返回
null
。因此,最好在解码后检查
null

据我所知,您只能在模拟器或根设备上保存来自Android内部存储的文件。这可以使用Eclipse的DDMS透视图或Android SDK工具链中的DDMS实用程序来完成。只需单击设备->文件资源管理器并从设备中提取文件

如果要从非根设备获取文件,最好将其保存到外部存储器(SD卡)。在这种情况下,您可以将设备连接到计算机,如外部硬盘驱动器

public Stego(Context context)
{
    //Instantiate an ImageView and define its properties
    contextPath = context.getFilesDir().getAbsolutePath();
    image = BitmapFactory.decodeFile(contextPath + "/" + picName);

    System.out.println("Image= " + image);
    imWidth  = image.getWidth();
    imHeight = image.getHeight();
    getMaxMessageChars();
    System.out.println("Width: " + imWidth);
}