Android中復(fù)制圖片的實(shí)例代碼
activity_main.xml中的配置
<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:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" android:orientation="vertical" tools:context=".MainActivity" > <ImageView android:id="@+id/iv_one" android:layout_width="wrap_content" android:layout_height="wrap_content"/> <ImageView android:id="@+id/iv_two" android:layout_width="wrap_content" android:layout_height="wrap_content"/> </LinearLayout>
MainActivity中代碼:
public class MainActivity extends Activity {
private ImageView ivOne;
private ImageView ivTwo;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//1.獲取圖片控件
ivOne = (ImageView) findViewById(R.id.iv_one);
ivTwo = (ImageView) findViewById(R.id.iv_two);
//2.把tomcat.png 轉(zhuǎn)換成bitmap 然后顯示到iv_src
Bitmap srcBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.tomcat);
//3.將原圖放置在第一個(gè)控件中
ivOne.setImageBitmap(srcBitmap);
//4.創(chuàng)建原圖模板
Bitmap copybitmap = Bitmap.createBitmap(srcBitmap.getWidth(), srcBitmap.getHeight(), srcBitmap.getConfig());
//5.想作畫 需要一個(gè)畫布 以copybitmap為模板
Canvas canvas = new Canvas(copybitmap);
//6.創(chuàng)建一個(gè)畫筆
Paint paint = new Paint();
//7.開始作畫 srcBitmap參考原圖去畫
canvas.drawBitmap(srcBitmap, new Matrix(), paint);
for (int i = 0; i < 10; i++) {
//[一次修改多個(gè)像素]
copybitmap.setPixel(20+i,30, Color.RED);
}
//8.把copybitmap顯示到ivTwo上
ivTwo.setImageBitmap(copybitmap);
}
}
總結(jié)
以上所述是小編給大家介紹的Android中復(fù)制圖片的實(shí)例代碼,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!
相關(guān)文章
Android入門教程之ListView的應(yīng)用示例
這篇文章主要介紹了Android入門教程之ListView的應(yīng)用,結(jié)合簡單實(shí)例形式分析了Android中l(wèi)istview的簡單創(chuàng)建與使用步驟,需要的朋友可以參考下2016-10-10
Android?Studio實(shí)現(xiàn)簡易計(jì)算器App?(Java語言版)
這篇文章主要為大家詳細(xì)介紹了Android?Studio實(shí)現(xiàn)簡易計(jì)算器App,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-05-05
Android使用Intent隱式實(shí)現(xiàn)頁面跳轉(zhuǎn)
這篇文章主要為大家詳細(xì)介紹了Android使用Intent隱式來實(shí)現(xiàn)向上跳轉(zhuǎn),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-08-08
Android判斷后臺服務(wù)是否開啟的兩種方法實(shí)例詳解
這篇文章主要介紹了Android判斷后臺服務(wù)是否開啟的方法的相關(guān)資料,這里提供了兩種方法及實(shí)例,需要的朋友可以參考下2017-07-07
Android onCreateOptionsMenu的使用方法總結(jié)
這篇文章主要介紹了Android onCreateOptionsMenu的使用方法總結(jié)的相關(guān)資料,在Android下,每一個(gè)activity都捆綁了一個(gè)Menu,要想定義和使用菜單,都必須在Activity下進(jìn)行操作,需要的朋友可以參考下2017-08-08

