简体   繁体   中英

read pixel value from png android

I am reading png to extract pixel RGB by using the following code

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.

Is there a way to avoid loading png as BitmapFactory and still extract pixel 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. The png was part of map (app shows a map), thus, was also being displayed on the map as well. So I did the following

  1. When user clicks the map, I converted latitude and longitude to pixel xy
  2. Instead of converting the whole png into Bitmap, I take screen shot of screen.
  3. I convert screen short image into bitmap and extract pixel values at xy location.

Since the screen short image is much smaller than the complete png, the solution is working fine.

thanks every one for help.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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