English 中文(简体)
外部储存的中装重图像
原标题:Android load big images from external storage

I need to load lots of big images (500 .png files) from the SD card to my app. Do I always have to convert images to Bitmap and make Bitmap files? I don t want to resize the Heap. Is there another way to read the images from SD card?

问题回答

If you re displaying them in a view, then you have to load them into memory in their entirety.

你没有提及你的形象将如何大,但我们在光彩中所做的事情是保留一份<代码>清单。 SoftReferences to these bitmaps, so that the garbage Collectionor can ob them when they re notprofile (i.e. when the view showing them have discarded-make ensure that this actual when, e.g. by using AdapterView/code>). 用这些比照图的齐装来判断这一点,你应该好。

在座标中,图像的内部表述是分光和斜体,而不是任何特定格式(png、bmp等)的形象。

当图象由BitmapFactory装上时,图像被转换为内部代表。

装上所有轨道图通常不是一个好的想法,你很快将摆脱记忆......

如果你的形象面貌非常大,那么,在装上图像前,你必须加以改变。 否则,即使有一幅照片,也很容易造成记忆问题。 我不知道你们想要同时展示多少形象,以及这些形象的大小。 但是,我建议你在显示这些想法之前重新加以利用。

为了改变形象和显示形象,你可以使用这一守则:

    BitmapFactory.Options bitmapOptions = new BitmapFactory.Options();
    bitmapOptions.inJustDecodeBounds = true;
    BitmapFactory.decodeStream(fileInputStream, null, bitmapOptions);

    //reduce the image size
    int imageWidth = bitmapOptions.outWidth;
    int imageHeight = bitmapOptions.outHeight;
    int scale = 1;
    while (imageWidth/scale >= screenWidth && imageHeight/scale >= screenHeight) {
        imageWidth = imageWidth / 2;
        imageHeight = imageHeight / 2;
        scale = scale * 2;
    }

    //decode the image with necessary size
    fileInputStream = new FileInputStream(cacheFile);
    bitmapOptions.inSampleSize = scale;
    bitmapOptions.inJustDecodeBounds = false;
    imageBitmap = BitmapFactory.decodeStream(fileInputStream, null, bitmapOptions);
    ImageView imageView = (ImageView)this.findViewById(R.id.preview);
    imageView.setImageBitmap(imageBitmap);

在我的波塔项目中,我正在利用这部法典,将我的克民共体的挂图转作审查。

Android Save And Loaddownload Locally





相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...