Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9123951
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T06:27:44+00:00 2026-06-17T06:27:44+00:00

I have a bitmap image that I’m trying to do a hit test on.

  • 0

I have a bitmap image that I’m trying to do a hit test on. The hit test works if its just a normal bitmap. But I need to rotate and scale the bitmap and I just can’t seem to figure out the hit test properly.

x and y here are the cursor x and y. I need to check if the cursor (finger press) was clicked inside the manipulated bitmap. The scale seems to work fine, but the rotation doesn’t seem to take affect.

float[] pts = new float[4];
float left = m.getX();
float top = m.getY();
float right = left + mBitmaps.get(i).getWidth();
float bottom = top + mBitmaps.get(i).getHeight();
pts[0] = left;
pts[1] = top;
pts[2] = right;
pts[3] = bottom;

float midx = left + mBitmaps.get(i).getWidth()/2;
float midy = top + mBitmaps.get(i).getHeight()/2;

Matrix matrix = new Matrix();
matrix.setRotate(m.getRotation(), midx, midy);
matrix.setScale(m.getSize(), m.getSize(), midx, midy);

matrix.mapPoints(pts);

if(x >= pts[0] && x <= pts[2] && y >= pts[1] && y <= pts[3])
{
    return i;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T06:27:45+00:00Added an answer on June 17, 2026 at 6:27 am

    Your test fails because after rotation the rectangle is no longer aligned to the coordinate axes.

    A trick you can do is to transform the cursor position back with the inverse transformation matrix and then compare the transformed position with the original rectangle.

    Matrix matrix = new Matrix();
    matrix.setRotate(m.getRotation(), midx, midy);
    matrix.postScale(m.getSize(), m.getSize(), midx, midy);
    
    Matrix inverse = new Matrix();
    matrix.invert(inverse);
    pts[0] = x;
    pts[1] = y;
    inverse.mapPoints(pts);
    if(pts[1] >= top && pts[1] <= bottom && pts[0] >= left && pts[0] <= right)
    {
        return i;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a bitmap image that I am parsing and I need to be
I have a image/bitmap (I can make it either) in c++ that I need
I have a Base64 String that represents a BitMap image. I need to transform
I am trying to use the Notification.Builder.setLargeIcon(bitmap) that takes a bitmap image. I have
I have a PNG image that has an unsupported bitmap graphics context pixel format.
I have a canvas that has a bitmap image of a document and several
I am trying to extract the palette from a 5-6-5 (16bit) bitmap image that
In my project I have an bitmap image. I need to convert this picture
I am Trying to add an image to an existing button..I have done that
I have created a custom control that will have a bitmap image in it.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.