我想重新大小的图像,该部分完成。然后我试图EXIF标签复制到新文件。我用ExifInterface读取标签。我知道这是一个接口不是对象。但是,当我尝试使用它的真正的大尺寸图像时,我得到 NullPointerException异常
。我得到这个错误并不适用于所有的图像。
I am trying to re-size an image, that part completed.
Then I'm trying to copy exif tags to new file.
I use ExifInterface to read tags.
I know it's an interface not an object.
But When I try to use it for really big sized image, I get NullPointerException
.
I get this error not for all the images.
07-25 11:59:23.870: WARN/System.err(1362): java.lang.NullPointerException
07-25 11:59:23.870: WARN/System.err(1362): at android.media.ExifInterface.saveAttributes(ExifInterface.java:202)
我该如何解决呢?
How do I solve it?
code复制EXIF信息
Code to copy exif information
try {
// copy paste exif information from original file to new
// file
ExifInterface oldexif = new ExifInterface(filePath);
ExifInterface newexif = new ExifInterface(file.getPath());
int build = Build.VERSION.SDK_INT;
// From API 11
if (build >= 11) {
newexif.setAttribute("FNumber",
oldexif.getAttribute("FNumber"));
newexif.setAttribute("ExposureTime",
oldexif.getAttribute("ExposureTime"));
newexif.setAttribute("ISOSpeedRatings",
oldexif.getAttribute("ISOSpeedRatings"));
}
// From API 9
if (build >= 9) {
newexif.setAttribute("GPSAltitude",
oldexif.getAttribute("GPSAltitude"));
newexif.setAttribute("GPSAltitudeRef",
oldexif.getAttribute("GPSAltitudeRef"));
}
// From API 8
if (build >= 8) {
newexif.setAttribute("FocalLength",
oldexif.getAttribute("FocalLength"));
newexif.setAttribute("GPSDateStamp",
oldexif.getAttribute("GPSDateStamp"));
newexif.setAttribute("GPSProcessingMethod",
oldexif.getAttribute("GPSProcessingMethod"));
newexif.setAttribute("GPSTimeStamp",
oldexif.getAttribute("GPSTimeStamp"));
}
newexif.setAttribute("DateTime",
oldexif.getAttribute("DateTime"));
newexif.setAttribute("Flash", oldexif.getAttribute("Flash"));
newexif.setAttribute("GPSLatitude",
oldexif.getAttribute("GPSLatitude"));
newexif.setAttribute("GPSLatitudeRef",
oldexif.getAttribute("GPSLatitudeRef"));
newexif.setAttribute("GPSLongitude",
oldexif.getAttribute("GPSLongitude"));
newexif.setAttribute("GPSLongitudeRef",
oldexif.getAttribute("GPSLongitudeRef"));
// You need to update this with your new height width
newexif.setAttribute("ImageLength",
oldexif.getAttribute("ImageLength"));
newexif.setAttribute("ImageWidth",
oldexif.getAttribute("ImageWidth"));
newexif.setAttribute("Make", oldexif.getAttribute("Make"));
newexif.setAttribute("Model", oldexif.getAttribute("Model"));
newexif.setAttribute("Orientation",
oldexif.getAttribute("Orientation"));
newexif.setAttribute("WhiteBalance",
oldexif.getAttribute("WhiteBalance"));
newexif.saveAttributes();
Toast.makeText(getApplicationContext(),
"Image resized & saved successfully",
Toast.LENGTH_SHORT).show();
} catch (Exception e) {
e.printStackTrace();
}
更多信息onFly:
Additional onFly information:
创建新文件时,我试图同时读取该文件:
New file is created when I'm trying to read both the file:
在oldexif调试手表
Debug watch on oldexif
在newexif调试手表
Debug watch on newexif
测试图片
HTTP://vikaskanani.files.word$p$ pss.com/2011/07/test.jpg
使用Android模拟器的SDK 2.1
Using Android emulator for sdk 2.1
您是在什么地方saveAttributes传递一个空值。
You are passing a null value somewhere in the saveAttributes.
调试NullPointerException异常是很容易的,为您提供有源$ C $ C。
Debugging NullPointerExceptions is very easy, providing you have the sourcecode.
下面你可以找到源头code为ExifInterface为Android 2.1
Below you can find the sourcecode for the ExifInterface for Android 2.1
http://grep$c$c.com/file/repository.grep$c$c.com/java/ext/com.google.android/android/2.1_r2/android/media/ExifInterface.java#ExifInterface
线202包含此:
sb.append(val.length() + " ");
唯一可以为空这里是VAL。 (你在saveAttributes方法传递的一个值)。
Only thing that can be null here is val. (one of the values you're passing in the saveAttributes method).
我会建议您检查一下你传递到该值的价值,并观看了空值。
I would suggest double checking the values you're passing onto that value, and watch out for null values.