我需要创建一个位图并将其作为纹理加载(在程序中创建一个位图,制作一些图纸,然后将其绑定到纹理)
从文件系统加载位图就像这样
private int images[] = {
R.drawable.one,
R.drawable.two,
R.drawable.six,
R.drawable.five,
R.drawable.three,
R.drawable.four,
};
我的loadTexture functoin看起来像这样
public void loadGLTexture(GL10 gl, Context context) {
// Generate texture pointer
gl.glGenTextures(images.length, textures, 0);
for (int image = 0; image < images.length; image++) {
// bind texture pointer
gl.glBindTexture(GL10.GL_TEXTURE_2D, textures[image]);
// create nearest filtered texture
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR);
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR);
// different possible texture parameters, e.g. GL10.GL_CLAMP_TO_EDGE
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S, GL10.GL_REPEAT);
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T, GL10.GL_REPEAT);
// get the texture from the Android resource directory
{
InputStream is = context.getResources().openRawResource(images[image]);
Bitmap bitmap = null;
try {
// BitmapFactory is an Android graphics utility for images
bitmap = BitmapFactory.decodeStream(is);
} finally {
try {
// Always clear and close
is.close();
is = null;
} catch (IOException e) {
}
}
// use Android GLUtils to specify a 2D texture image from our bitmap
GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap, 0);
// cleanup
bitmap.recycle();
}
}
最后我有一个绘制画布并将其保存在位图中的功能。 (现在它只有一个)我想知道如何将创建的位图应用于图像数组。
public Bitmap onDraw( Canvas canvas) {
Paint paint = new Paint();
canvas.drawColor(Color.BLUE);
Bitmap one = Bitmap.createBitmap(256, 256, Bitmap.Config.RGB_565);
Canvas c = new Canvas(one);
canvas.drawRect(0, 0, 256, 256, paint);
paint.setTextSize(40);
paint.setTextScaleX(1.f);
paint.setAntiAlias(true);
canvas.drawText("Your text", 30, 40, paint);
paint.setColor(Color.RED);
return one;
}
如何将位图加载到int []数组?
谢谢