Split image into pieces

I am trying to break an image into pieces, say, for example, 16 pieces (4x4). When I split the image, how can I display this image of the piece as a whole.

Should I use a bitmap or drawing? Is there a way to split, or do I need to create my own method?

+6
source share
2 answers

Use a bitmap because it contains an image pixel that will be useful for future use if you want to display that image.

e.g. ---->

Bitmap bm = BitmapFactory.decodeResource(getResources(), R.drawable.icon); ImageView iv = (ImageView) findViewById(R.id.imageView1); iv.setImageBitmap(bm); 

- ----------------------------------- EDITED PART ------ ------ --------------------------------

if you want to send an image from one place to another (one device to another), you must convert it to an array of bytes, for example: --->

 Bitmap bm = BitmapFactory.decodeResource(getResources(), R.drawable.icon); ByteArrayOutputStream baos = new ByteArrayOutputStream(); bm.compress(Bitmap.Compress.JPEG, 100, baos); byte[] b = baos.toByteArray(); 

and then send it to another device.

+1
source

You can use Canvas , with a drawing function, breaking it into pieces and setting each to a 4x4 ImageView .

@note:

  • as in my experience, Bitmap will give better performance than Drawable .
  • reduce the size and image quality to display on the screen first, then split and set it to ImageView .

You can refer to my list of image processing articles for an idea of ​​this. In practice, it’s not so difficult :)

0
source

Source: https://habr.com/ru/post/898963/


All Articles