我只能保存1张图像,此代码保存了最后一次拍摄的图像,因此旧图像会自动删除。我应该保存大量的图像到SD卡,我该怎么办才能修复此代码?在Android中将图像保存到SD卡
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == IMAGE_ACTION_CODE) {
// 2
Bitmap thumbnail = (Bitmap) data.getExtras().get("data");
imagev.setImageBitmap(thumbnail);
// 3
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
thumbnail.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
// 4
String filename;
Date date = new Date(0);
SimpleDateFormat sdf = new SimpleDateFormat ("yyyyMMddHHmmss");
filename = sdf.format(date);
File file = new
File(Environment.getExternalStorageDirectory()+File.separator+filename+".jpg");
try {
file.createNewFile();
FileOutputStream fo = new FileOutputStream(file);
// 5
fo.write(bytes.toByteArray());
fo.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
我想这代码,但仍然采取错误的logcat:
sdf.setTimeZone(TimeZone.getTimeZone("UTC")); filename = sdf.format(new Date());
我意识到这个问题是不是日期格式。
仍以错误的logcat例如:
12-20 08:48:32.120: E/SoundPool(288): error loading /system/media/audio/ui/Lock.ogg
12-20 08:48:32.120: E/SoundPool(288): error loading /system/media/audio/ui/Unlock.ogg
12-20 08:48:32.620: E/EventHub(288): could not get driver version for /dev/input/mouse0, Not a typewriter
12-20 08:48:32.620: E/EventHub(288): could not get driver version for /dev/input/mice, Not a typewriter
12-20 08:48:32.720: E/Trace(288): error opening trace file: No such file or directory (2)
12-20 08:48:33.800: E/CommandListener(34): Failed to open /proc/sys/net/ipv6/conf/wlan0/disable_ipv6: No such file or directory
12-20 08:48:33.840: E/WifiStateMachine(288): Failed to disable IPv6: java.lang.IllegalStateException: command '1 interface ipv6 wlan0 disable' failed with '400 1 Failed to change IPv6 state (No such file or directory)'
12-20 08:48:33.920: E/MobileDataStateTracker(288): default: Ignoring feature request because could not acquire PhoneService
12-20 08:48:33.920: E/MobileDataStateTracker(288): default: Could not enable APN type "default"
12-20 08:48:36.850: E/Trace(349): error opening trace file: No such file or directory (2)
12-20 08:48:38.330: D/dalvikvm(288): GC_CONCURRENT freed 273K, 9% free 4588K/5012K, paused 8ms+31ms, total 516ms
12-20 08:48:38.330: D/dalvikvm(288): WAIT_FOR_CONCURRENT_GC blocked 284ms
12-20 08:48:38.340: D/dalvikvm(288): WAIT_FOR_CONCURRENT_GC blocked 335ms
12-20 08:48:38.350: D/dalvikvm(288): WAIT_FOR_CONCURRENT_GC blocked 317ms
12-20 08:48:38.350: I/ActivityManager(288): Start proc com.android.inputmethod.latin for service com.android.inputmethod.latin/.LatinIME: pid=377 uid=10018 gids={50018}
12-20 08:48:38.360: D/dalvikvm(288): WAIT_FOR_CONCURRENT_GC blocked 254ms
12-20 08:48:38.590: E/Trace(377): error opening trace file: No such file or directory (2)
12-20 08:48:39.500: E/ThrottleService(288): problem during onPollAlarm: java.lang.IllegalStateException: problem parsing stats: java.io.FileNotFoundException: /proc/net/xt_qtaguid/iface_stat_all: open failed: ENOENT (No such file or directory)
12-20 08:48:40.261: E/Trace(394): error opening trace file: No such file or directory (2)
12-20 08:48:42.171: E/SurfaceFlinger(37): ro.sf.lcd_density must be defined as a build property
12-20 08:48:42.331: E/ActivityThread(377): Failed to find provider info for com.android.inputmethod.latin.dictionarypack
12-20 08:48:42.502: E/BinaryDictionaryGetter(377): Could not find a dictionary pack
12-20 08:48:43.362: I/ActivityManager(288): Start proc android.process.acore for content provider com.android.providers.userdictionary/.UserDictionaryProvider: pid=432 uid=10010 gids={50010, 3003, 1015, 1028}
12-20 08:48:43.471: E/StrictMode(377): A resource was acquired at attached stack trace but never released. See java.io.Closeable for information on avoiding resource leaks.
12-20 08:48:43.471: E/StrictMode(377): java.lang.Throwable: Explicit termination method 'close' not called
12-20 08:48:43.471: E/StrictMode(377): at dalvik.system.CloseGuard.open(CloseGuard.java:184)
12-20 08:48:43.471: E/StrictMode(377): at android.os.ParcelFileDescriptor.<init>(ParcelFileDescriptor.java:412)
12-20 08:48:43.471: E/StrictMode(377): at android.content.res.AssetManager.openNonAssetFdNative(Native Method)
12-20 08:48:43.471: E/StrictMode(377): at android.content.res.AssetManager.openNonAssetFd(AssetManager.java:428)
,并采取这个错误在错误日志:
**警告:环境变量家里没有设置。以下目录将用于存储Git。 警告:未处理的事件循环异常。
警告:EGit无法检测到原生Git的安装路径“gitPrefix”。因此,EGit无法遵守系统级别 可能在**中配置的Git设置
您的图像保存为“20131220000000”? HHmmss没有区别? – Fllo
用1970010102000121.jpg名称保存。是的。 –