安卓:问题解码位图图像 [英] Android: problem in Decoding bitmap image

查看:121
本文介绍了安卓:问题解码位图图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在项目中,我有过计划,我提取的像素,操纵这些像素,然后在我的包保存它的图片。是我救了它的方式是:

In my project I have a Picture that through program, I extracted pixels, manipulate those pixels and then saved it in my package. The way that I saved it, is:

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.");
}

所以,这样可以节省我的照片在这个目录中

so, it saves my picture in this directory

/data/data/my_package_name/files/myPic.bmp

/data/data/my_package_name/files/myPic.bmp

现在,我想读这个新的照片,并提取这张照片的像素。我用这个方法:

Now, I want to read this new Picture and extract pixels of this picture. I have used this method:

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);
}

在这里程序崩溃。 logcat的指示,对于图像的结果为空,当程序达到崩溃的getWidth

Program crashes here. logcat indicates that the result for the image is null and when program reaches to getWidth crashes.

这些途径写入和读出正确的?
我可以去通过目录模拟器来查看是否创建或者不这样呢?

are these ways for writing and reading correct? Can I go to the directory through emulator to check Whether this picture is created or not?

感谢

推荐答案

我觉得你应该关闭 FOS 流中的 createPicture()方法。

I think you should close fos stream in the createPicture() method.

BitmapFactory.de code *()方法在出错的情况下返回。因此最好在解码后检查

BitmapFactory.decode*() methods return null in case of error. So it's better to check for null after decoding.

据我知道你可以只保存在一个仿真器或一个植根设备从Android内部存储的文件。这可以通过使用Eclipse的DDMS角度还是从Android SDK中的工具链DDMS工具来完成。只需点击的设备 - >文件浏览器的和从设备拉你的文件。

As far as I know you can save a file from the Android internal storage only on an emulator or a rooted device. This can be done using Eclipse's DDMS Perspective or ddms utility from Android SDK toolchain. Just click Device->File Explorer and pull your files from a device.

如果您想从一个无根设备的文件,你最好把它保存到外部存储(SD卡)。在这种情况下,您可以将您的设备连接到像外部硬盘驱动器的计算机。

If you want to get a file from a non-rooted device, you'd better save it to the external storage (sdcard). In this case you can connect your device to a computer like external hard drive.

这篇关于安卓:问题解码位图图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆