问题描述
|
我正在开发一个使用一副纸牌的应用程序,因此我的应用程序中有很多PNG图像。为了使文件更易于管理,我将它们放在子目录中的assets目录中。
我想知道这是否会带来性能问题,而不是将图像放入res / drawable中。
我意识到它们将无法通过R文件进行访问,但这仅仅是为了方便编码,还是我会受到性能的影响?
如果这会导致性能问题,通常如何组织具有多个图像文件的应用程序?是否将所有图像文件都放入了res / drawable目录中(不支持子目录)?
谢谢你的帮助!
解决方法
这种方法将图像从资产文件夹复制到您的SD卡中,这里Jaydeep \的Folder是我在SD卡上的文件夹的名称。您可以在该位置使用您的文件夹名称。
public void copyImagesInSdcard()
{
assetManager = mycontext.getAssets();
assetManager1 = mycontext.getAssets();
System.out.println(\"In copyImagesInSdcard\");
try
{
str1=assetManager.list(\"\");
ss=assetManager1.list(str1[1]);
InputStream is;
//System.out.println(ss[0]);
File file=new File(Environment.getExternalStorageDirectory().getPath() + \"/Jaydeep\'s Folder\");
if(file.exists()!=true)
{
file.mkdir();
}
else
{
if(file.length()==0)
{
file.mkdir();
}
System.out.println(\"Length:\"+file.length());
}
for(int i=0;i<ss.length;i++)
{
is=assetManager1.open(str1[1] + \"/\" + ss[i]);
file=new File(Environment.getExternalStorageDirectory().getPath() + \"/Jaydeep\'s Folder/\" + ss[i] );
FileOutputStream out=new FileOutputStream(file);
//Bitmap bi = BitmapDrawable.createFromStream(is,ss[0]);
byte b[] =new byte[4096];
while (is.read(b) != -1) {
out.write(b);
}
out.close();
}
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
, 唯一的性能问题是,使用SD卡中的图像将总是较慢(可能“总是”一词太强了,但目前肯定是正确的)。