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自定義密碼輸入框的簡(jiǎn)單實(shí)現(xiàn)過(guò)程
在最近的項(xiàng)目中,用戶需要輸入密碼,不想用系統(tǒng)鍵盤(pán),就寫(xiě)了一個(gè)自定義鍵盤(pán),下面這篇文章主要給大家介紹了關(guān)于Android自定義密碼輸入框的簡(jiǎn)單實(shí)現(xiàn)過(guò)程,需要的朋友可以參考下2021-11-11
Android監(jiān)聽(tīng)?wèi)?yīng)用前臺(tái)的實(shí)現(xiàn)方案
在 Android 應(yīng)用開(kāi)發(fā)中,監(jiān)聽(tīng)?wèi)?yīng)用前臺(tái)狀態(tài)是一項(xiàng)核心功能,對(duì)于優(yōu)化用戶體驗(yàn)、提升資源管理效率以及實(shí)現(xiàn)系統(tǒng)級(jí)功能具有重要意義,以下將從技術(shù)實(shí)現(xiàn)、業(yè)務(wù)場(chǎng)景和系統(tǒng)特性等多個(gè)維度,深入探討幾種主流的實(shí)現(xiàn)方案,需要的朋友可以參考下2025-02-02
android客戶端從服務(wù)器端獲取json數(shù)據(jù)并解析的實(shí)現(xiàn)代碼
今天總結(jié)一下android客戶端從服務(wù)器端獲取json數(shù)據(jù)的實(shí)現(xiàn)代碼,需要的朋友可以參考下2013-06-06
Android自定義EditText實(shí)現(xiàn)登錄界面
這篇文章主要為大家詳細(xì)介紹了Android自定義EditText實(shí)現(xiàn)登錄界面,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-12-12
Android OpenGL ES 實(shí)現(xiàn)抖音傳送帶特效(原理解析)
這篇文章主要介紹了Android OpenGL ES 實(shí)現(xiàn)抖音傳送帶特效,抖音傳送帶特效推出已經(jīng)很長(zhǎng)一段時(shí)間了,前面也實(shí)現(xiàn)了下,最近把它整理出來(lái)了,如果你有仔細(xì)觀測(cè)傳送帶特效,就會(huì)發(fā)現(xiàn)它的實(shí)現(xiàn)原理其實(shí)很簡(jiǎn)單,需要的朋友可以參考下2022-07-07

