[英]Can I load a texture into OpenGL based off of the display density?
Following example code for Android OpenGL programming, I am loading my textures from a raw resource. 按照用于Android OpenGL编程的示例代码,我从原始资源加载纹理。
eg., 例如。,
// Create a texture handle
int[] texArray = new int[1];
GLES20.glGenTextures(1, texArray, 0);
int textureID = texArray[0];
// Bind the texture and configure parameters
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureID);
GLES20.glTexParameterf(etc...);
// Open the image resource as a stream
InputStream is = resources.openRawResource(R.raw.sometexture);
// Read the stream into a bitmap
Bitmap bitmap = BitmapFactory.decodeStream(is);
// Load the bitmap into GL
GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, bitmap, 0);
bitmap.recycle();
is.close();
(My actual code does have error checking etc...) (我的实际代码确实有错误检查等...)
This is loading a bitmap from a PNG file stored in res/raw/sometexture.png 这是从存储在res / raw / sometexture.png中的PNG文件加载位图
How do I load an image based on the current display density? 如何根据当前显示密度加载图像? I assume that I would put the images into the various res/drawable-??dpi folders, but then not sure how to load them!
我假设我会将图像放入各种res / drawable-?? dpi文件夹中,但不确定如何加载它们!
Apparently, I can use 显然,我可以使用
BitmapFactory.decodeResource(getResources(), R.drawable.sometexture);
and that will load an image from the best available option of the drawable-??dpi folder under /res/. 并从/ res /下的drawable-?? dpi文件夹的最佳可用选项中加载图像。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.