Dividir imagem em 4 partes iguais

1,431 views
Skip to first unread message

Douglas Alípio

unread,
May 28, 2012, 12:56:59 PM5/28/12
to android-bra...@googlegroups.com, androidb...@googlegroups.com
Ae galera, 

                  Alguém sabe como eu faço pra recortar uma imagem em 4 partes iguais? utilizando android...

--







Atenciosamente,
Douglas Alípio Mesquita


Jonas Alves

unread,
May 28, 2012, 3:22:28 PM5/28/12
to androidb...@googlegroups.com, android-bra...@googlegroups.com

public static Bitmap createBitmap (Bitmap source, int x, int y, int width, int height)

Since: API Level 1

Returns an immutable bitmap from the specified subset of the source bitmap. The new bitmap may be the same object as source, or a copy may have been made. It is initialized with the same density as the original bitmap.

Parameters
source The bitmap we are subsetting
xThe x coordinate of the first pixel in source
yThe y coordinate of the first pixel in source
widthThe number of pixels in each row
heightThe number of rows

2012/5/28 Douglas Alípio <douglas...@gmail.com>



--
Jonas Alves

Daniel Lopes

unread,
Apr 29, 2016, 2:08:55 PM4/29/16
to Android Brasil - Dev, android-bra...@googlegroups.com
Olá Jonas como eu uso método? estou tendo dificuldade para implementa. tipo fazer as divisões para as imagens. 

Miron Alighieri dos Santos

unread,
Apr 29, 2016, 2:46:58 PM4/29/16
to androidb...@googlegroups.com, android-bra...@googlegroups.com
Você vai precisar chamar o método 4 vezes, passando a mesma imagem de origem porém alterando os parâmetros de recorte desta imagem.

Para uma imagem de origem 100 x 100, por exemplo, você teria que fazer algo como o código abaixo:

Bitmap imagem1 = createBitmap(imagemOrigem,   0, 0, 25,25);  // Cria imagem do canto superior esquerdo
Bitmap imagem2 = createBitmap(imagemOrigem,   25, 0, 25,25);  // Cria imagem do canto superior direito
Bitmap imagem3 = createBitmap(imagemOrigem, 0, 25, 25,25);  // Cria imagem do canto inferior esquerdo
Bitmap imagem4 = createBitmap(imagemOrigem, 25, 25, 25,25);  // Cria imagem do canto inferior direito

Obviamente este código é só pra entendimento básico da lógica do uso do método. Ao escrever seu método você deve fazer algo mais estruturado e para que funcione com qualquer imagem, você deve elaborar a matemática da lógica para achar as coordenadas e dimensões para as chamadas do método.

Espero ter ajudado.

Miron Alighieri
LG G3 - BH

--
You received this message because you are subscribed to the Google Groups "Android Brasil - Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to androidbrasil-...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages