在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 教程/ Android/ Android圖片效果
Android 應(yīng)用組件
使用布局文件自定義Android組件
Android通知
Android主題示例
Android JetPlayer實(shí)例
Android MediaPlayer(多媒體播放)
Android AbsoluteLayout
Android FrameLayout
Android Gestures/手勢(shì)
Android AutoCompleteTextView(自動(dòng)完成)實(shí)例
Android 資源組織和訪(fǎng)問(wèn)
Android ListView
Android GridView
Android數(shù)據(jù)備份
Android撥打電話(huà)
Android發(fā)送短信/SMS
Android ProgressDialog
SimpleCursorAdapter
Android發(fā)送電子郵件
Android Activity
Android TextView
Android事件處理
Android TableLayout
Android加載Spinner
Android內(nèi)容提供者
Android自定義字體
Android Service
Android CheckBox
Android Intent過(guò)濾器
Android LinearLayout
Android登錄實(shí)例
Android RadioButton
Android樣式和主題
Android自定義組件及屬性
Android UI控件
Android Animation(動(dòng)畫(huà))實(shí)例
Android Camera(攝像頭)
Android ToggleButton
Android Clipboard(復(fù)制/剪貼板)
Android音頻捕獲(錄音)
發(fā)布Android應(yīng)用
Android Alertdialog(警告對(duì)話(huà)框)
Android圖片效果
Android內(nèi)部存儲(chǔ)
Android基于位置服務(wù)
Android RadioGroup
Android AutoCompleteTextView
Android Bluetooth(藍(lán)牙)實(shí)例
Android RelativeLayout
Android最佳實(shí)踐
Android本地化
Android自定義組件
Android教程
Android 架構(gòu)
Android UI布局
Android Button
Android Hello World示例
Android音頻管理器實(shí)例
ArrayAdapter
Android拖放
Android碎片/片段
Android圖片切換
Android JSON解析器
Android開(kāi)發(fā)環(huán)境搭建
Android Spinner
Android樣式示例
使用活動(dòng)代碼自定義Android組件
Android ImageButton
Android EditText
Android廣播接收器

Android圖片效果

Android的允許通過(guò)添加不同種類(lèi)的處理圖像效果??梢暂p松地應(yīng)用圖像處理技術(shù)來(lái)增加某些種類(lèi)的圖像效果。這些影響可能是亮度,黑暗中,灰度轉(zhuǎn)換等

Android提供了Bitmap類(lèi)來(lái)處理圖像。這可以在 android.graphics.bitmap 下找到。有很多種方法,通過(guò)它可以位圖 Bitmap 實(shí)例調(diào)用。如下創(chuàng)建的圖像從ImageView的位圖。

private Bitmap bmp;
private ImageView img;
img = (ImageView)findViewById(R.id.imageView1);
BitmapDrawable  abmp = (BitmapDrawable)img.getDrawable();

現(xiàn)在,我們將通過(guò)調(diào)用BitmapDrawable類(lèi)的getBitmap()函數(shù)來(lái)創(chuàng)建位圖。它的語(yǔ)法如下:

bmp = abmp.getBitmap();

圖像不過(guò)是一個(gè)二維矩陣。同樣的方式處理位圖。圖像由像素組成。所以,從中得到位圖的像素并應(yīng)用處理它。它的語(yǔ)法如下:

for(int i=0; i<bmp.getWidth(); i++){
   for(int j=0; j<bmp.getHeight(); j++){
      int p = bmp.getPixel(i, j);
   }
}

所述的 getWidth()和 getHeight()函數(shù)返回矩陣的高度和寬度。使用getPixel()方法返回像素的指定索引處。得到了像素之后可以根據(jù)需要方便地操縱它。

除了這些方法,還有其他方法,幫助我們更好地處理圖像。

Sr.No 方法及說(shuō)明
1 copy(Bitmap.Config config, boolean isMutable)
這種方法復(fù)制此位圖的像素到新位圖
2 createBitmap(DisplayMetrics display, int width, int height, Bitmap.Config config)
返回一個(gè)可變的位圖指定的寬度和高度
3 createBitmap(int width, int height, Bitmap.Config config)
返回一個(gè)可變的位圖指定的寬度和高度
4 createBitmap(Bitmap src)
從源位圖返回一個(gè)不可變位
5 extractAlpha()
返回一個(gè)新的位圖,它捕獲原有的alpha值
6 getConfig()
這個(gè)方法返回配置,或者返回null
7 getDensity()
返回此位圖密度
8 getRowBytes()
返回位圖的像素字節(jié)行之間的數(shù)
9 setPixel(int x, int y, int color)
寫(xiě)入指定的顏色成位圖(假設(shè)它是可變的)在X,Y坐標(biāo)
10 setDensity(int density)
這種方法指定此位圖的密度

例子

下面的例子演示了一些對(duì)位圖上的圖像效果。它創(chuàng)建了一個(gè)基本的應(yīng)用程序,讓圖片轉(zhuǎn)換成灰度等等。

為了試驗(yàn)這個(gè)例子,需要在實(shí)際設(shè)備上運(yùn)行此程序。

步驟 描述
1 使用Eclipse IDE創(chuàng)建Android應(yīng)用程序,并將其命名為 ImageEffects。在創(chuàng)建這個(gè)項(xiàng)目時(shí)確保目標(biāo)SDK編譯在A(yíng)ndroid SDK的最新版本或使用更高級(jí)別的API。
2 修改 src/MainActivity.java文件中添加必要的代碼
3 修改res/layout/activity_main添加相應(yīng)的XML組件
4 修改res/values/string.xml添加必要的字符串
5 運(yùn)行應(yīng)用程序并選擇運(yùn)行Android的設(shè)備,并在其上安裝的應(yīng)用和驗(yàn)證結(jié)果

以下是修改主活動(dòng)文件的內(nèi)容src/com.yiibai.imageeffects/MainActivity.java.

package com.example.imageeffects;

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.ImageView;

public class MainActivity extends Activity {

   private ImageView img;
   private Bitmap bmp;
   private Bitmap operation;

   @Override
   protected void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   setContentView(R.layout.activity_main);

   img = (ImageView)findViewById(R.id.imageView1);
   BitmapDrawable  abmp = (BitmapDrawable)img.getDrawable();
   bmp = abmp.getBitmap();

   }

   public void gray(View view){
      operation= Bitmap.createBitmap(bmp.getWidth(),
      bmp.getHeight(),bmp.getConfig());

      double red = 0.33;
      double green = 0.59;
      double blue = 0.11;

   for(int上一篇:Android撥打電話(huà)下一篇:Android LinearLayout