How to get a Rectangle for a BitmapFactory. Something like this a.getRectangle, where a is a BitmapFactory. As a result, you need to earn in this line of code

if (Rect.intersects (a.getRectangle (), b.getRectangle ()))

    1 answer 1

    1. BitmapFactory allows you to get an image from a file or stream.
    2. Therefore, you need to put the resulting image into a container through which you can get the necessary data about the rectangle into which this image will fit.
    3. Bitmap bitmap = BitmapFactory.decodeStream(inputStream);
    4. With the received Bitmap instance (let's call it bitmap), you can already do something.
    5. bitmap.getHeight , bitmap.getWidth - height and width of the bitmap.
    6. You can build an instance of Rect based on these parameters. (Rect(int left, int top, int right, int bottom) , where left = 0, top = 0, right = bitmap.getWidth , bottom = bitmap.getHeight )
    7. Therefore, we simply make a method that accepts a Bitmap as input and produces a Rectangle (Rect getBitmapRectangle(Bitmap bitmap)) at the output Rectangle (Rect getBitmapRectangle(Bitmap bitmap)) .
    8. Apply: if(Rect.intersects(getBitmapRectangle(a.decodeStream(inputStream1)),getBitmapRectangle(b.decodeStream(inputStream2)))...
    • why does he swear at inputStream? - En1q0d
    • inputStream1 and inputStream2 are most likely not defined in your application. Typically, InputStream instances are created like this: InputStream inputStream = assetManager.open ("cat.png"); In your case, I believe, it is necessary to transfer the flow thus opened to the factory. - DimXenon