I'm developing an application that uses a deck of cards, so I have many PNG images in my application. In an attempt to make the files more manageable - I put them in the assets directory in sub directories. I'm wondering if this will any performance issues, as opposed to putting the images in res/drawable. I realize that they will not be accessible through the R file, but is that just a convenience for coding, or will I be taking a performance hit?
If it will cause performance issues, how are applications with many image files generally organized? Are all of the image files just 开发者_运维知识库put into the res/drawable directory (with no support for subdirectories)?
Thanks for your help!
This method copies images from assets folder to your Sdcard .here Jaydeep's Folder is the name of my folder on sdcard.You can use your folder name in that place.
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();
}
}
The only performance issue is it will always be slower to work with images from the SD Card (will, maybe "always" is too strong of a word, but certainly is true currently).
精彩评论