android 生成缩略图
来源:互联网 发布:javascript与jsp 编辑:程序博客网 时间:2024/05/01 20:29
package com.example.ImageView;import android.app.Activity;import android.content.Context;import android.content.Intent;import android.database.Cursor;import android.net.Uri;import android.os.Bundle;import android.provider.MediaStore;import android.util.Log;import android.view.Menu;import android.view.MenuInflater;import android.view.MenuItem;import android.view.View;import android.view.ViewGroup;import android.widget.AdapterView;import android.widget.BaseAdapter;import android.widget.GridView;import android.widget.ImageView;import android.widget.AdapterView.OnItemClickListener;/** * SD 卡上显示图片 */public class MyActivity extends Activity { /** * Cursor used to access the results from querying for images on the SD card. */ private Cursor cursor; /* * Column index for the Thumbnails Image IDs. */ private int columnIndex; String TAG="test"; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); // Set up an array of the Thumbnail Image ID column we want String[] projection = {MediaStore.Images.Thumbnails._ID}; // Create the cursor pointing to the SDCard cursor = managedQuery( MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI, projection, // Which columns to return null, // Return all rows null, MediaStore.Images.Thumbnails.IMAGE_ID); // Get the column index of the Thumbnails Image ID columnIndex = cursor.getColumnIndexOrThrow(MediaStore.Images.Thumbnails._ID); GridView sdcardImages = (GridView) findViewById(R.id.sdcard); sdcardImages.setAdapter(new ImageAdapter(this)); // Set up a click listener sdcardImages.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView parent, View v, int position, long id) { // Get the data location of the image String[] projection = {MediaStore.Images.Media.DATA}; cursor = managedQuery( MediaStore.Images.Media.EXTERNAL_CONTENT_URI, projection, // Which columns to return null, // Return all rows null, null); columnIndex = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); cursor.moveToPosition(position); // Get image filename读取图片 Log.d(TAG,"-----------------------one------------------------"); String imagePath = cursor.getString(columnIndex); Log.d(TAG,imagePath);//调用系统图片浏览器 Intent it = new Intent(Intent.ACTION_VIEW); Uri mUri = Uri.parse("file://" + imagePath); it.setDataAndType(mUri, "image/*"); startActivity(it); // Use this path to do further processing, i.e. full screen display } }); } /** * Adapter for our image files. */ private class ImageAdapter extends BaseAdapter { private Context context; public ImageAdapter(Context localContext) { context = localContext; } public int getCount() { return cursor.getCount(); } public Object getItem(int position) { return position; } public long getItemId(int position) { return position; } public View getView(int position, View convertView, ViewGroup parent) { ImageView picturesView; if (convertView == null) { picturesView = new ImageView(context); // Move cursor to current position cursor.moveToPosition(position); // Get the current value for the requested column int imageID = cursor.getInt(columnIndex); // Set the content of the image based on the provided URI picturesView.setImageURI(Uri.withAppendedPath( MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI, "" + imageID)); picturesView.setScaleType(ImageView.ScaleType.FIT_CENTER); picturesView.setPadding(8, 8, 8, 8); picturesView.setLayoutParams(new GridView.LayoutParams(100, 100)); } else { picturesView = (ImageView)convertView; } return picturesView; } }}
0 0
- android 生成缩略图
- android生成缩略图
- android生成缩略图
- android 生成缩略图
- android 生成缩略图
- android为图片生成缩略图
- Android 生成缩略图的方法!!!
- Android图片操作-生成缩略图
- Android--生成缩略图------方法总结
- Android为多媒体文件生成缩略图
- android 怎样为多媒体文件生成缩略图
- Android为多媒体文件生成缩略图
- Android为多媒体文件生成缩略图
- Android生成圆形缩略图的一种方法
- Android为多媒体文件生成缩略图
- android 图片压缩 生成缩略图方法
- Android图片质量压缩以及缩略图生成
- Android图片质量压缩以及缩略图生成
- Socket的阻塞模式和非阻塞模式
- eclipse创建分支遇到的问题(初稿)
- Recover Binary Search Tree
- 《云端时代杀手级应用:大数据分析》扫描版[PDF]
- 2013级C++第3周【项目3 - 时间类】
- android 生成缩略图
- LA 4452 The Ministers' Major Mess(2-SAT)
- 1324:算法2-2:有序线性表的有序合并
- Windows 7安装CentOS6.5 双系统
- Grinder
- WPF: 把引用的dll移动到自定义路径
- Linux下找不到Android设备的解决方法
- Remove Element
- 【时光网评出的得分最高的100部电影】一定要抽时间去看看!