zoukankan      html  css  js  c++  java
  • android 图片合成

    
    
    package com.ebensz.eink.demo;
    
    import java.io.File;
    import java.io.FileOutputStream;
    
    import android.app.Activity;
    import android.graphics.Bitmap;
    import android.graphics.Bitmap.CompressFormat;
    import android.graphics.Canvas;
    import android.graphics.Matrix;
    import android.os.Bundle;
    import android.view.View;
    import android.view.View.MeasureSpec;
    import android.view.View.OnClickListener;
    import android.widget.Button;
    
    public class Exchange extends Activity implements OnClickListener {
        private Bitmap bitmap1;
        private Button mExportBtn;
        private static final String BITMAP_He = "/sdcard/bitmap_add.png";
    
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.scrollview);
    
            mExportBtn = (Button) this.findViewById(R.id.export_he);
            mExportBtn.setOnClickListener(this);
        }
    
        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            switch (v.getId()) {
            case R.id.export_he:
                exportAll();
                break;
            default:
                break;
            }
        }
    
        /**
         * 将布局转换为View类型对象
         * @param filename
         */
        private void exportAll( ) {
            View view = getLayoutInflater().inflate(R.layout.scrollview, null);
            view.setDrawingCacheEnabled(true);
            view.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
                    MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
            view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight());
            try {
                bitmap1 = view.getDrawingCache();
                heCheng(BITMAP_He);
            } catch (Exception e) {
    
            }
        }
    
        /**
         * bitmap1 考评结果图片
         * bitmap2 签字图片
         * bitmap3 带签字的考评结果
         * @param filename 生成带签字考评结果的文件路径和文件名
         */
        private void heCheng(String filename) {
    
            Bitmap bitmap2 = MainActivity.mbitmap;
            Bitmap bitmap3 = Bitmap.createBitmap(bitmap1.getWidth(),
                    bitmap1.getHeight(), bitmap1.getConfig());
            Canvas canvas = new Canvas(bitmap3);
            canvas.drawBitmap(bitmap1, new Matrix(), null);
            canvas.drawBitmap(bitmap2, 20, 1000, null); // 120、350为bitmap2写入点的x、y坐标
            try {
                FileOutputStream out = new FileOutputStream(filename);
                bitmap3.compress(Bitmap.CompressFormat.PNG, 90, out);
                out.close();
            } catch (Exception e) {
    
            }
        }
    
    }
  • 相关阅读:
    IIC时序和24C02读写字节时序
    Labview-vi的可重入性
    Labview笔记-创建自定义控件
    非院校科研机构如何查阅下载文献?
    【转】经典的图像去噪算法NLM和BM3D算法
    【转载】计算机科学最重要的32个算法
    图像存储方式
    二维物体形状识别方法比较
    论static关键词
    论引用
  • 原文地址:https://www.cnblogs.com/qinaidexin/p/4560797.html
Copyright © 2011-2022 走看看