android - 将图像加载到页面 curl Activity 中

标签 android image

我已经将一组图像加载到我的 SD 卡中,我想在我的 page curl Activity 中显示它们。

我检查了图像是否正确下载:

 ArrayList<String>  mStringList= new ArrayList<String>();
 File strPath = new File(Environment.getExternalStorageDirectory() + "/Pictures");
 int lists = strPath.listFiles().length; 
 Log.d("number of items in array ",String.valueOf(lists));

 File yourDir = new File(strPath, "");
 for (File f : yourDir.listFiles()) {
     if (f.isFile())
     {
         String name = f.getName();
         String v = strPath + "/" + name;
         mStringList.add(v);
     }
 }

这是位图提供者:

 * Bitmap provider.
 */
private class PageProvider implements CurlView.PageProvider {

    // Bitmap resources.
    private int[] mBitmapIds = { R.drawable.obama, R.drawable.road_rage,
            R.drawable.taipei_101, R.drawable.world };

    @Override
    public int getPageCount() {
        return 5;
    }

    private Bitmap loadBitmap(int width, int height, int index) {
        Bitmap b = Bitmap.createBitmap(width, height,
                Bitmap.Config.ARGB_8888);
        b.eraseColor(0xFFFFFFFF);
        Canvas c = new Canvas(b);
        Drawable d = getResources().getDrawable(mBitmapIds[index]);

        int margin = 7;
        int border = 3;
        Rect r = new Rect(margin, margin, width - margin, height - margin);

        int imageWidth = r.width() - (border * 2);
        int imageHeight = imageWidth * d.getIntrinsicHeight()
                / d.getIntrinsicWidth();
        if (imageHeight > r.height() - (border * 2)) {
            imageHeight = r.height() - (border * 2);
            imageWidth = imageHeight * d.getIntrinsicWidth()
                    / d.getIntrinsicHeight();
        }

        r.left += ((r.width() - imageWidth) / 2) - border;
        r.right = r.left + imageWidth + border + border;
        r.top += ((r.height() - imageHeight) / 2) - border;
        r.bottom = r.top + imageHeight + border + border;

        Paint p = new Paint();
        p.setColor(0xFFC0C0C0);
        c.drawRect(r, p);
        r.left += border;
        r.right -= border;
        r.top += border;
        r.bottom -= border;

        d.setBounds(r);
        d.draw(c);

        return b;
    }

如何替换

// Bitmap resources.
        private int[] mBitmapIds = { R.drawable.obama, R.drawable.road_rage,
                R.drawable.taipei_101, R.drawable.world }; 
and Drawable d = getResources().getDrawable(mBitmapIds[index]);

进入我的 SD 卡中的那些?

最佳答案

将图像从 sdcard 转换为 drawable 为:

BitmapFactory.Options options = new BitmapFactory.Options();
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
Bitmap bitmap = BitmapFactory.decodeFile(mStringList[index], options);

Drawable d = new BitmapDrawable(bitmap);;

关于android - 将图像加载到页面 curl Activity 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14231376/

相关文章:

php - ffmpeg 视频中的随机图像,但按顺序排列

javascript - 在 div 中使用图像而不使用 <img> 标签

image - 使用 iText 将外部图像添加到 PDF

android - 不存在这样的 acos 函数

java - 在多个数组上获取相同的元素值

Android YoutubePlayer 因 "java.lang.NoClassDefFoundError: us"异常和应用程序崩溃而停止

javascript - 如何在html中使用jquery变量

FragmentDialog 中的 Android Google map 被 Dialog 自己的灰色覆盖层覆盖

android - 为什么 ListView.getCheckedItemPositions() 没有返回正确的值?

javascript - 投资组合图像未在 Mozilla Firefox 中加载