2017-02-16 56 views
-1

我想生成一个qr代码图像,并以编程方式将其添加到应用程序的资产可绘制文件夹中。android添加图像以编程方式绘制

同时,你可以在eclipse或android studio中手工添加它。只是想知道是否有任何方法可以通过编程来完成。

非常感谢!

+0

有没有办法,你可以做的一件事是在你的应用程序中创建一个单独的文件夹,并将图像存储在那里 – Nilabja

回答

0

这根本不可能,你不能修改/添加该文件夹,一旦你已经生成apk和安装的应用程序。你可以做的是在内部或外部存储器上生成一个文件夹,并将图像保存在那里。 它已经disccussed herehere

0

Asset文件夹是用来加载我们的应用数据,它永远不会在运行时改变,AssetManger有方法来读取资产数据,也没有办法在运行中Asset写编程时间。

相反,如果你想在运行时存储你的数据,你可以存储在InternalMemory像下面的代码。

Drawable drawable = getResources().getDrawable(R.drawable.demo_img); 
Bitmap bitmap = ((BitmapDrawable)drawable).getBitmap(); 
bitmap.compress(Bitmap.CompressFormat.PNG, 60, bytearrayoutputstream); 
file = new File(Environment.getExternalStorageDirectory() + "/SampleImage.png"); 
    try 
    { 
    file.createNewFile(); 
    fileoutputstream = new FileOutputStream(file); 
    fileoutputstream.write(bytearrayoutputstream.toByteArray()); 
    fileoutputstream.close(); 
    } 
    catch (Exception e) 
    { 
    e.printStackTrace(); 
    } 
相关问题