<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                ## 本節引言: > 上一節中我們講解了Android中Paint?**API**中的**ColorFilter**(顏色過濾器)的第一個子類:**ColorMatrixColorFilter**(顏色矩陣顏色過濾器),相信又開闊了大家的Android圖像處理視野, 而本節我們來研究它的第二個子類:**LightingColorFilter**(光照色彩顏色過濾器),先上一發 官方API文檔:[LightingColorFilter](http://androiddoc.qiniudn.com/reference/android/graphics/LightingColorFilter.html),文檔里的東西也不多,關鍵的在這里: > > ![](https://box.kancloud.cn/2015-12-02_565e7993c6ecf.jpg) > > 大概意思就是:一個顏色過濾器,可以用來模擬簡單的燈光效果,構造方法的參數有兩個,一個 用來乘以原圖的RPG值,一個添加到前面得出的結果上!其實計算方法無非:?**(RGB值 * mul + Add) % 255**,從而得到新的RPG值,這里的%是求余,另外,整個過程中Alpha不 參與改變!下面我們寫個示例來驗證驗證! * * * ## 1.代碼示例: **運行效果圖**: ![](https://box.kancloud.cn/2015-12-02_565e7993e56ee.jpg) **實現代碼**: 先是一個簡單的布局:**activity_main.xml**: ~~~ <RelativeLayout 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:padding="5dp" tools:context=".MainActivity"> <ImageView android:id="@+id/img_meizi" android:layout_width="300dp" android:layout_height="300dp" android:src="@mipmap/img_meizi" /> <EditText android:id="@+id/edit_mul" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/img_meizi" android:text="0" /> <EditText android:id="@+id/edit_add" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/edit_mul" android:text="0" /> <Button android:id="@+id/btn_change" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignRight="@id/img_meizi" android:layout_below="@id/img_meizi" android:text="變化" /> </RelativeLayout> ~~~ 接著是我們的**MainActiivty.java**,同樣很簡單: ~~~ public class MainActivity extends AppCompatActivity implements View.OnClickListener{ private ImageView img_meizi; private EditText edit_mul; private EditText edit_add; private Button btn_change; private Bitmap mBitmap; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mBitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.img_meizi); bindViews(); } private void bindViews() { img_meizi = (ImageView) findViewById(R.id.img_meizi); edit_mul = (EditText) findViewById(R.id.edit_mul); edit_add = (EditText) findViewById(R.id.edit_add); btn_change = (Button) findViewById(R.id.btn_change); btn_change.setOnClickListener(this); } private Bitmap ProcessImage(Bitmap bp,int mul,int add){ Bitmap bitmap = Bitmap.createBitmap(bp.getWidth(),bp.getHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); paint.setColorFilter(new LightingColorFilter(mul,add)); canvas.drawBitmap(bp,0,0,paint); return bitmap; } @Override public void onClick(View v) { switch (v.getId()){ case R.id.btn_change: int mul = Integer.parseInt(edit_mul.getText().toString()); int add = Integer.parseInt(edit_add.getText().toString()); img_meizi.setImageBitmap(ProcessImage(mBitmap,mul,add)); break; } } } ~~~ 好了,LightingColorFilter的使用演示完畢~ * * * ## 3.本節代碼下載 [LightingColorFilterDemo.zip](http://static.runoob.com/download/LightingColorFilterDemo.zip) * * * ## 本節小結: > 嗯,本節演示了一下LightingColorFilter的一個基本用法,用來模擬簡單的燈光效果, 實現簡單的圖片處理效果,好的,本節就到這里,謝謝~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看