如何打破图像到Android中破灭的形状 [英] How to break the image into shattered shapes in android

查看:150
本文介绍了如何打破图像到Android中破灭的形状的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图打破形象破灭片,但我无法赶上逻辑,请给我的方式如何实现。  

Am trying to break image in shattered pieces, but am unable to catch the logic, please give me way how to achieve.

我希望下面的图片可以给我的想法,我想,打破了位图到一个支离破碎的片段像三角形或任何形状。以后我会洗牌的位图的形状和最终用户提供拼图重新排列它们的顺序。

I hope the below image can give my idea, what I want, Breaking the bitmap into a shattered pieces like triangle or any shape. later i will shuffle those bitmap shapes and giving puzzle to enduser rearrange them in order.

推荐答案

OK,如果你想重新排列件(就像拼图),那么每个三角形/多边形将要出现在一个矩形位图具有透明背景,因为这是如何绘制位图工程的Java / Android的(和大多数其他环境)。

OK, if you want to rearrange the pieces (like in a jigsaw) then each triangle/polygon will have to appear in a rectangular bitmap with a transparent background, because that's how drawing bitmaps works in Java/Android (and most other environments).

有一种方法做这样的机器人,它被称为搬运工 - 达夫合成掩蔽。 Android的文件很糟糕是不存在的,但也有其在Java中使用的很多文章。

There is a way to do this sort of masking in Android, its called porter-duff compositing. The Android documentation is poor to non-existent, but there are many articles on its use in Java.

基本上你创建一个矩形形状的透明位图只是大到足以容纳你的切口。然后,你画到这个位图填充的三角形(透明非零)重新presenting切出。它可以是任何你喜欢的颜色。然后使用波特 - 达芙模式,它复制的透明度数据,但不将RGB数据绘制在源图像的顶部的切口在正确的位置。你将留下对一个透明背景的缺口。

Basically you create a rectangular transparent bitmap just large enough to hold your cut-out. Then you draw onto this bitmap a filled triangle (with transparency non-zero) representing the cut-out. It can be any colour you like. Then draw the cutout on top of the source image at the correct location using the Porter-Duff mode which copies the transparency data but not the RGB data. You will be left with your cutout against a transparent background.

这是容易得多,如果你做出切口位图的大小相同的源图像。我建议第一次得到这个工作。这样做的缺点是双重的。首先,你会走动的大位图走动的小切口,将这样的UI慢一些。其次,你会使用大量的内存位图,以及在一些Android版本,你很可能内存用完。

This is much easier if you make the cutout bitmap the same size as the source image. I would recommend getting this working first. The downsides of this are twofold. Firstly you will be moving around large bitmaps to move around small cutouts, so the UI will be slower. Secondly you will use a lot of memory for bitmaps, and on some versions of Android you may well run out of memory.

但是,一旦你拥有了它工作的位图的大小相同的源图像,它应该是pretty的直观改变它的工作为较小的位图。你的大部分瞎将在查找和使用正确的波特 - 达夫模式。因为只有他们的16,它没有很大的努力,试图所有这些,看看他们做什么。他们可能会建议其他拼图的想法。

But once you have it working for bitmaps the same size as the source image, it should be pretty straightforward to change it to work for smaller bitmaps. Most of your "mucking about" will be in finding and using the correct Porter-Duff mode. As there are only 16 of them, its no great effort to try them all and see what they do. And they may suggest other puzzle ideas.

我注意到你的切口部分是所有多边形。随着额外的复杂性只是一个很小的量,你可以让他们任何你喜欢的形状,包括看起来像普通拼图。要做到这一点,使用Path类来定义用于切口形状。 Path类工作正常波特 - 达夫合成,使几乎任何形状,你可以想像的切口。我用这个广泛在我的应用程序之一。

I note your cutout sections are all polygons. With only a tiny amount of extra complexity, you could make them any shape you like, including looking like regular jigsaw pieces. To do this, use the Path class to define the shapes used for cutouts. The Path class works fine with Porter-Duff compositing, allowing cutouts of almost any shape you can imagine. I use this extensively in one of my apps.

这篇关于如何打破图像到Android中破灭的形状的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆