Java-Android:图像保存到位置
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了Java-Android:图像保存到位置,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2309字,纯文字阅读大概需要4分钟。
内容图文
![Java-Android:图像保存到位置](/upload/InfoBanner/zyjiaocheng/652/c8bd05ebb30f46da8632e0fd2f974962.jpg)
我正在显示一组图像,然后,如果用户希望,可以将图像保存到SD卡.我需要将其保存到外部存储的帮助.有人可以帮我这个忙吗?
网格视图:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
GridView gridview = (GridView) findViewById(R.id.gridview);
gridview.setAdapter(new ImageAdapter(this));
gridview.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
Toast.makeText(HelloGridView.this, "" + position, Toast.LENGTH_SHORT).show();
}
});
ImageAdapter:
public class ImageAdapter extends BaseAdapter {
private Context mContext;
public ImageAdapter(Context c) {
mContext = c;
}
public int getCount() {
return mThumbIds.length;
}
public Object getItem(int position) {
return null;
}
public long getItemId(int position) {
return 0;
}
// create a new ImageView for each item referenced by the Adapter
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imageView;
if (convertView == null) { // if it's not recycled, initialize some attributes
imageView = new ImageView(mContext);
imageView.setLayoutParams(new GridView.LayoutParams(85, 85));
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setPadding(8, 8, 8, 8);
} else {
imageView = (ImageView) convertView;
}
imageView.setImageResource(mThumbIds[position]);
return imageView;
}
// references to our images
private Integer[] mThumbIds = {
R.drawable.sample_2, R.drawable.sample_3,
R.drawable.sample_4, R.drawable.sample_5,
R.drawable.sample_6, R.drawable.sample_7,
R.drawable.sample_0, R.drawable.sample_1,
R.drawable.sample_2, R.drawable.sample_3,
R.drawable.sample_4, R.drawable.sample_5,
R.drawable.sample_6, R.drawable.sample_7,
R.drawable.sample_0, R.drawable.sample_1,
R.drawable.sample_2, R.drawable.sample_3,
R.drawable.sample_4, R.drawable.sample_5,
R.drawable.sample_6, R.drawable.sample_7
};
解决方法:
你好
我没有使用我提供给您的代码作为应用程序的一部分,但是我确实使用它来调试了其中一个应用程序在运行时生成的位图.
try {
FileOutputStream out = new FileOutputStream("/sdcard/test2.png");
mBitmap.compress(Bitmap.CompressFormat.PNG, 90, out);
} catch (Exception e) {
e.printStackTrace();
}
使用此代码,只要您有位图,就只需要清单权限
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
希望能帮到您
杰森
内容总结
以上是互联网集市为您收集整理的Java-Android:图像保存到位置全部内容,希望文章能够帮你解决Java-Android:图像保存到位置所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。