title: Android - Drawing lines using bitmap on TouchImageView
body: <p>Basically I would like to draw lines on an image so that when that image is zoomed, the lines would also get zoomed proportionally, or any kind of interactivity like fling or zoom reset. I'm using TouchImageView as my ImageView and here's my code</p>
  
  <pre><code>public class ParkA extends Activity{
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.parka);
          TouchImageView parka = (TouchImageView) findViewById(R.id.parka);
          parka.setImageResource(R.drawable.parka);
  
          Bitmap lineABmp = Bitmap.createBitmap(480, 640, Bitmap.Config.ARGB_8888);
          Canvas lineACanvas = new Canvas(lineABmp);
          Paint paint = new Paint();
          paint.setColor(Color.GREEN);
          paint.setStrokeWidth(10);
          lineACanvas.drawBitmap(lineABmp,0 ,0, null);
          //lineACanvas.drawLine(60, 64, 60, 500, paint);
  
          TouchImageView linea = new TouchImageView(this);
          linea = (TouchImageView) findViewById(R.id.parka);
          linea.setImageBitmap(lineABmp);
  
      }
  
      @Override
      protected void onResume() {
          super.onResume();
  
  
      }
  
      @Override
      protected void onPause() {
  
  
          super.onPause();
      }
  
      @Override
      protected void onNewIntent(Intent intent) {
  
  
      }
  
      @Override
      public void onBackPressed() {
          //Do Nothing
      }
  
  }
  </code></pre>
  
  <p>Here's my xml file</p>
  
  <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:paddingBottom="@dimen/activity_vertical_margin"
      android:paddingLeft="@dimen/activity_horizontal_margin"
      android:paddingRight="@dimen/activity_horizontal_margin"
      android:paddingTop="@dimen/activity_vertical_margin"
      tools:context="com.kmparkit.ParkA" &gt;
  
      &lt;com.km.parkit.TouchImageView
          android:id="@+id/parka"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:gravity="center"
          android:contentDescription="@string/imageDesc"
          android:scaleType="matrix"  /&gt;
          &lt;!-- android:src="@drawable/parka" --&gt; 
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>If I change the <code>Bitmap.createBitmap(480, 640, Bitmap.Config.ARGB_8888);</code></p>
  
  <p>Into <code>Bitmap.createBitmap(parka.getWidth(), parka.getHeight(), Bitmap.Config.ARGB_8888);</code></p>
  
  <p>The logcat says that width and height must be > 0</p>
  
  <p>If I drawLine, only the green line itself would be shown</p>
  
  <p>What am I missing here in order to create a TouhImageView picture with lines drawn on it?</p>
  
  <p>UPDATE :</p>
  
  <p>Here's the solution!</p>
  
  <pre><code>@Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.parka);
  
          TouchImageView parka = (TouchImageView) findViewById(R.id.parka);
          parka.setImageResource(R.drawable.parka);
  
          Bitmap lineABmp = ((BitmapDrawable)parka.getDrawable()).getBitmap();
          Bitmap lineAMutBmp = lineABmp.copy(Bitmap.Config.ARGB_8888, true);
  
          Canvas lineACanvas = new Canvas(lineAMutBmp);
          Paint paint = new Paint();
          paint.setColor(Color.GREEN);
          paint.setStrokeWidth(10);
          lineACanvas.drawLine(82, 1058, 82, 858, paint);
  
          parka.setImageBitmap(lineAMutBmp);
      }
  </code></pre>
  
  <p>I have to copy the bitmap in order to make it mutable and use <code>parka.setImageResource();</code> and <code>parka.setImageBitmap()</code> to display the picture and the lines in one <code>TouchImageView</code> while drawing the lines using <code>Canvas</code>.</p>