我从SD卡中取得一张图片,怎么把修改后的图片在存入SD卡中,
解决方案 »
- Android连接WebService失败,帮我看看是什么原因
- 软键盘挤压屏幕造成PopupWindow显示位置错误
- 请教:MediaPlayer播放进度问题
- android源码packages/apps下的程序如何调试
- 执行mediaplayer.prepare()方法随机的抛异常?求解答。。。
- 基于Android的手机智能监控系统
- android网络应用开发问题
- android 开发 求分析下这个数据库表结构,求点拨
- PackageInfo 和 ResolveInfo 的区别
- myeclipse8.5安装adt插件一直就在准备,dandan都碎掉了……
- android 2.2 直接把apk安装到SDCard问题(求教,只限高手)
- 我想学安卓开发,不知道怎么开始?
或在eclipse的ddms下有相关操作
<uses-permission android:name=”android.permission.INTERNET” />
try {
FileOutputStream out = new FileOutputStream(Environment.getExternalStorageDirectory()+ File.separator+ "test.jpg");
bmp.compress(Bitmap.CompressFormat.PNG, 90, out);
out.flush();
out.close();
} catch (Exception e) {
e.printStackTrace();
}
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
写道sdcard根目录下就是
FileOutputStream out = new FileOutputStream(new File("/sdcard/b.bmp"));
public static void write(String path){
try{
FileInputStream i = new FileInputStream(new File(path));
FileOutputStream o = new FileOutputStream(new File("/sdcard/b.bmp"));
byte[] bytes = new byte[1024];
while(i.read(bytes) != -1){
o.write(bytes, 0, 1024);
o.flush();
}
i.close();
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}特地给你写了个
这句是把什么内容写进去了????我要写进去的内容加在哪??麻烦具体点,我真的不懂
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
这句话写在</application>后面
public static void write(String path){
...
}
这个path就是你要读的文件的路径,也就是你那个bmp的路径
思路就是从path里面用输入流读取字节缓存到数组,在用输出流一点点输出到/sdcard/b.bmp
b.bmp随便取得名字,成功后你就会看到sdcard下多了个b。bmp文件
唉,就这些吧
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>才对
把AndroidManifest.xml贴上来看看
提示不对,()中必须为string 怎么改谢谢,最后一问了,望回答
能说的具体点吗,这个方法是什么意思。
Bitmap的方法直接把位图压缩成png后存入流文件内
提示不对,()中必须为string 怎么改谢谢,最后一问了,望回答
有URI直接调用 URI.openStream()就返回InputStream对象了
super.onActivityResult(requestCode, resultCode, data);
Log.v("Result OK Value:", resultCode+"");
Log.v("RequestCode Value", requestCode+"");
if(resultCode == RESULT_OK){
imageUri = data.getData();
if(requestCode == FIRST_PIC){
//在Gallery中选中一个图片时,返回来的Intent中的Data就是选择图片的Uri
srcBitmap = getSrcImage(imageUri);
srcImageView.setImageBitmap(srcBitmap);
//startActivityForResult(Intent.createChooser(intent, "选择图片"),SELECT_PICTURE);
}else if(requestCode == SECOND_PIC){
//这里处理用户选择的第二张图片
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.main);
dstBitmap = getSrcImage(imageUri);
dstImageView.setImageBitmap(dstBitmap);
try{
FileInputStream i = new FileInputStream(new File(Strinf(imageUri));
FileOutputStream o = new FileOutputStream(new File("/sdcard/b.bmp"));
byte[] bytes = new byte[1024];
while(i.read(bytes) != -1){
o.write(bytes, 0, 1024);
o.flush();
}
i.close();
}
catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
怎么改啊。
你真要URI转成String可以这样 public String getRealPathFromURI(Uri contentUri) {
String [] proj={MediaStore.Images.Media.DATA};
Cursor cursor = managedQuery( contentUri,
proj, // Which columns to return
null, // WHERE clause; which rows to return (all rows)
null, // WHERE clause selection arguments (none)
null); // Order-by clause (ascending by name)
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
return cursor.getString(column_index);
}