gpt4 book ai didi

android - 如何添加 R drawable android?

转载 作者:行者123 更新时间:2023-11-29 14:39:09 24 4
gpt4 key购买 nike

基本上我的问题是如何将可绘制资源添加到 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);

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

最佳答案

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

关于android - 如何添加 R drawable android?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17980621/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com