LibGdx中使用非2的N次幂尺寸的图片
来源:互联网 发布:jquery遍历json的顺序 编辑:程序博客网 时间:2024/05/17 23:11
Libgdx关于载入图片规格的问题
对于libgdx来说,对载入的图片要求是:宽高都必须是2的N次幂的图片才行,否则会提示:texture width and height must be powers of two。
那么,如何使用非2的N次幂尺寸的图片呢,使用以下函数:
import com.badlogic.gdx.graphics.Pixmap;import com.badlogic.gdx.graphics.Pixmap.Format;import com.badlogic.gdx.graphics.Texture;
// 如工程目录assets/texture/001.png下: filePath = "texture/001.png"/** 载入任意尺寸的图像,创建Texture */public static Texture loadTexture(String filePath){Pixmap pic = new Pixmap(Gdx.files.internal(filePath));pic = Format2power(pic);// 图像尺寸转化为2的幂return new Texture(pic);// 从Pixmap构建Texture}/** 将Pic转化为尺寸为2的幂的图像 */public static Pixmap Format2power(Pixmap Pic){int width = Pic.getWidth(), height = Pic.getHeight();// 获取图像的尺寸Pixmap image = new Pixmap(closestTwoPower(width), closestTwoPower(height), Format.RGBA8888);if (image.getWidth() == width && image.getHeight() == height) return image;// 若原图像尺寸为2的幂,则直接返回原图像int color;for (int i = 0; i < width; i++){for (int j = 0; j < height; j++){color = Pic.getPixel(i, j);// 原图像像素信息image.drawPixel(i, j, color);// 生成图像}}return image;}/** 获取最接近于n的2的幂 */public static int closestTwoPower(int n){int power = 1;while (power < n)power <<= 1;return power;}
0 0
- LibGdx中使用非2的N次幂尺寸的图片
- Android 应用非2的N次幂纹理
- 2的n次幂
- 2 的 n 次幂
- libgdx中tilemap的使用
- 【OpenGL ES 2.0】如何显示出非2的N次幂的贴图。(NPOT)
- libgdx图片整合工具TexturePacker的使用
- libgdx: 打包图片.atlas文件的使用
- 判断一个非负整数是否为2的n次幂?-by大彬
- 计算2的n次幂
- 2的N次幂表示
- libGDX中Stage,Actor,Action的使用
- libgdx中BitmapFont字体的使用
- 大数的N次幂
- r的n次幂
- x的n次幂
- 10 的 n 次幂
- 整数的n次幂
- 点阵字库的显示原理
- http post get请求
- RESTful API 设计指南
- MAVEN: Error assembling WAR: webxml attribute is required
- 关于EntityFramework在vs2012无法引用的问题
- LibGdx中使用非2的N次幂尺寸的图片
- python -_csv.Error: line contains NULL byte
- android对系统日历的读写操作开发经验的总结
- 让外网访问内网网站,TUNNEL比花生壳更快
- HDU 1754
- C++ virtural关键字和虚析构函数作用
- 处理Selection对象和Range对象——Word VBA中重要的两个对象
- 可信认证网站
- spring与mybatis三种整合方法