欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android圖片特效:黑白特效、圓角效果、高斯模糊

 更新時間:2013年03月20日 10:06:36   作者:  
Android圖片特效:黑白特效、圓角效果、高斯模糊

1.黑白效果

復制代碼 代碼如下:

/**
     * 將彩色圖轉換為黑白圖
     *
     * @param 位圖
     * @return 返回轉換好的位圖
     */
    public static Bitmap convertToBlackWhite(Bitmap bmp) {
        int width = bmp.getWidth(); // 獲取位圖的寬
        int height = bmp.getHeight(); // 獲取位圖的高

        int[] pixels = new int[width * height]; // 通過位圖的大小創(chuàng)建像素點數(shù)組

        bmp.getPixels(pixels, 0, width, 0, 0, width, height);
        int alpha = 0xFF << 24;
        for (int i = 0; i < height; i++) {
            for (int j = 0; j < width; j++) {
                int grey = pixels[width * i + j];

                int red = ((grey & 0x00FF0000) >> 16);
                int green = ((grey & 0x0000FF00) >> 8);
                int blue = (grey & 0x000000FF);

                grey = (int) (red * 0.3 + green * 0.59 + blue * 0.11);
                grey = alpha | (grey << 16) | (grey << 8) | grey;
                pixels[width * i + j] = grey;
            }
        }
        Bitmap newBmp = Bitmap.createBitmap(width, height, Config.RGB_565);
        newBmp.setPixels(pixels, 0, width, 0, 0, width, height);
        return newBmp;
    }

2.圖片圓角

復制代碼 代碼如下:

/**
     * 轉換成圓角
     *
     * @param bmp
     * @param roundPx
     * @return
     */
    public static Bitmap convertToRoundedCorner(Bitmap bmp, float roundPx) {

        Bitmap newBmp = Bitmap.createBitmap(bmp.getWidth(), bmp.getHeight(),
                Config.ARGB_8888);
        // 得到畫布
        Canvas canvas = new Canvas(newBmp);

        final int color = 0xff424242;
        final Paint paint = new Paint();
        final Rect rect = new Rect(0, 0, bmp.getWidth(), bmp.getHeight());
        final RectF rectF = new RectF(rect);

        paint.setAntiAlias(true);
        canvas.drawARGB(0, 0, 0, 0);
        paint.setColor(color);
        // 第二個和第三個參數(shù)一樣則畫的是正圓的一角,否則是橢圓的一角
        canvas.drawRoundRect(rectF, roundPx, roundPx, paint);

        paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
        canvas.drawBitmap(bmp, rect, rect, paint);

        return newBmp;
    }

3.高斯模糊

復制代碼 代碼如下:

/**
     * 高斯模糊
     *
     * @param bmp
     * @return
     */
    public static Bitmap convertToBlur(Bitmap bmp) {
        // 高斯矩陣
        int[] gauss = new int[] { 1, 2, 1, 2, 4, 2, 1, 2, 1 };

        int width = bmp.getWidth();
        int height = bmp.getHeight();
        Bitmap newBmp = Bitmap.createBitmap(width, height,
                Bitmap.Config.RGB_565);

        int pixR = 0;
        int pixG = 0;
        int pixB = 0;

        int pixColor = 0;

        int newR = 0;
        int newG = 0;
        int newB = 0;

        int delta = 16; // 值越小圖片會越亮,越大則越暗

        int idx = 0;
        int[] pixels = new int[width * height];
        bmp.getPixels(pixels, 0, width, 0, 0, width, height);
        for (int i = 1, length = height - 1; i < length; i++) {
            for (int k = 1, len = width - 1; k < len; k++) {
                idx = 0;
                for (int m = -1; m <= 1; m++) {
                    for (int n = -1; n <= 1; n++) {
                        pixColor = pixels[(i + m) * width + k + n];
                        pixR = Color.red(pixColor);
                        pixG = Color.green(pixColor);
                        pixB = Color.blue(pixColor);

                        newR = newR + pixR * gauss[idx];
                        newG = newG + pixG * gauss[idx];
                        newB = newB + pixB * gauss[idx];
                        idx++;
                    }
                }

                newR /= delta;
                newG /= delta;
                newB /= delta;

                newR = Math.min(255, Math.max(0, newR));
                newG = Math.min(255, Math.max(0, newG));
                newB = Math.min(255, Math.max(0, newB));

                pixels[i * width + k] = Color.argb(255, newR, newG, newB);

                newR = 0;
                newG = 0;
                newB = 0;
            }
        }

        newBmp.setPixels(pixels, 0, width, 0, 0, width, height);

        return newBmp;
    }

相關文章

  • Android基于OpenCV實現(xiàn)圖像脫色

    Android基于OpenCV實現(xiàn)圖像脫色

    脫色是將彩色圖像轉換為灰度圖像的過程。同時,它也是數(shù)字打印,風格化的黑白照片渲染以及許多單通道圖像處理應用程序中的基本工具。本文講述基于OpenCV實現(xiàn)圖像脫色的步驟
    2021-06-06
  • Android實現(xiàn)下拉刷新的視圖和圖標的旋轉

    Android實現(xiàn)下拉刷新的視圖和圖標的旋轉

    本篇文章主要介紹了Android實現(xiàn)下拉刷新的視圖和圖標的旋轉的實例,具有很好的參考價值。下面跟著小編一起來看下吧
    2017-03-03
  • Android編程實現(xiàn)下載時主界面與詳細界面一致更新的方法

    Android編程實現(xiàn)下載時主界面與詳細界面一致更新的方法

    這篇文章主要介紹了Android編程實現(xiàn)下載時主界面與詳細界面一致更新的方法,涉及Android事件監(jiān)聽及界面動態(tài)更新相關操作技巧,需要的朋友可以參考下
    2017-11-11
  • android使用ViewPager實現(xiàn)輪播效果

    android使用ViewPager實現(xiàn)輪播效果

    這篇文章主要為大家詳細介紹了android使用ViewPager實現(xiàn)輪播效果,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-04-04
  • Android 攔截返回鍵事件的實例詳解

    Android 攔截返回鍵事件的實例詳解

    這篇文章主要介紹了Android 攔截返回鍵事件的實例詳解的相關資料,希望通過本文能幫助到大家,讓大家掌握這部分內容,需要的朋友可以參考下
    2017-10-10
  • android實現(xiàn)輪播圖引導頁

    android實現(xiàn)輪播圖引導頁

    這篇文章主要為大家詳細介紹了android實現(xiàn)輪播圖引導頁,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-09-09
  • Android MarkTipsView文字標識控件使用方法

    Android MarkTipsView文字標識控件使用方法

    這篇文章主要為大家詳細介紹了Android MarkTipsView文字標識控件的使用方法,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2021-04-04
  • Flutter?EventBus事件總線的應用詳解

    Flutter?EventBus事件總線的應用詳解

    這篇文章主要為大家介紹了Flutter?EventBus事件總線的應用詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2022-08-08
  • Android實現(xiàn)雙層ViewPager嵌套

    Android實現(xiàn)雙層ViewPager嵌套

    這篇文章主要介紹了Android實現(xiàn)雙層ViewPager嵌套,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-04-04
  • Android利用傳感器仿微信搖一搖功能

    Android利用傳感器仿微信搖一搖功能

    這篇文章主要為大家詳細介紹了Android利用傳感器仿微信搖一搖功能,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-05-05

最新評論