Drawing a circle on ImageView2 in same coordinates as ImageView1 if i tap a place in ImageView1 and Vice...





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







4















I'm trying to make find the difference game app, but I never made anything like that and since I'm a new to development I'm stuck



well baby Steps are always needed to learn xD



I read in some documentation that i have to get each ImageView height and width separately so when i touch imageView1 its coordinates can be set to ImageVIew2 and ViceVersa I MAYBE BE WRONG XD



Right now I have a layout with 2 Images set vertically



<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".PlayActivity"
android:id="@+id/hello1">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="@+id/hello">

<ImageView
android:id="@+id/image1"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="@drawable/pic_9" />

<ImageView
android:id="@+id/image2"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="@drawable/pic_9a" />

</LinearLayout>




What i want to do is if i tap a place in image1 a circle should be created on the same place in image2



after reading along a few things i have made a circle if i tap the layout but i am stuck after this i cant find what to do next maybe i cant find documentation related to my problems



public class PlayActivity extends AppCompatActivity {

RelativeLayout layout;
float x = 0;
float y = 0;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_play);

layout=(RelativeLayout) findViewById(R.id.hello1);
layout.addView(new CustomView(PlayActivity.this));

}

public class CustomView extends View {

Bitmap mBitmap;
Paint paint;

public CustomView(Context context) {
super(context);
mBitmap = Bitmap.createBitmap(400, 800, Bitmap.Config.ARGB_8888);
paint = new Paint();
paint.setColor(Color.RED);
paint.setStyle(Paint.Style.FILL);
}

@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
canvas.drawCircle(x, y, 50, paint);
}

public boolean onTouchEvent(MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
x = event.getX();
y = event.getY();
invalidate();
}
return false;
}
}}


Right now i think my two ImageView arent separate because when i touch between the 2 images a circle is created which shouldn't since imageView1 ends im not sure if im thinking in right direction its just my guess on how should it work for the game to work I MAYBE BE WRONG XD



See the circle is created even between 2 images



I still have a long way to go, but I'm stuck here

can anyone help?



I replaced my PlayActivity code using Tejas Pandya



RelativeLayout layout;
float x = 0;
float y = 0;
ImageView ImageView1, ImageView2;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_play);

layout=(RelativeLayout) findViewById(R.id.hello1);
layout.addView(new CustomView(PlayActivity.this));

ImageView1 = (ImageView) findViewById(R.id.image1);
ImageView2 = (ImageView) findViewById(R.id.image2);

}

public class CustomView extends View {


public CustomView(Context context) {
super(context);
}

public boolean onTouchEvent(MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
x = event.getX();
y = event.getY();
invalidate();
drawCircle(R.id.image2,ImageView2,x,y);
}
return false;
}

public void drawCircle(int my_image_id, ImageView my_imageview, float x , float y){

BitmapFactory.Options myOptions = new BitmapFactory.Options();
myOptions.inDither = true;
myOptions.inScaled = false;
myOptions.inPreferredConfig = Bitmap.Config.ARGB_8888;// important
myOptions.inPurgeable = true;

Bitmap bitmap = BitmapFactory.decodeResource(getResources(), my_image_id,myOptions);
Paint paint = new Paint();
paint.setAntiAlias(true);
paint.setColor(Color.BLUE);


Bitmap workingBitmap = Bitmap.createBitmap(bitmap);
Bitmap mutableBitmap = workingBitmap.copy(Bitmap.Config.ARGB_8888, true);


Canvas canvas = new Canvas(mutableBitmap);
canvas.drawCircle(x, y, 25, paint);


my_imageview.setAdjustViewBounds(true);
my_imageview.setImageBitmap(mutableBitmap);

}
}


and i get this error




E/MessageQueue-JNI: java.lang.NullPointerException: Attempt to invoke virtual method 'int android.graphics.Bitmap.getWidth()' on a null object reference
at android.graphics.Bitmap.createBitmap(Bitmap.java:742)
at com.example.pc.blazedifferencegame.PlayActivity$CustomView.drawCircle(PlayActivity.java:68)
at com.example.pc.blazedifferencegame.PlayActivity$CustomView.onTouchEvent(PlayActivity.java:49)











share|improve this question































    4















    I'm trying to make find the difference game app, but I never made anything like that and since I'm a new to development I'm stuck



    well baby Steps are always needed to learn xD



    I read in some documentation that i have to get each ImageView height and width separately so when i touch imageView1 its coordinates can be set to ImageVIew2 and ViceVersa I MAYBE BE WRONG XD



    Right now I have a layout with 2 Images set vertically



    <RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".PlayActivity"
    android:id="@+id/hello1">

    <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:id="@+id/hello">

    <ImageView
    android:id="@+id/image1"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1"
    android:background="@drawable/pic_9" />

    <ImageView
    android:id="@+id/image2"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1"
    android:background="@drawable/pic_9a" />

    </LinearLayout>




    What i want to do is if i tap a place in image1 a circle should be created on the same place in image2



    after reading along a few things i have made a circle if i tap the layout but i am stuck after this i cant find what to do next maybe i cant find documentation related to my problems



    public class PlayActivity extends AppCompatActivity {

    RelativeLayout layout;
    float x = 0;
    float y = 0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_play);

    layout=(RelativeLayout) findViewById(R.id.hello1);
    layout.addView(new CustomView(PlayActivity.this));

    }

    public class CustomView extends View {

    Bitmap mBitmap;
    Paint paint;

    public CustomView(Context context) {
    super(context);
    mBitmap = Bitmap.createBitmap(400, 800, Bitmap.Config.ARGB_8888);
    paint = new Paint();
    paint.setColor(Color.RED);
    paint.setStyle(Paint.Style.FILL);
    }

    @Override
    protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    canvas.drawCircle(x, y, 50, paint);
    }

    public boolean onTouchEvent(MotionEvent event) {
    if (event.getAction() == MotionEvent.ACTION_DOWN) {
    x = event.getX();
    y = event.getY();
    invalidate();
    }
    return false;
    }
    }}


    Right now i think my two ImageView arent separate because when i touch between the 2 images a circle is created which shouldn't since imageView1 ends im not sure if im thinking in right direction its just my guess on how should it work for the game to work I MAYBE BE WRONG XD



    See the circle is created even between 2 images



    I still have a long way to go, but I'm stuck here

    can anyone help?



    I replaced my PlayActivity code using Tejas Pandya



    RelativeLayout layout;
    float x = 0;
    float y = 0;
    ImageView ImageView1, ImageView2;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_play);

    layout=(RelativeLayout) findViewById(R.id.hello1);
    layout.addView(new CustomView(PlayActivity.this));

    ImageView1 = (ImageView) findViewById(R.id.image1);
    ImageView2 = (ImageView) findViewById(R.id.image2);

    }

    public class CustomView extends View {


    public CustomView(Context context) {
    super(context);
    }

    public boolean onTouchEvent(MotionEvent event) {
    if (event.getAction() == MotionEvent.ACTION_DOWN) {
    x = event.getX();
    y = event.getY();
    invalidate();
    drawCircle(R.id.image2,ImageView2,x,y);
    }
    return false;
    }

    public void drawCircle(int my_image_id, ImageView my_imageview, float x , float y){

    BitmapFactory.Options myOptions = new BitmapFactory.Options();
    myOptions.inDither = true;
    myOptions.inScaled = false;
    myOptions.inPreferredConfig = Bitmap.Config.ARGB_8888;// important
    myOptions.inPurgeable = true;

    Bitmap bitmap = BitmapFactory.decodeResource(getResources(), my_image_id,myOptions);
    Paint paint = new Paint();
    paint.setAntiAlias(true);
    paint.setColor(Color.BLUE);


    Bitmap workingBitmap = Bitmap.createBitmap(bitmap);
    Bitmap mutableBitmap = workingBitmap.copy(Bitmap.Config.ARGB_8888, true);


    Canvas canvas = new Canvas(mutableBitmap);
    canvas.drawCircle(x, y, 25, paint);


    my_imageview.setAdjustViewBounds(true);
    my_imageview.setImageBitmap(mutableBitmap);

    }
    }


    and i get this error




    E/MessageQueue-JNI: java.lang.NullPointerException: Attempt to invoke virtual method 'int android.graphics.Bitmap.getWidth()' on a null object reference
    at android.graphics.Bitmap.createBitmap(Bitmap.java:742)
    at com.example.pc.blazedifferencegame.PlayActivity$CustomView.drawCircle(PlayActivity.java:68)
    at com.example.pc.blazedifferencegame.PlayActivity$CustomView.onTouchEvent(PlayActivity.java:49)











    share|improve this question



























      4












      4








      4


      1






      I'm trying to make find the difference game app, but I never made anything like that and since I'm a new to development I'm stuck



      well baby Steps are always needed to learn xD



      I read in some documentation that i have to get each ImageView height and width separately so when i touch imageView1 its coordinates can be set to ImageVIew2 and ViceVersa I MAYBE BE WRONG XD



      Right now I have a layout with 2 Images set vertically



      <RelativeLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:app="http://schemas.android.com/apk/res-auto"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      tools:context=".PlayActivity"
      android:id="@+id/hello1">

      <LinearLayout
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:orientation="vertical"
      android:id="@+id/hello">

      <ImageView
      android:id="@+id/image1"
      android:layout_width="match_parent"
      android:layout_height="0dp"
      android:layout_weight="1"
      android:background="@drawable/pic_9" />

      <ImageView
      android:id="@+id/image2"
      android:layout_width="match_parent"
      android:layout_height="0dp"
      android:layout_weight="1"
      android:background="@drawable/pic_9a" />

      </LinearLayout>




      What i want to do is if i tap a place in image1 a circle should be created on the same place in image2



      after reading along a few things i have made a circle if i tap the layout but i am stuck after this i cant find what to do next maybe i cant find documentation related to my problems



      public class PlayActivity extends AppCompatActivity {

      RelativeLayout layout;
      float x = 0;
      float y = 0;

      @Override
      protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_play);

      layout=(RelativeLayout) findViewById(R.id.hello1);
      layout.addView(new CustomView(PlayActivity.this));

      }

      public class CustomView extends View {

      Bitmap mBitmap;
      Paint paint;

      public CustomView(Context context) {
      super(context);
      mBitmap = Bitmap.createBitmap(400, 800, Bitmap.Config.ARGB_8888);
      paint = new Paint();
      paint.setColor(Color.RED);
      paint.setStyle(Paint.Style.FILL);
      }

      @Override
      protected void onDraw(Canvas canvas) {
      super.onDraw(canvas);
      canvas.drawCircle(x, y, 50, paint);
      }

      public boolean onTouchEvent(MotionEvent event) {
      if (event.getAction() == MotionEvent.ACTION_DOWN) {
      x = event.getX();
      y = event.getY();
      invalidate();
      }
      return false;
      }
      }}


      Right now i think my two ImageView arent separate because when i touch between the 2 images a circle is created which shouldn't since imageView1 ends im not sure if im thinking in right direction its just my guess on how should it work for the game to work I MAYBE BE WRONG XD



      See the circle is created even between 2 images



      I still have a long way to go, but I'm stuck here

      can anyone help?



      I replaced my PlayActivity code using Tejas Pandya



      RelativeLayout layout;
      float x = 0;
      float y = 0;
      ImageView ImageView1, ImageView2;

      @Override
      protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_play);

      layout=(RelativeLayout) findViewById(R.id.hello1);
      layout.addView(new CustomView(PlayActivity.this));

      ImageView1 = (ImageView) findViewById(R.id.image1);
      ImageView2 = (ImageView) findViewById(R.id.image2);

      }

      public class CustomView extends View {


      public CustomView(Context context) {
      super(context);
      }

      public boolean onTouchEvent(MotionEvent event) {
      if (event.getAction() == MotionEvent.ACTION_DOWN) {
      x = event.getX();
      y = event.getY();
      invalidate();
      drawCircle(R.id.image2,ImageView2,x,y);
      }
      return false;
      }

      public void drawCircle(int my_image_id, ImageView my_imageview, float x , float y){

      BitmapFactory.Options myOptions = new BitmapFactory.Options();
      myOptions.inDither = true;
      myOptions.inScaled = false;
      myOptions.inPreferredConfig = Bitmap.Config.ARGB_8888;// important
      myOptions.inPurgeable = true;

      Bitmap bitmap = BitmapFactory.decodeResource(getResources(), my_image_id,myOptions);
      Paint paint = new Paint();
      paint.setAntiAlias(true);
      paint.setColor(Color.BLUE);


      Bitmap workingBitmap = Bitmap.createBitmap(bitmap);
      Bitmap mutableBitmap = workingBitmap.copy(Bitmap.Config.ARGB_8888, true);


      Canvas canvas = new Canvas(mutableBitmap);
      canvas.drawCircle(x, y, 25, paint);


      my_imageview.setAdjustViewBounds(true);
      my_imageview.setImageBitmap(mutableBitmap);

      }
      }


      and i get this error




      E/MessageQueue-JNI: java.lang.NullPointerException: Attempt to invoke virtual method 'int android.graphics.Bitmap.getWidth()' on a null object reference
      at android.graphics.Bitmap.createBitmap(Bitmap.java:742)
      at com.example.pc.blazedifferencegame.PlayActivity$CustomView.drawCircle(PlayActivity.java:68)
      at com.example.pc.blazedifferencegame.PlayActivity$CustomView.onTouchEvent(PlayActivity.java:49)











      share|improve this question
















      I'm trying to make find the difference game app, but I never made anything like that and since I'm a new to development I'm stuck



      well baby Steps are always needed to learn xD



      I read in some documentation that i have to get each ImageView height and width separately so when i touch imageView1 its coordinates can be set to ImageVIew2 and ViceVersa I MAYBE BE WRONG XD



      Right now I have a layout with 2 Images set vertically



      <RelativeLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:app="http://schemas.android.com/apk/res-auto"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      tools:context=".PlayActivity"
      android:id="@+id/hello1">

      <LinearLayout
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:orientation="vertical"
      android:id="@+id/hello">

      <ImageView
      android:id="@+id/image1"
      android:layout_width="match_parent"
      android:layout_height="0dp"
      android:layout_weight="1"
      android:background="@drawable/pic_9" />

      <ImageView
      android:id="@+id/image2"
      android:layout_width="match_parent"
      android:layout_height="0dp"
      android:layout_weight="1"
      android:background="@drawable/pic_9a" />

      </LinearLayout>




      What i want to do is if i tap a place in image1 a circle should be created on the same place in image2



      after reading along a few things i have made a circle if i tap the layout but i am stuck after this i cant find what to do next maybe i cant find documentation related to my problems



      public class PlayActivity extends AppCompatActivity {

      RelativeLayout layout;
      float x = 0;
      float y = 0;

      @Override
      protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_play);

      layout=(RelativeLayout) findViewById(R.id.hello1);
      layout.addView(new CustomView(PlayActivity.this));

      }

      public class CustomView extends View {

      Bitmap mBitmap;
      Paint paint;

      public CustomView(Context context) {
      super(context);
      mBitmap = Bitmap.createBitmap(400, 800, Bitmap.Config.ARGB_8888);
      paint = new Paint();
      paint.setColor(Color.RED);
      paint.setStyle(Paint.Style.FILL);
      }

      @Override
      protected void onDraw(Canvas canvas) {
      super.onDraw(canvas);
      canvas.drawCircle(x, y, 50, paint);
      }

      public boolean onTouchEvent(MotionEvent event) {
      if (event.getAction() == MotionEvent.ACTION_DOWN) {
      x = event.getX();
      y = event.getY();
      invalidate();
      }
      return false;
      }
      }}


      Right now i think my two ImageView arent separate because when i touch between the 2 images a circle is created which shouldn't since imageView1 ends im not sure if im thinking in right direction its just my guess on how should it work for the game to work I MAYBE BE WRONG XD



      See the circle is created even between 2 images



      I still have a long way to go, but I'm stuck here

      can anyone help?



      I replaced my PlayActivity code using Tejas Pandya



      RelativeLayout layout;
      float x = 0;
      float y = 0;
      ImageView ImageView1, ImageView2;

      @Override
      protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_play);

      layout=(RelativeLayout) findViewById(R.id.hello1);
      layout.addView(new CustomView(PlayActivity.this));

      ImageView1 = (ImageView) findViewById(R.id.image1);
      ImageView2 = (ImageView) findViewById(R.id.image2);

      }

      public class CustomView extends View {


      public CustomView(Context context) {
      super(context);
      }

      public boolean onTouchEvent(MotionEvent event) {
      if (event.getAction() == MotionEvent.ACTION_DOWN) {
      x = event.getX();
      y = event.getY();
      invalidate();
      drawCircle(R.id.image2,ImageView2,x,y);
      }
      return false;
      }

      public void drawCircle(int my_image_id, ImageView my_imageview, float x , float y){

      BitmapFactory.Options myOptions = new BitmapFactory.Options();
      myOptions.inDither = true;
      myOptions.inScaled = false;
      myOptions.inPreferredConfig = Bitmap.Config.ARGB_8888;// important
      myOptions.inPurgeable = true;

      Bitmap bitmap = BitmapFactory.decodeResource(getResources(), my_image_id,myOptions);
      Paint paint = new Paint();
      paint.setAntiAlias(true);
      paint.setColor(Color.BLUE);


      Bitmap workingBitmap = Bitmap.createBitmap(bitmap);
      Bitmap mutableBitmap = workingBitmap.copy(Bitmap.Config.ARGB_8888, true);


      Canvas canvas = new Canvas(mutableBitmap);
      canvas.drawCircle(x, y, 25, paint);


      my_imageview.setAdjustViewBounds(true);
      my_imageview.setImageBitmap(mutableBitmap);

      }
      }


      and i get this error




      E/MessageQueue-JNI: java.lang.NullPointerException: Attempt to invoke virtual method 'int android.graphics.Bitmap.getWidth()' on a null object reference
      at android.graphics.Bitmap.createBitmap(Bitmap.java:742)
      at com.example.pc.blazedifferencegame.PlayActivity$CustomView.drawCircle(PlayActivity.java:68)
      at com.example.pc.blazedifferencegame.PlayActivity$CustomView.onTouchEvent(PlayActivity.java:49)








      android






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jan 8 at 9:09









      Md. Zakir Hossain

      586416




      586416










      asked Jan 3 at 10:56









      Ahsan razaAhsan raza

      237




      237
























          1 Answer
          1






          active

          oldest

          votes


















          0














          When You tape on Image . You are getting x,y coordinate in



           x = event.getX();
          y = event.getY();


          Now you have x,y coordinate . call your drawCircle() method on both of your imageview with this same x,y coordinate.



          For Drawing circle :



          make one function drawCircle();



          public void drawCircle(int my_image_id,Imageview my_imageview,int x ,int y){

          BitmapFactory.Options myOptions = new BitmapFactory.Options();
          myOptions.inDither = true;
          myOptions.inScaled = false;
          myOptions.inPreferredConfig = Bitmap.Config.ARGB_8888;// important
          myOptions.inPurgeable = true;

          Bitmap bitmap = BitmapFactory.decodeResource(getResources(), my_image_id,myOptions);
          Paint paint = new Paint();
          paint.setAntiAlias(true);
          paint.setColor(Color.BLUE);


          //please check here . you've got your bitmap or it is null.
          // if it is null,there might be some problem with decoding your resources above.
          Bitmap workingBitmap = Bitmap.createBitmap(bitmap);
          Bitmap mutableBitmap = workingBitmap.copy(Bitmap.Config.ARGB_8888, true);


          Canvas canvas = new Canvas(mutableBitmap);
          canvas.drawCircle(x, y, 25, paint);


          my_imageview.setAdjustViewBounds(true);
          my_imageview.setImageBitmap(mutableBitmap);

          }


          now for
          image 1 . use drawCircle(R.id.imageview1,imageview,x,y) and for
          image 2 . use drawCircle(R.id.imageview2,imageview2,x,y)






          share|improve this answer


























          • i tried to do that but it i think im doing it wrong since it draws circle on the same place in image1 and doesn't draw circle on image2

            – Ahsan raza
            Jan 3 at 11:56











          • @Ahsanraza i've updated my answer .

            – NullPointerException
            Jan 3 at 12:30











          • i tried it but it giving in error can you add this in my code and tell me how to use it maybe im doing it wrong

            – Ahsan raza
            Jan 5 at 20:09











          • @Ahsanraza whats the error you are getting ?

            – NullPointerException
            Jan 7 at 4:37











          • Please look above i edited my question I placed your code inside in PlayActivity i might have placed it wrong. I read in a documentation that you have to get width and height of each image view separately and somehow use it i dont know how. I have read many things in these few days and tried different things but i cant get it to work all i wanted to make was a simple game :'( maybe i picked the wrong game.

            – Ahsan raza
            Jan 8 at 6:57












          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54020941%2fdrawing-a-circle-on-imageview2-in-same-coordinates-as-imageview1-if-i-tap-a-plac%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          When You tape on Image . You are getting x,y coordinate in



           x = event.getX();
          y = event.getY();


          Now you have x,y coordinate . call your drawCircle() method on both of your imageview with this same x,y coordinate.



          For Drawing circle :



          make one function drawCircle();



          public void drawCircle(int my_image_id,Imageview my_imageview,int x ,int y){

          BitmapFactory.Options myOptions = new BitmapFactory.Options();
          myOptions.inDither = true;
          myOptions.inScaled = false;
          myOptions.inPreferredConfig = Bitmap.Config.ARGB_8888;// important
          myOptions.inPurgeable = true;

          Bitmap bitmap = BitmapFactory.decodeResource(getResources(), my_image_id,myOptions);
          Paint paint = new Paint();
          paint.setAntiAlias(true);
          paint.setColor(Color.BLUE);


          //please check here . you've got your bitmap or it is null.
          // if it is null,there might be some problem with decoding your resources above.
          Bitmap workingBitmap = Bitmap.createBitmap(bitmap);
          Bitmap mutableBitmap = workingBitmap.copy(Bitmap.Config.ARGB_8888, true);


          Canvas canvas = new Canvas(mutableBitmap);
          canvas.drawCircle(x, y, 25, paint);


          my_imageview.setAdjustViewBounds(true);
          my_imageview.setImageBitmap(mutableBitmap);

          }


          now for
          image 1 . use drawCircle(R.id.imageview1,imageview,x,y) and for
          image 2 . use drawCircle(R.id.imageview2,imageview2,x,y)






          share|improve this answer


























          • i tried to do that but it i think im doing it wrong since it draws circle on the same place in image1 and doesn't draw circle on image2

            – Ahsan raza
            Jan 3 at 11:56











          • @Ahsanraza i've updated my answer .

            – NullPointerException
            Jan 3 at 12:30











          • i tried it but it giving in error can you add this in my code and tell me how to use it maybe im doing it wrong

            – Ahsan raza
            Jan 5 at 20:09











          • @Ahsanraza whats the error you are getting ?

            – NullPointerException
            Jan 7 at 4:37











          • Please look above i edited my question I placed your code inside in PlayActivity i might have placed it wrong. I read in a documentation that you have to get width and height of each image view separately and somehow use it i dont know how. I have read many things in these few days and tried different things but i cant get it to work all i wanted to make was a simple game :'( maybe i picked the wrong game.

            – Ahsan raza
            Jan 8 at 6:57
















          0














          When You tape on Image . You are getting x,y coordinate in



           x = event.getX();
          y = event.getY();


          Now you have x,y coordinate . call your drawCircle() method on both of your imageview with this same x,y coordinate.



          For Drawing circle :



          make one function drawCircle();



          public void drawCircle(int my_image_id,Imageview my_imageview,int x ,int y){

          BitmapFactory.Options myOptions = new BitmapFactory.Options();
          myOptions.inDither = true;
          myOptions.inScaled = false;
          myOptions.inPreferredConfig = Bitmap.Config.ARGB_8888;// important
          myOptions.inPurgeable = true;

          Bitmap bitmap = BitmapFactory.decodeResource(getResources(), my_image_id,myOptions);
          Paint paint = new Paint();
          paint.setAntiAlias(true);
          paint.setColor(Color.BLUE);


          //please check here . you've got your bitmap or it is null.
          // if it is null,there might be some problem with decoding your resources above.
          Bitmap workingBitmap = Bitmap.createBitmap(bitmap);
          Bitmap mutableBitmap = workingBitmap.copy(Bitmap.Config.ARGB_8888, true);


          Canvas canvas = new Canvas(mutableBitmap);
          canvas.drawCircle(x, y, 25, paint);


          my_imageview.setAdjustViewBounds(true);
          my_imageview.setImageBitmap(mutableBitmap);

          }


          now for
          image 1 . use drawCircle(R.id.imageview1,imageview,x,y) and for
          image 2 . use drawCircle(R.id.imageview2,imageview2,x,y)






          share|improve this answer


























          • i tried to do that but it i think im doing it wrong since it draws circle on the same place in image1 and doesn't draw circle on image2

            – Ahsan raza
            Jan 3 at 11:56











          • @Ahsanraza i've updated my answer .

            – NullPointerException
            Jan 3 at 12:30











          • i tried it but it giving in error can you add this in my code and tell me how to use it maybe im doing it wrong

            – Ahsan raza
            Jan 5 at 20:09











          • @Ahsanraza whats the error you are getting ?

            – NullPointerException
            Jan 7 at 4:37











          • Please look above i edited my question I placed your code inside in PlayActivity i might have placed it wrong. I read in a documentation that you have to get width and height of each image view separately and somehow use it i dont know how. I have read many things in these few days and tried different things but i cant get it to work all i wanted to make was a simple game :'( maybe i picked the wrong game.

            – Ahsan raza
            Jan 8 at 6:57














          0












          0








          0







          When You tape on Image . You are getting x,y coordinate in



           x = event.getX();
          y = event.getY();


          Now you have x,y coordinate . call your drawCircle() method on both of your imageview with this same x,y coordinate.



          For Drawing circle :



          make one function drawCircle();



          public void drawCircle(int my_image_id,Imageview my_imageview,int x ,int y){

          BitmapFactory.Options myOptions = new BitmapFactory.Options();
          myOptions.inDither = true;
          myOptions.inScaled = false;
          myOptions.inPreferredConfig = Bitmap.Config.ARGB_8888;// important
          myOptions.inPurgeable = true;

          Bitmap bitmap = BitmapFactory.decodeResource(getResources(), my_image_id,myOptions);
          Paint paint = new Paint();
          paint.setAntiAlias(true);
          paint.setColor(Color.BLUE);


          //please check here . you've got your bitmap or it is null.
          // if it is null,there might be some problem with decoding your resources above.
          Bitmap workingBitmap = Bitmap.createBitmap(bitmap);
          Bitmap mutableBitmap = workingBitmap.copy(Bitmap.Config.ARGB_8888, true);


          Canvas canvas = new Canvas(mutableBitmap);
          canvas.drawCircle(x, y, 25, paint);


          my_imageview.setAdjustViewBounds(true);
          my_imageview.setImageBitmap(mutableBitmap);

          }


          now for
          image 1 . use drawCircle(R.id.imageview1,imageview,x,y) and for
          image 2 . use drawCircle(R.id.imageview2,imageview2,x,y)






          share|improve this answer















          When You tape on Image . You are getting x,y coordinate in



           x = event.getX();
          y = event.getY();


          Now you have x,y coordinate . call your drawCircle() method on both of your imageview with this same x,y coordinate.



          For Drawing circle :



          make one function drawCircle();



          public void drawCircle(int my_image_id,Imageview my_imageview,int x ,int y){

          BitmapFactory.Options myOptions = new BitmapFactory.Options();
          myOptions.inDither = true;
          myOptions.inScaled = false;
          myOptions.inPreferredConfig = Bitmap.Config.ARGB_8888;// important
          myOptions.inPurgeable = true;

          Bitmap bitmap = BitmapFactory.decodeResource(getResources(), my_image_id,myOptions);
          Paint paint = new Paint();
          paint.setAntiAlias(true);
          paint.setColor(Color.BLUE);


          //please check here . you've got your bitmap or it is null.
          // if it is null,there might be some problem with decoding your resources above.
          Bitmap workingBitmap = Bitmap.createBitmap(bitmap);
          Bitmap mutableBitmap = workingBitmap.copy(Bitmap.Config.ARGB_8888, true);


          Canvas canvas = new Canvas(mutableBitmap);
          canvas.drawCircle(x, y, 25, paint);


          my_imageview.setAdjustViewBounds(true);
          my_imageview.setImageBitmap(mutableBitmap);

          }


          now for
          image 1 . use drawCircle(R.id.imageview1,imageview,x,y) and for
          image 2 . use drawCircle(R.id.imageview2,imageview2,x,y)







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Jan 8 at 7:10

























          answered Jan 3 at 11:26









          NullPointerExceptionNullPointerException

          2,35311834




          2,35311834













          • i tried to do that but it i think im doing it wrong since it draws circle on the same place in image1 and doesn't draw circle on image2

            – Ahsan raza
            Jan 3 at 11:56











          • @Ahsanraza i've updated my answer .

            – NullPointerException
            Jan 3 at 12:30











          • i tried it but it giving in error can you add this in my code and tell me how to use it maybe im doing it wrong

            – Ahsan raza
            Jan 5 at 20:09











          • @Ahsanraza whats the error you are getting ?

            – NullPointerException
            Jan 7 at 4:37











          • Please look above i edited my question I placed your code inside in PlayActivity i might have placed it wrong. I read in a documentation that you have to get width and height of each image view separately and somehow use it i dont know how. I have read many things in these few days and tried different things but i cant get it to work all i wanted to make was a simple game :'( maybe i picked the wrong game.

            – Ahsan raza
            Jan 8 at 6:57



















          • i tried to do that but it i think im doing it wrong since it draws circle on the same place in image1 and doesn't draw circle on image2

            – Ahsan raza
            Jan 3 at 11:56











          • @Ahsanraza i've updated my answer .

            – NullPointerException
            Jan 3 at 12:30











          • i tried it but it giving in error can you add this in my code and tell me how to use it maybe im doing it wrong

            – Ahsan raza
            Jan 5 at 20:09











          • @Ahsanraza whats the error you are getting ?

            – NullPointerException
            Jan 7 at 4:37











          • Please look above i edited my question I placed your code inside in PlayActivity i might have placed it wrong. I read in a documentation that you have to get width and height of each image view separately and somehow use it i dont know how. I have read many things in these few days and tried different things but i cant get it to work all i wanted to make was a simple game :'( maybe i picked the wrong game.

            – Ahsan raza
            Jan 8 at 6:57

















          i tried to do that but it i think im doing it wrong since it draws circle on the same place in image1 and doesn't draw circle on image2

          – Ahsan raza
          Jan 3 at 11:56





          i tried to do that but it i think im doing it wrong since it draws circle on the same place in image1 and doesn't draw circle on image2

          – Ahsan raza
          Jan 3 at 11:56













          @Ahsanraza i've updated my answer .

          – NullPointerException
          Jan 3 at 12:30





          @Ahsanraza i've updated my answer .

          – NullPointerException
          Jan 3 at 12:30













          i tried it but it giving in error can you add this in my code and tell me how to use it maybe im doing it wrong

          – Ahsan raza
          Jan 5 at 20:09





          i tried it but it giving in error can you add this in my code and tell me how to use it maybe im doing it wrong

          – Ahsan raza
          Jan 5 at 20:09













          @Ahsanraza whats the error you are getting ?

          – NullPointerException
          Jan 7 at 4:37





          @Ahsanraza whats the error you are getting ?

          – NullPointerException
          Jan 7 at 4:37













          Please look above i edited my question I placed your code inside in PlayActivity i might have placed it wrong. I read in a documentation that you have to get width and height of each image view separately and somehow use it i dont know how. I have read many things in these few days and tried different things but i cant get it to work all i wanted to make was a simple game :'( maybe i picked the wrong game.

          – Ahsan raza
          Jan 8 at 6:57





          Please look above i edited my question I placed your code inside in PlayActivity i might have placed it wrong. I read in a documentation that you have to get width and height of each image view separately and somehow use it i dont know how. I have read many things in these few days and tried different things but i cant get it to work all i wanted to make was a simple game :'( maybe i picked the wrong game.

          – Ahsan raza
          Jan 8 at 6:57




















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54020941%2fdrawing-a-circle-on-imageview2-in-same-coordinates-as-imageview1-if-i-tap-a-plac%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          MongoDB - Not Authorized To Execute Command

          How to fix TextFormField cause rebuild widget in Flutter

          Npm cannot find a required file even through it is in the searched directory