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 8356245
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T10:07:47+00:00 2026-06-09T10:07:47+00:00

I am a newbie in android and i am making a simple app in

  • 0

I am a newbie in android and i am making a simple app in which i select an image from the gallery, a rectangle is drawn on the image which the user can drag at any position on the image and re-size the rectangle dynamically.

My code up-till now can load an image from the gallery and draw a rectangle on the image. But i don’t know how to go about making the rectangle dragable dynamically.

public class MainActivity extends Activity   {
private static int RESULT_LOAD_IMAGE = 1;


@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    Button buttonLoadImage = (Button) findViewById(R.id.buttonLoadPicture);
    buttonLoadImage.setOnClickListener(new View.OnClickListener() {

        public void onClick(View arg0) {

            Intent i = new Intent(
                    Intent.ACTION_PICK,
                    android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);

            startActivityForResult(i, RESULT_LOAD_IMAGE);
        }
    });
}



@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK && null != data) {
        Uri selectedImage = data.getData();
        String[] filePathColumn = { MediaStore.Images.Media.DATA };

        Cursor cursor = getContentResolver().query(selectedImage,
                filePathColumn, null, null, null);
        cursor.moveToFirst();

        int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
        String picturePath = cursor.getString(columnIndex);
        cursor.close();

        ImageView imageView = (ImageView) findViewById(R.id.imgView);
        Bitmap bMap = BitmapFactory.decodeFile(picturePath);

        bMap = bMap.copy(Bitmap.Config.ARGB_8888 , true);

        float width = imageView.getWidth();
        float height = imageView.getHeight();

        Canvas canvas = new Canvas(bMap);
        Paint paint = new Paint();
        paint.setAntiAlias(true);
        paint.setStyle(Paint.Style.STROKE);
        paint.setStrokeWidth(4);  
        paint.setColor(Color.RED);
        canvas.drawRect(width/2+60, height/2-20, width/2-60, height/2+20, paint);

        imageView.setImageBitmap(bMap);

    }


}

}

Output

The output i want is something like in the above picture. The red rectangle can be resized and dragged by the user and then save the image.

  • 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-09T10:07:50+00:00Added an answer on June 9, 2026 at 10:07 am

    You’ll need to create a custom view that represents the rectangle you drew. In the onDraw(...) you can set the Paint of the rectangle and it’s initial size. Now the concept is, that when it is touched on it’s corners and dragged, the x and y coordinates of the rectangle will change when the user lifts their finger(s) from the screen. I will refer you to this on the Android Developer Guide on how to create a custom view. And this is a similar question post on here that may give you some ideas.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am newbie in android, in my android app, a main Activity class, which
I am making a simple app to learn Android at the same time, I
I am developing an Android app which takes the current location of the user
Scala/Android newbie question. I'm trying to rewrite this simple code from Java to Scala.
I'm a newbie with Android dev. I have a simple learning app with a
I am a newbie to Android development. I am writing an app for my
I am a newbie to android development and am trying to develop a simple
I have the following thing to achieve in Android(newbie). I have an xml which
I am newbie in android. I had planned to develop an application which divides
I am a newbie to android app development. I want to customize my android

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.