在我的项目中,我有一张图片,我通过程序提取像素,处理这些像素,然后将其保存在我的包中。我保存它的方式是:
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.");
}
所以,它将我的图片保存在这个目录中
/data/data/my_package_name/files/myPic.bmp
现在,我想阅读这张新图片并提取这张图片的像素。我用过这个方法:
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 指示图像的结果为 null 并且程序到达 getWidth 时崩溃。
这些写作和阅读方式正确吗?能否通过模拟器进入目录查看这张图片是否创建?
谢谢