Skip to main content

draw rectangle on a picture from pixels coordinates



with the following code i can draw a rectangle on my bitmap image.







Paint paint = new Paint();

paint.setStyle(Style.STROKE);

paint.setColor(Color.BLUE);

publishProgress(80);

Canvas canvas = new Canvas(mBitmap);

publishProgress(85);

canvas.drawRect(200, 100, 200, 100, paint);

bitmap.recycle();

channel.close();







i've read that the values given in canvas.drawRect(200, 100, 200, 100, paint); represent respectively left x, top y, right x and bottom y. So my questions are :





  • are those values in pixels? ppi or what??







  • how can i draw a rectangle on my image if i have only the coordinates of each corners in pixels as shown on the picture below ? assuming that i have A (x, y) B (x, y), C(x, y) and D(x, y) with x and y expressed in pixels from the axes of the picture below. NB: i don't have control on A,B,C,D they are given to me from a web service





    rectangle i want to draw






Comments

  1. I don't think you have a problem here, you would just do this:

    canvas.drawRect(a.getX(), a.getY(), c.getX(), c.getY(), paint);

    Yes the values are in pixels however your origin (0,0) is the top left of the canvas normally. Y value becomes more positive as you move down the canvas.

    ReplyDelete

Post a Comment

Popular posts from this blog

Why is this Javascript much *slower* than its jQuery equivalent?

I have a HTML list of about 500 items and a "filter" box above it. I started by using jQuery to filter the list when I typed a letter (timing code added later): $('#filter').keyup( function() { var jqStart = (new Date).getTime(); var search = $(this).val().toLowerCase(); var $list = $('ul.ablist > li'); $list.each( function() { if ( $(this).text().toLowerCase().indexOf(search) === -1 ) $(this).hide(); else $(this).show(); } ); console.log('Time: ' + ((new Date).getTime() - jqStart)); } ); However, there was a couple of seconds delay after typing each letter (particularly the first letter). So I thought it may be slightly quicker if I used plain Javascript (I read recently that jQuery's each function is particularly slow). Here's my JS equivalent: document.getElementById('filter').addEventListener( 'keyup', function () { var jsStart = (new Date).getTime()...

Is it possible to have IF statement in an Echo statement in PHP

Thanks in advance. I did look at the other questions/answers that were similar and didn't find exactly what I was looking for. I'm trying to do this, am I on the right path? echo " <div id='tabs-".$match."'> <textarea id='".$match."' name='".$match."'>". if ($COLUMN_NAME === $match) { echo $FIELD_WITH_COLUMN_NAME; } else { } ."</textarea> <script type='text/javascript'> CKEDITOR.replace( '".$match."' ); </script> </div>"; I am getting the following error message in the browser: Parse error: syntax error, unexpected T_IF Please let me know if this is the right way to go about nesting an IF statement inside an echo. Thank you.