简体   繁体   English

从png android读取像素值

[英]read pixel value from png android

I am reading png to extract pixel RGB by using the following code 我正在读取png以使用以下代码提取像素RGB

String filePath="map.png";

InputStream instream;


try {
        instream = assetManager.open(filePath);
        bMap = BitmapFactory.decodeStream(istr);


} catch (IOException e) {
      // handle exception
}   

The code works fine but when png is converted into BitMap, the bmap object size is too large (png=700kb , bmap=30MB+), thus, application crashes. 该代码可以正常工作,但是当png转换为BitMap时,bmap对象的大小太大(png = 700kb,bmap = 30MB +),因此,应用程序崩溃。

Is there a way to avoid loading png as BitmapFactory and still extract pixel RGB. 有没有一种方法可以避免将png加载为BitmapFactory并仍然提取像素RGB。

Thanks for the help. 谢谢您的帮助。

Thanks for the comments every one. 感谢您的评论。

I finally managed to solve it by using an other technique. 我终于设法通过使用其他技术来解决它。 The issue was that my png size was too big thus when converted to Bitmap the app was crashing. 问题是我的png大小太大,因此当转换为Bitmap时,应用程序崩溃了。 The png was part of map (app shows a map), thus, was also being displayed on the map as well. png是地图的一部分(应用程序显示地图),因此也在地图上也显示。 So I did the following 所以我做了以下

  1. When user clicks the map, I converted latitude and longitude to pixel xy 当用户单击地图时,我将纬度和经度转换为像素xy
  2. Instead of converting the whole png into Bitmap, I take screen shot of screen. 我没有将整个png转换为Bitmap,而是截取了screen的屏幕快照。
  3. I convert screen short image into bitmap and extract pixel values at xy location. 我将屏幕短图像转换为位图,并在xy位置提取像素值。

Since the screen short image is much smaller than the complete png, the solution is working fine. 由于屏幕短图像比完整的png小得多,因此该解决方案可以正常工作。

thanks every one for help. 谢谢大家的帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM