大绘制JPG图片的问题 [英] problems with big drawable jpg image

查看:385
本文介绍了大绘制JPG图片的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一两天期间,我一直在这里看着,在许多岗位在互联网上的一个问题IM解决方案上具有装载或移动的大JPG图片(位于由现在绘制reource),我认为它的时间问自己altought有许多问题和解决方案非常相关的。

during a couple of days i've been looking here and on the Internet in many post for a solution on an issue im having loading or moving a large jpg image (located as a drawable reource by now) and I think it's time to ask myself altought there are many questions and solutions very related.

我正在开发一个三维地形模拟与OpenGL和问题是,我使用的地形纹理相当大的JPG格式(2048×2048 = 1.94 MB)。

I'm developing a 3D terrain simulation with OpenGL and the problem is that I'm using as terrain texture a quite large jpg image ( 2048x2048 = 1,94 MB ).

让我们来看看一些workarround我所做的:

Let's look at some workarround I Did:

1

Bitmap terrainBitmap = BitmapFactory.decodeResource(getResources(),
R.drawable.terrain, options);

这一次崩溃inmediately,可能是因为图片太大

This one crashes inmediately, probably because the image is too big

2日:

Uri path = Uri.parse("android.resource://com.jgc.my_app/" + R.drawable.terrain);
URL ulrn;ulrn = new URL(path.getPath());
HttpURLConnection con = (HttpURLConnection)ulrn.openConnection();
InputStream is = con.getInputStream();
Bitmap bmp = BitmapFactory.decodeStream(is);

,一个可能是相当愚蠢的尝试

that one probably was a quite silly attempt

3

Bitmap terrainBitmap = BitmapFactory.decodeFile("android.resource://com.jgc.my_app/terrain.jpg", options);

但我发现了一个非常令人沮丧的空位图作为结果...

but I'm getting a very frustrating null bitmap as result...

在考虑到其他workarrounds是,因为绘制资源是内部的应用程序,为什么不将它们移动到SD卡和德codeFile的形式出现,但是,鉴于移动位图或绘制的解决方案到我发现总是用户BitmapFactory.de codeResource(getResources(),R.drawable.terrain,期权)的SD卡;

Other workarrounds in mind are, as the drawable resources are "inside" the application, why not to move them to the sd card and decodefile form there, but, the solutions given to move a bitmap or a drawable to the sdcard that I've found always user BitmapFactory.decodeResource(getResources(), R.drawable.terrain, options);

我AP preciate任何建议,从那时起,我将在我的proyect合作角落找寻其他任务。

I appreciate any suggestion, since then I'll be working arround other tasks in my proyect.

在此先感谢

推荐答案

好吧,也许我很幸运,这里是n个工作IND角落找寻这workd对我来说:

Ok, maybe I've been lucky, here is the n work-arround ind this workd for me:

private static BitmapFactory.Options terrainBitmapOptions = new BitmapFactory.Options();

...

// Set our bitmaps to 16-bit, 565 format.
    terrainBitmapOptions.inPreferredConfig = Bitmap.Config.RGB_565;

...

InputStream is = getResources().openRawResource(R.drawable.terrain);
Bitmap terrainBitmap;
try {
    terrainBitmap = BitmapFactory.decodeStream(is, null, terrainBitmapOptions);
} finally {
    try {
        is.close();
        } catch (IOException e) {
        // Ignore.
    }
}

我希望它可以帮助别人...

I hope it helps anyone else...

这篇关于大绘制JPG图片的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆