Android中復制圖片的實例代碼
更新時間:2017年08月23日 17:27:03 作者:su708877595
本文通過實例代碼給大家介紹了android 復制圖片的實現(xiàn)方法,非常不錯,具有參考借鑒價值,需要的朋友參考下吧
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); } }
總結
以上所述是小編給大家介紹的Android中復制圖片的實例代碼,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!
相關文章
Android?Studio實現(xiàn)簡易計算器App?(Java語言版)
這篇文章主要為大家詳細介紹了Android?Studio實現(xiàn)簡易計算器App,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下2022-05-05Android使用Intent隱式實現(xiàn)頁面跳轉(zhuǎn)
這篇文章主要為大家詳細介紹了Android使用Intent隱式來實現(xiàn)向上跳轉(zhuǎn),具有一定的參考價值,感興趣的小伙伴們可以參考一下2018-08-08Android onCreateOptionsMenu的使用方法總結
這篇文章主要介紹了Android onCreateOptionsMenu的使用方法總結的相關資料,在Android下,每一個activity都捆綁了一個Menu,要想定義和使用菜單,都必須在Activity下進行操作,需要的朋友可以參考下2017-08-08