如何在每个像素中创建包含信息的位图?(How to create a bitmap with information in every pixel?)

编程入门 行业动态 更新时间:2024-10-27 18:30:42
如何在每个像素中创建包含信息的位图?(How to create a bitmap with information in every pixel?)

我正在Android上创建一个谷歌地图应用程序,我面临着问题。 我有文本格式的高程数据。 看起来像这样

longtitude latitude elevation 491222 163550 238.270000 491219 163551 242.130000 etc.

此高程信息存储在10x10米的网格中。 这意味着每10米就是一个高程值。 这个文本太大,以至于我可以在那里找到我需要的信息,所以我想用这些信息创建一个位图。

我需要做的是在某个时刻扫描我所在位置的高程。 可以有很多要扫描的点,所以我想快速完成。 这就是为什么我在考虑位图。

我不知道它是否可能,但我的想法是,我的文本网格的大小会有位图,并且每个像素都会有关于高程的信息。 所以它应该像根据坐标放置在地图上的谷歌地图上的隐形地图,当我需要了解我的位置的高程时,我只看这些像素并读取高程值。

你认为有可能创建这样的位图吗? 我有这个想法,但不知道如何实现它。 例如,如何在其中存储高程信息,如何阅读,如何创建位图..我将非常感谢您可以给我的每一个建议,方向,来源。 非常感谢!

I'm creating a google maps application on Android and I'm facing problem. I have elevation data in text format. It looks like this

longtitude latitude elevation 491222 163550 238.270000 491219 163551 242.130000 etc.

This elevation information is stored in grid of 10x10 meters. It means that for every 10 meters is an elevation value. This text is too large so that I could find there the information I need so I would want to create a bitmap with this information.

What I need to do is in certain moment to scan the elevation around my location. There can be a lot of points to be scanned so I want to make it quick. That's why I'm thinking about the bitmap.

I don't know if it's even possible but my idea is that there would be a bitmap of size of my text grid and in every pixel would be information about the elevation. So it should be like invisible map over the google map placed in the place according to coordinates and when I need to learn the elevation about my location, I would just look at these pixels and read the value of elevation.

Do you think that is possible to create such a bitmap? I have just this idea but no idea how to implement it. Eg how to store in it the elevation information, how to read that back, how to create the bitmap.. I would be very grateful for every advice, direction, source which you can give me. Thank you so much!

最满意答案

BufferedImage在android中不可用,但可以使用android.graphics.Bitmap 。 位图必须以无损格式保存(例如PNG)。

double[] elevations={238.27,242.1301,222,1}; int[] pixels = doublesToInts(elevations); //encoding Bitmap bmp=Bitmap.createBitmap(2, 2, Config.ARGB_8888); bmp.setPixels(pixels, 0, 2, 0, 0, 2, 2); File file=new File(getCacheDir(),"bitmap.png"); try { FileOutputStream fos = new FileOutputStream(file); bmp.compress(CompressFormat.PNG, 100, fos); fos.close(); } catch (IOException e) { e.printStackTrace(); } //decoding Bitmap out=BitmapFactory.decodeFile(file.getPath()); if (out!=null) { int [] outPixels=new int[out.getWidth()*out.getHeight()]; out.getPixels(outPixels, 0, out.getWidth(), 0, 0, out.getWidth(), out.getHeight()); double[] outElevations=intsToDoubles(outPixels); } static int[] doublesToInts(double[] elevations) { int[] out=new int[elevations.length]; for (int i=0;i<elevations.length;i++) { int tmp=(int) (elevations[i]*1000000); out[i]=0xFF000000|tmp>>8; } return out; } static double[] intsToDoubles(int[] pixels) { double[] out=new double[pixels.length]; for (int i=0;i<pixels.length;i++) out[i]=(pixels[i]<<8)/1000000.0; return out; }

BufferedImage is not available in android but android.graphics.Bitmap can be used. Bitmap must be saved in lossless format (eg. PNG).

double[] elevations={238.27,242.1301,222,1}; int[] pixels = doublesToInts(elevations); //encoding Bitmap bmp=Bitmap.createBitmap(2, 2, Config.ARGB_8888); bmp.setPixels(pixels, 0, 2, 0, 0, 2, 2); File file=new File(getCacheDir(),"bitmap.png"); try { FileOutputStream fos = new FileOutputStream(file); bmp.compress(CompressFormat.PNG, 100, fos); fos.close(); } catch (IOException e) { e.printStackTrace(); } //decoding Bitmap out=BitmapFactory.decodeFile(file.getPath()); if (out!=null) { int [] outPixels=new int[out.getWidth()*out.getHeight()]; out.getPixels(outPixels, 0, out.getWidth(), 0, 0, out.getWidth(), out.getHeight()); double[] outElevations=intsToDoubles(outPixels); } static int[] doublesToInts(double[] elevations) { int[] out=new int[elevations.length]; for (int i=0;i<elevations.length;i++) { int tmp=(int) (elevations[i]*1000000); out[i]=0xFF000000|tmp>>8; } return out; } static double[] intsToDoubles(int[] pixels) { double[] out=new double[pixels.length]; for (int i=0;i<pixels.length;i++) out[i]=(pixels[i]<<8)/1000000.0; return out; }

更多推荐

本文发布于:2023-08-05 20:14:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1439483.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:位图   像素   在每个   信息   information

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!