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.想作畫(huà) 需要一個(gè)畫(huà)布 以copybitmap為模板 Canvas canvas = new Canvas(copybitmap); //6.創(chuàng)建一個(gè)畫(huà)筆 Paint paint = new Paint(); //7.開(kāi)始作畫(huà) srcBitmap參考原圖去畫(huà) 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í)例代碼,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
相關(guān)文章
Android入門教程之ListView的應(yīng)用示例
這篇文章主要介紹了Android入門教程之ListView的應(yīng)用,結(jié)合簡(jiǎn)單實(shí)例形式分析了Android中l(wèi)istview的簡(jiǎn)單創(chuàng)建與使用步驟,需要的朋友可以參考下2016-10-10Android實(shí)現(xiàn)簡(jiǎn)單音樂(lè)播放控件
這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)簡(jiǎn)單音樂(lè)播放控件,提供一個(gè)類似網(wǎng)易播放控件的默認(rèn)界面,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-04-04Android?Studio實(shí)現(xiàn)簡(jiǎn)易計(jì)算器App?(Java語(yǔ)言版)
這篇文章主要為大家詳細(xì)介紹了Android?Studio實(shí)現(xiàn)簡(jiǎn)易計(jì)算器App,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-05-05Android使用Intent隱式實(shí)現(xiàn)頁(yè)面跳轉(zhuǎn)
這篇文章主要為大家詳細(xì)介紹了Android使用Intent隱式來(lái)實(shí)現(xiàn)向上跳轉(zhuǎn),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-08-08Android判斷后臺(tái)服務(wù)是否開(kāi)啟的兩種方法實(shí)例詳解
這篇文章主要介紹了Android判斷后臺(tái)服務(wù)是否開(kāi)啟的方法的相關(guān)資料,這里提供了兩種方法及實(shí)例,需要的朋友可以參考下2017-07-07Android onCreateOptionsMenu的使用方法總結(jié)
這篇文章主要介紹了Android onCreateOptionsMenu的使用方法總結(jié)的相關(guān)資料,在Android下,每一個(gè)activity都捆綁了一個(gè)Menu,要想定義和使用菜單,都必須在Activity下進(jìn)行操作,需要的朋友可以參考下2017-08-08