画像を表示
64842 ワード
sdカードの画像を1枚1枚表示するには、すべてロードして表示する必要があります.1枚をロードすると表示が遅くなります.
public class Pics extends Activity { private ImageView image; private String[] mFiles; private int mFilePosition = 0; private ArrayList<Bitmap> bitArray; private Bitmap b; private int i; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); image = (ImageView) findViewById(R.id.image); bitArray = new ArrayList<Bitmap>(); File images = Environment .getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES); try { images.createNewFile(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } Log.e("file path", images.getAbsolutePath()); File[] imagelist = images.listFiles(new FilenameFilter() { public boolean accept(File dir, String name) { return ((name.endsWith(".jpg")) || (name.endsWith(".png"))); } }); mFiles = new String[imagelist.length]; Log.e("size", imagelist.length + ""); for (int i = 0; i < imagelist.length; i++) { mFiles[i] = imagelist[i].toString(); } getImageFromSDCard(); } public void getImageFromSDCard() { BitmapFactory.Options options = new BitmapFactory.Options(); options.inSampleSize = 8; try { for (int j = 0; j < mFiles.length; j++) { Log.d("", mFiles[mFilePosition]); b = BitmapFactory.decodeFile(mFiles[j], null); bitArray.add(b); } } catch (Exception e) { // Log error background-color: transparent; margin: 0px; color: #000000; font-size: 14px; vertical-align: baseline; bord