Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/185.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何使用RGB_565创建位图?_Android_Bitmap - Fatal编程技术网

Android 如何使用RGB_565创建位图?

Android 如何使用RGB_565创建位图?,android,bitmap,Android,Bitmap,实际上,我正在使用以下代码从assets文件夹打开png文件: public static Bitmap loadImage( String imageName ){ if( imageName.charAt(0) == '/' ) { imageName = imageName.substring(1); } imageName = imageName + ".png"; Bitmap image = BitmapFactory.decodeSt

实际上,我正在使用以下代码从assets文件夹打开png文件:

public static Bitmap loadImage( String imageName ){
    if( imageName.charAt(0) == '/' ) {
        imageName = imageName.substring(1);
    }
    imageName = imageName + ".png";
    Bitmap image = BitmapFactory.decodeStream(getResourceAsStream(imageName));
    return image;
}
public static InputStream getResourceAsStream( String resourceName ) {
    if( resourceName.charAt(0) == '/' ) {
        resourceName = resourceName.substring(1);
    }

    InputStream is = null;
    try {
        is = context.getAssets().open( resourceName );
    } catch (IOException e) {e.printStackTrace();}
    return is;
}
这段代码以完整的方式打开位图,打开它需要很多时间。我将尝试使用RGB_565加快位图的打开速度

使用RGB_565打开位图时,我应该在代码中更改什么?如你所见,我不知道图像的宽度和高度

此外,任何加快位图打开速度的建议都将受到欢迎


感谢添加位图工厂。
decodeStream()
调用的选项:

BitmapFactory.Options bitmapLoadingOptions = new BitmapFactory.Options();
bitmapLoadingOptions.inPreferredConfig = Bitmap.Config.RGB_565;
BitmapFactory.decodeStream(instream,null,bitmapLoadingOptions);

至于如何加速加载图像?我不知道你还能做什么,除非可能的话可以减小图像的大小。

这段代码对我很有用

    AssetManager assetManager = getAssets();
    InputStream istr = null;
    try {
        istr = assetManager.open(strName);
    } catch (IOException e) {
        e.printStackTrace();
    }

    BitmapFactory.Options bitmapLoadingOptions = new BitmapFactory.Options();
    bitmapLoadingOptions.inPreferredConfig = Bitmap.Config.RGB_565;
    Bitmap bitmap = BitmapFactory.decodeStream(istr,null,bitmapLoadingOptions);


    return bitmap;