algorithm - How to break the image into shattered shapes in android -
am trying break image in shattered pieces, unable catch logic, please give me way how achieve.
i hope below image can give idea, want, breaking bitmap shattered pieces triangle or shape. later shuffle bitmap shapes , giving puzzle enduser rearrange them in order.
ok, if want rearrange pieces (like in jigsaw) each triangle/polygon have appear in rectangular bitmap transparent background, because that's how drawing bitmaps works in java/android (and other environments).
there way sort of masking in android, called porter-duff compositing. android documentation poor non-existent, there many articles on use in java.
basically create rectangular transparent bitmap large enough hold cut-out. draw onto bitmap filled triangle (with transparency non-zero) representing cut-out. can colour like. draw cutout on top of source image @ correct location using porter-duff mode copies transparency data not rgb data. left cutout against transparent background.
this easier if make cutout bitmap same size source image. recommend getting working first. downsides of twofold. firstly moving around large bitmaps move around small cutouts, ui slower. secondly use lot of memory bitmaps, , on versions of android may run out of memory.
but once have working bitmaps same size source image, should pretty straightforward change work smaller bitmaps. of "mucking about" in finding , using correct porter-duff mode. there 16 of them, no great effort try them , see do. , may suggest other puzzle ideas.
i note cutout sections polygons. tiny amount of complexity, make them shape like, including looking regular jigsaw pieces. this, use path class define shapes used cutouts. path class works fine porter-duff compositing, allowing cutouts of shape can imagine. use extensively in 1 of apps.
Comments
Post a Comment