eclipse 如何添加 R drawable android?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17980621/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 21:00:23  来源:igfitidea点击:

How do I add R drawable android?

androideclipseimager.java-file

提问by Miguel

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:

基本上我的问题是如何在 android eclipse 中向 R.java 文件添加可绘制资源,以便我可以使用以下代码:

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.

图像存储在父项目文件夹中,但我不知道如何将它添加到 R 文件中。

回答by TronicZomB

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

由于 R.java 文件是从您的资源自动生成的,您需要将图像文件放在res/drawable文件夹下,然后从那里将它们编入索引并可从R.drawable.myImageFile(XML) 或getResources().getDrawable(R.drawable.myImageFile);(java) 访问