Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲
 Android教程網 >> Android技術 >> 關於Android編程 >> Android FotoMix

Android FotoMix

編輯:關於Android編程

the xml layout file is simple.u just need a imageview:

activity_main.xml:



    



MainActivity.java:

package com.example.pictogether;

import android.R.color;
import android.os.Bundle;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.PorterDuffXfermode;
import android.view.Menu;
import android.widget.ImageView;

public class MainActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		ImageView iv = (ImageView)findViewById(R.id.iv);
		
//		//photo mix ,Canvas draw the pic1 first and draw the pic2 later.
		Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.face);
		
		Bitmap alertBitmap = Bitmap.createBitmap(bitmap.getWidth(),bitmap.getHeight(),bitmap.getConfig());
		
		Canvas canvas = new Canvas(alertBitmap);
		Paint paint = new Paint();
		
		canvas.drawBitmap(bitmap,0,0, paint);
		Bitmap ic_luncher = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
   		canvas.drawBitmap(ic_luncher, 0,0, paint);
		
		iv.setImageBitmap(alertBitmap);
		
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

}

Final Result::


  1. 上一頁:
  2. 下一頁:
熱門文章
閱讀排行版
Copyright © Android教程網 All Rights Reserved