b2科目四模拟试题多少题驾考考爆了怎么补救
b2科目四模拟试题多少题 驾考考爆了怎么补救

灰度图像数据量 Android滤镜效果实现及原理分析(2)

电脑杂谈  发布时间:2018-02-19 11:04:38  来源:网络整理

Android实例

下面,我们着手写一个demo,模拟一个 4×5 的颜色矩阵来体验一下上面对颜色矩阵的分析。效果如下:

关键代码是将 4×5 矩阵转换成一维数组,然后再将这一维数组设置到ColorMatrix类里去,请看代码:

灰度图像是什么_灰度图像数据量_图像处理灰度

//将矩阵设置到图像 private void setImageMatrix() { Bitmap bmp = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888); ColorMatrix colorMatrix = new ColorMatrix(); colorMatrix.set(mColorMatrix);//将一维数组设置到ColorMatrix Canvas canvas = new Canvas(bmp); Paint paint = new Paint(); paint.setColorFilter(new ColorMatrixColorFilter(colorMatrix)); canvas.drawBitmap(bitmap, 0, 0, paint); iv_photo.setImageBitmap(bmp); }

这个demo里面的代码比较简单,我在这里就全部贴出来了,先上xml布局:

<?xml version="1。0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas。android。com/apk/res/android" xmlns:tools="http://schemas。android。com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com。example。deeson。mycolormatrix。MainActivity" android:orientation="vertical"> <ImageView android:id="@+id/iv_photo" android:layout_width="300dp" android:layout_height="0dp" android:layout_weight="3" android:layout_gravity="center_horizontal"/> <GridLayout android:id="@+id/matrix_layout" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="4" android:columnCount="5" android:rowCount="4"> </GridLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <Button android:id="@+id/btn_change" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="change"/> <Button android:id="@+id/btn_reset" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="reset"/> </LinearLayout></LinearLayout>


本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/jisuanjixue/article-84905-2.html

相关阅读
    发表评论  请自觉遵守互联网相关的政策法规,严禁发布、暴力、反动的言论

    热点图片
    拼命载入中...