In android Image filter application,Getpixels and setpixels not working properly

試著忘記壹切 提交于 2019-12-11 06:40:06

问题


I am creating an image filters app in android. I am retrieving pixels from a bitmap doing some rgb work on then and setting them on another bitmap. Here is my code and it isnt working properly. please help

bmOut = Bitmap.createBitmap(bm1.getWidth(),
                                bm1.getHeight(), bm1.getConfig());
                        final double GS_RED = 0.299;
                        final double GS_GREEN = 0.587;
                        final double GS_BLUE = 0.114;
                        int A, R, G, B;
                        int pixel;
int[] pixels = new int[bm1.getHeight()* bm1.getWidth()];
bm1.getPixels(pixels, 0, bm1.getWidth(), 0, 0,bm1.getWidth(), bm1.getHeight());

                        for (int pix = 0 ; pix< pixels.length;pix++) {
                            A = Color.alpha(pix);
                            R = Color.red(pix);
                            G = Color.green(pix);
                            B = Color.blue(pix);
                            R = G = B = (int) (GS_RED * R + GS_GREEN * G + GS_BLUE * B);
                            pixels[pix] = Color.argb(A, R, G, B);

                        }

                        bmOut.setPixels(pixels, 0, bm1.getWidth(), 0, 0,
                                bm1.getWidth(), bm1.getHeight());

来源:https://stackoverflow.com/questions/26573971/in-android-image-filter-application-getpixels-and-setpixels-not-working-properly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!