How do I add R drawable android?

﹥>﹥吖頭↗ 提交于 2019-12-11 12:41:26

问题


Basicly my question is that how do I add a drawable resource to the R.java file in android eclipse so I can use it with this code:

ByteArrayOutputStream stream = new ByteArrayOutputStream();
        Bitmap bitmap = BitmapFactory.decodeResource(getBaseContext().getResources(),     R.drawable.kapschlogo);
        bitmap.compress(Bitmap.CompressFormat.JPEG, 100 , stream);
        Image myImg = Image.getInstance(stream.toByteArray());
        myImg.setAlignment(Image.MIDDLE);

        doc.add(myImg);

The image is stored in the parent project folder but I cant figure out how do I add it tho te R file.


回答1:


Since the R.java file is automatically generated from your resources you need to put the image file(s) under the res/drawable folder and from there they will be indexed and accessible from R.drawable.myImageFile(XML) or getResources().getDrawable(R.drawable.myImageFile);(java)



来源:https://stackoverflow.com/questions/17980621/how-do-i-add-r-drawable-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!