av一区二区在线观看_亚洲男人的天堂网站_日韩亚洲视频_在线成人免费_欧美日韩精品免费观看视频_久草视

您的位置:首頁技術(shù)文章
文章詳情頁

Android實(shí)現(xiàn)濾鏡效果ColorMatrix

瀏覽:3日期:2022-09-18 18:15:31

本文實(shí)例為大家分享了Android實(shí)現(xiàn)濾鏡效果的具體代碼,供大家參考,具體內(nèi)容如下

1.效果圖

Android實(shí)現(xiàn)濾鏡效果ColorMatrix

2.矩陣算法

package net.surina.myapplication15; import android.graphics.Bitmap;import android.graphics.BitmapFactory;import android.graphics.Canvas;import android.graphics.ColorMatrix;import android.graphics.ColorMatrixColorFilter;import android.graphics.Paint;import android.os.Bundle;import android.text.InputType;import android.view.View;import android.widget.Button;import android.widget.EditText;import android.widget.GridLayout;import android.widget.ImageView; import androidx.appcompat.app.AppCompatActivity; import java.util.LinkedList;import java.util.Stack; /** * @author Deeson * 參考代碼:https://github.com/DeesonWoo/MyColorMatrixDemo */public class MainActivity extends AppCompatActivity implements View.OnClickListener { Bitmap bitmap; ImageView iv_photo; GridLayout matrixLayout; //每個(gè)edittext的寬高 int mEtWidth; int mEtHeight; //保存20個(gè)edittext EditText[] mEts = new EditText[20]; //一維數(shù)組保存20個(gè)矩陣值 float[] mColorMatrix = new float[20]; @Override protected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.girl);iv_photo = (ImageView) findViewById(R.id.iv_photo);matrixLayout = (GridLayout) findViewById(R.id.matrix_layout);Button btn_change = (Button) findViewById(R.id.btn_change);Button btn_reset = (Button) findViewById(R.id.btn_reset);btn_change.setOnClickListener(this);btn_reset.setOnClickListener(this);iv_photo.setImageBitmap(bitmap); //我們無法在onCreate()方法中獲得視圖的寬高值,所以通過View的post()方法,在視圖創(chuàng)建完畢后獲得其寬高值matrixLayout.post(new Runnable() { @Override public void run() {mEtWidth = matrixLayout.getWidth() / 5;mEtHeight = matrixLayout.getHeight() / 4;addEts();initMatrix(); } }); } //動(dòng)態(tài)添加edittext private void addEts() {for (int i = 0; i < 20; i++) { EditText et = new EditText(this); et.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL); mEts[i] = et; matrixLayout.addView(et, mEtWidth, mEtHeight);} } //初始化顏色矩陣 private void initMatrix() {for (int i = 0; i < 20; i++) { if (i % 6 == 0) {mEts[i].setText(String.valueOf(1)); } else {mEts[i].setText(String.valueOf(0)); }} } //獲取矩陣值 private void getMatrix() {for (int i = 0; i < 20; i++) { String matrix = mEts[i].getText().toString(); boolean isNone = null == matrix || ''.equals(matrix); mColorMatrix[i] = isNone ? 0.0f : Float.valueOf(matrix); if (isNone) {mEts[i].setText('0'); }} } //將矩陣設(shè)置到圖像 private void setImageMatrix() {Bitmap bmp = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);ColorMatrix colorMatrix = new ColorMatrix();colorMatrix.set(mColorMatrix);//將一維數(shù)組設(shè)置到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); } @Override public void onClick(View v) {switch (v.getId()) { case R.id.btn_change:break; case R.id.btn_reset://重置矩陣效果initMatrix();break;}//作用矩陣效果getMatrix();setImageMatrix(); }}3.布局

<?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' android:orientation='vertical'> <ImageViewandroid: android:layout_width='300dp'android:layout_height='0dp'android:layout_weight='4'android:layout_gravity='center_horizontal'android:scaleType='fitCenter'android:src='http://m.4tl426be.cn/bcjs/@drawable/girl'/> <GridLayoutandroid: android:layout_width='match_parent'android:layout_height='0dp'android:layout_weight='2'android:columnCount='5'android:rowCount='4'> </GridLayout> <LinearLayoutandroid:layout_width='match_parent'android:layout_height='wrap_content'android:orientation='horizontal'> <Button android: android:layout_width='0dp' android:layout_height='wrap_content' android:layout_weight='1' android:text='change'/><Button android: android:layout_width='0dp' android:layout_height='wrap_content' android:layout_weight='1' android:text='reset'/> </LinearLayout> </LinearLayout>

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。

標(biāo)簽: Android
相關(guān)文章:
主站蜘蛛池模板: 国产网站在线免费观看 | 丁香久久 | 亚洲传媒在线 | 国产精品久久久久久久久免费樱桃 | 狠狠综合久久av一区二区老牛 | 国产成人午夜电影网 | 午夜免费看| 欧美极品在线 | 欧美精品一区二区三区在线 | 1204国产成人精品视频 | 一本色道久久综合亚洲精品高清 | h在线免费观看 | 色播视频在线观看 | 一级片免费网站 | 99re在线视频免费观看 | 国产成人99久久亚洲综合精品 | 免费看91| 日韩在线播放第一页 | 国产精品一区二区在线 | 国产一级片在线观看视频 | 欧美精品一区二区三区在线播放 | 成人一级视频在线观看 | 日韩精品专区在线影院重磅 | a级免费视频| 日韩在线精品 | 超碰97免费观看 | 亚洲国产成人精品女人 | 国产精品久久久久久久久久免费 | 国产精品区一区二区三区 | 成人免费淫片aa视频免费 | 久久精品超碰 | 日韩成人中文字幕 | 久久国产精品一区二区三区 | 欧美三级视频 | 亚洲国产精品一区二区三区 | 成人一区二区三区在线观看 | 欧美日韩综合精品 | 亚洲欧美国产精品一区二区 | 成人国产精品免费观看视频 | 久久大陆 | 黄色成人免费在线观看 |