日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

安卓实现qq离线图像变灰色或暗色效果

發(fā)布時間:2023/12/29 编程问答 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 安卓实现qq离线图像变灰色或暗色效果 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

頭像由彩色變灰色有兩種實現(xiàn)方式:

/** 方法1:* ColorMatrix類有一個內(nèi)置的方法可用于改變飽和度。* 傳入一個大于1的數(shù)字將增加飽和度,而傳入一個0~1之間的數(shù)字會減少飽和度。0值將產(chǎn)生一幅灰度圖像。*/ColorMatrix matrix = new ColorMatrix();matrix.setSaturation(0);ColorMatrixColorFilter filter = new ColorMatrixColorFilter(matrix);image1.setColorFilter(filter);

方法二:

/*** 將彩色圖轉換為純黑白二色** @param* @return 返回轉換好的位圖*/private 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);// 設置圖片數(shù)據(jù)newBmp.setPixels(pixels, 0, width, 0, 0, width, height);//設置寬高Bitmap resizeBmp = ThumbnailUtils.extractThumbnail(newBmp, 460, 460);return resizeBmp;} Bitmap bmp = BitmapFactory.decodeResource(getResources(),R.drawable.icon);image2.setImageBitmap(convertToBlackWhite(bmp));

有時候我們需要把一張圖變暗,也有兩種方式可以實現(xiàn)
方法一:

ImageView image3 = (ImageView) findViewById(R.id.image3);Drawable drawable = getResources().getDrawable(R.drawable.icon1);drawable.setColorFilter(Color.GRAY, PorterDuff.Mode.MULTIPLY);image3.setImageDrawable(drawable);

方法二:在布局把要顯示的圖片作為background,把變暗的圖片或顏色設為src,就可以實現(xiàn)變暗的效果。

<ImageView android:id="@+id/image4"android:layout_width="120dp"android:layout_height="120dp"android:src="#77000000"android:background="@drawable/icon"android:layout_marginLeft="30dp"/>

總結

以上是生活随笔為你收集整理的安卓实现qq离线图像变灰色或暗色效果的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。