package test.com;
import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
public class Demo_picActivity extends Activity
{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
// this.requestWindowFeature(Window.FEATURE_NO_TITLE);
// this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(new picRe(this));
}
class picRe extends View
{
public picRe(Context context)
{
super(context);
}
public picRe(Context context,String[] path)
{
super(context);
this.path = path;
}
public picRe(Context context, String[] path, int width, int height)
{
super(context);
this.path = path;
this.width = width;
this.height = height;
}
@Override
protected void onDraw(Canvas canvas)
{
super.onDraw(canvas);
int height_sum = border;
Bitmap pic[] = new Bitmap[path.length];
for (int i = 0; i < pic.length; i++)
{
pic[i] = Bitmap.createScaledBitmap(BitmapFactory.decodeFile(path[i]), width, height, true);
height_sum += pic[i].getHeight() + border;
}
Bitmap new_pic = Bitmap.createBitmap(width + border * 2, height_sum, Config.ARGB_8888);
Canvas _reCanvas = new Canvas(new_pic);
_reCanvas.drawColor(-1);
for (int i = 0; i < pic.length; i++)
{
_reCanvas.drawBitmap(pic[i], border, height * i + border * i + border, null);
pic[i].recycle();
}
Matrix new_pic_Matrix = canvas.getMatrix();
new_pic_Matrix.postScale(200.0f / (float)width, 200.0f / (float)width);
canvas.setMatrix(new_pic_Matrix);
canvas.drawBitmap(new_pic, 0, 150, null);
}
private String[] path = {"data/data/com.test/filse/you.jpg", "data/data/com.test/filse/test.gif", "data/data/com.test/filse/you.jpg"};
private int width = 480;
private int height = 480;
private int border = 5;
}
}
使用android的bitmap类实现图片的拼接
最新推荐文章于 2025-05-17 18:59:20 发布