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.將原圖放置在第一個控件中
ivOne.setImageBitmap(srcBitmap);
//4.創(chuàng)建原圖模板
Bitmap copybitmap = Bitmap.createBitmap(srcBitmap.getWidth(), srcBitmap.getHeight(), srcBitmap.getConfig());
//5.想作畫 需要一個畫布 以copybitmap為模板
Canvas canvas = new Canvas(copybitmap);
//6.創(chuàng)建一個畫筆
Paint paint = new Paint();
//7.開始作畫 srcBitmap參考原圖去畫
canvas.drawBitmap(srcBitmap, new Matrix(), paint);
for (int i = 0; i < 10; i++) {
//[一次修改多個像素]
copybitmap.setPixel(20+i,30, Color.RED);
}
//8.把copybitmap顯示到ivTwo上
ivTwo.setImageBitmap(copybitmap);
}
}
總結(jié)
以上所述是小編給大家介紹的Android中復(fù)制圖片的實(shí)例代碼,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!
相關(guān)文章
Android自定義密碼輸入框的簡單實(shí)現(xiàn)過程
在最近的項(xiàng)目中,用戶需要輸入密碼,不想用系統(tǒng)鍵盤,就寫了一個自定義鍵盤,下面這篇文章主要給大家介紹了關(guān)于Android自定義密碼輸入框的簡單實(shí)現(xiàn)過程,需要的朋友可以參考下2021-11-11
Android監(jiān)聽?wèi)?yīng)用前臺的實(shí)現(xiàn)方案
在 Android 應(yīng)用開發(fā)中,監(jiān)聽?wèi)?yīng)用前臺狀態(tài)是一項(xiàng)核心功能,對于優(yōu)化用戶體驗(yàn)、提升資源管理效率以及實(shí)現(xiàn)系統(tǒng)級功能具有重要意義,以下將從技術(shù)實(shí)現(xiàn)、業(yè)務(wù)場景和系統(tǒng)特性等多個維度,深入探討幾種主流的實(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)很長一段時間了,前面也實(shí)現(xiàn)了下,最近把它整理出來了,如果你有仔細(xì)觀測傳送帶特效,就會發(fā)現(xiàn)它的實(shí)現(xiàn)原理其實(shí)很簡單,需要的朋友可以參考下2022-07-07

