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