如何在android中添加雪流效果?

如何在android中添加雪流效果?,第1张

概述我正在尝试添加雪流效果.但没有成功我试图做到不断积雪的效果.可能吗?如果可以,请提出建议.我的代码如下.publicclassMainActivityextendsActivity{privateintCOLOR_MAX=0xff;ImageViewimage;@OverrideprotectedvoidonCreate(BundlesavedIn

我正在尝试添加雪流效果.但没有成功
我试图做到不断积雪的效果.
可能吗?如果可以,请提出建议.

我的代码如下.

public class MainActivity extends Activity {    private int color_MAX = 0xff;    ImageVIEw image;    @OverrIDe    protected voID onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentVIEw(R.layout.activity_main);        image = (ImageVIEw)findVIEwByID(R.ID.imageVIEw1);        Bitmap imagebitmap = BitmapFactory.decodeResource(getResources(),R.drawable.hydrangeas);            applySNowEffect(imagebitmap);    }    Bitmap applySNowEffect(Bitmap source)     {        // get image size        int wIDth = source.getWIDth();        int height = source.getHeight();        int[] pixels = new int[wIDth * height];        // get pixel array from source        source.getPixels(pixels, 0, wIDth, 0, 0, wIDth, height);        // random object        Random random = new Random();        int R, G, B, index = 0, thresHold = 50;        // iteration through pixels        for(int y = 0; y < height; ++y) {            for(int x = 0; x < wIDth; ++x) {                // get current index in 2D-matrix                index = y * wIDth + x;                              // get color                R = color.red(pixels[index]);                G = color.green(pixels[index]);                B = color.blue(pixels[index]);                // generate threshold                thresHold = random.nextInt(color_MAX );                if(R > thresHold && G > thresHold && B > thresHold) {                    pixels[index] = color.rgb(color_MAX, color_MAX, color_MAX);                }                                       }        }        // output bitmap                        Bitmap bmOut = Bitmap.createBitmap(wIDth, height, Bitmap.Config.RGB_565);        bmOut.setPixels(pixels, 0, wIDth, 0, 0, wIDth, height);        Toast.makeText(getApplicationContext(),"processed",10).show();        return bmOut;    }

解决方法:

我实际上是前几天读到的.您可以将粒子系统用于AndroID.可在此处找到有助于此目的的库-https://github.com/plattysoft/Leonids

总结

以上是内存溢出为你收集整理的如何在android中添加雪流效果?全部内容,希望文章能够帮你解决如何在android中添加雪流效果?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1076142.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-26
下一篇2022-05-26

发表评论

登录后才能评论

评论列表(0条)

    保存