Search code examples
androidbitmapcoordinatesresolutionpixel

Via math formula get coords(pixels) of Low Resolution Bitmap and Put them into same location to High Resolution bitmap Android


So i making image from camera,via native API. The problem is that,i also have an algorithms to compute some stuff(with bitmap) and problem comes,when resolution is too high(for e.g. 3000x2500),because i need wait too much time.

So first what comes in my mind,its like a workaround:

  1. Convert from source bitmap to low-resolution(for e.g. 600x800).
  2. Work with this low-resolution bitmap(computing some stuff and calculate coords,that are located on this low-resolution bitmap).
  3. Get exact pixel coords and via some Math formula(that calculates width/heights or pixels?) put them into same place,but on source bitmap(with high resolution).

So how can i achieve this part? I think it's possible,but cant understand what exactly need to do.
Thanks!


Solution

  • OK, that is what you need

    assuming you have computed some x, y values for you low res image:

    int lowResX, lowResY;
    

    Than for converting them to the hi res:

    double scaleRatio = hiResImageWidth / lowResImageWidth; //be sure to use here double or float values as the result of integer division will be int, and not the double/float!
    int hiResX = (int) (lowResX * scaleRatio);
    int hiResY = (int) (lowResY * scaleRatio);
    

    That's all