Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid - How crop jpeg using view layout dimensions
    primarykey
    data
    text
    <p>Newbie user question:</p> <p>I have searched and experimented for several days and need some help. I have probably read every SO posting on this topic but I still cannot figure it out.</p> <p>I am trying to crop a specific area of a camera preview image. The issue is that the blue box is defined by a layout with top = 150 and left = 38, and height = 292 and width = 600. The image has height = 2448 and width = 3264.</p> <p>Big box is the camera preview screen, small box is the portion I want to crop (apparently I don't yet have the ability to post pictures).</p> <pre> ----------------------------- | | | | | | | --------- | | | | | | --------- | | | ----------------------------- </pre> <p>How do I crop the image so I am only left with the portion in the box? I'll be displaying it on another activity so I am not worried about that part.</p> <p>Just to complicate things, the box size and image size changes depending on the phone, and I need to work with API 8 (version 2.2, Froyo).</p> <p>I would also prefer not to save the image to a file because then I would have to encrypt it (the picture would be an image of a check for deposit).</p> <p>I am using Camera.takePicture() and the jpegCallback as in the following code snippet (initialBitmap would be the "big box" above, and rl would be the "small box"):</p> <pre><code> PictureCallback jpegCallback = new PictureCallback() { public void onPictureTaken(byte[] data, Camera camera) { if ( data != null &amp;&amp; data.length &gt; 0 ) { Bitmap initialBitmap = BitmapFactory.decodeByteArray(data, 0, data.length); int bitmapHeight = initialBitmap.getHeight(); int bitmapWidth = initialBitmap.getWidth(); // get the "picture" frame RelativeLayout rl = (RelativeLayout) findViewById( R.id.clear_layout ); int frameX = rl.getLeft(); int frameY = rl.getTop(); int frameHeight = rl.getHeight(); </code></pre> <p>Hopefully there is a simple mathematical relationship between the view coordinates/dimensions and the bitmap.</p> <p>I am also open to any better way to go about things but have tried to use the Preview data itself (too small) and manipulating the bitmap (out of memory errors).</p> <p>Thanks in advance.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload