zoukankan      html  css  js  c++  java
  • 团队冲刺第二阶段08

    今天学了安卓程序的拍照功能,在网上学了相关的内容,写了简单的代码实现,明天在程序中加入,和其他代码整合。

    import android.app.Activity; 
    import android.content.Intent; 
    import android.graphics.Bitmap; 
    import android.os.Bundle; 
    import android.provider.MediaStore; 
    import android.util.Log;
    
    public class PhotographActivity extends Activity { 
        /** Called when the activity is first created. */ 
        private String logTag = "Exception"; 
        @Override 
        public void onCreate(Bundle savedInstanceState) { 
            super.onCreate(savedInstanceState); 
            setContentView(R.layout.main); 
            try { 
                 Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); 
                 startActivityForResult(intent, 0); 
            } catch (Exception e) { 
                Log.v(logTag, e.getMessage()); 
            } 
        }
    
        protected void onActivityResult(int requestCode, int resultCode, Intent data) 
        { 
            try { 
                if (requestCode != 0) { 
                    return; 
                } 
                super.onActivityResult(requestCode, resultCode, data);
    
                Bundle extras = data.getExtras(); 
                Bitmap b = (Bitmap) extras.get("data"); 
                Intent intent = new Intent();
    
                //得到图片后,我们在另一个activity中显示 
                intent.setClass(this, ShowImageActivity.class); 
                intent.putExtra("image",b); 
                this.startActivity(intent); 
            } catch (Exception e) { 
                // TODO: handle exception 
                Log.v(logTag, e.getMessage()); 
            } 
        }
    
    }
    
    新建一个显示图片的activity。这样,在这个activity中就可以对图片做其他更多的操作。
    
    import android.app.Activity; 
    import android.graphics.Bitmap; 
    import android.os.Bundle; 
    import android.util.Log; 
    import android.widget.ImageView;
    
    public class ShowImageActivity extends Activity {
    
        private String logTag = "exception";
    
        private ImageView view; 
        @Override 
        protected void onCreate(Bundle savedInstanceState) { 
            super.onCreate(savedInstanceState); 
            setContentView(R.layout.show);
    
            try { 
                view = (ImageView) findViewById(R.id.view);   
                Bundle bundle = this.getIntent().getExtras(); 
                Bitmap b = bundle.getParcelable("image"); 
                view.setImageBitmap(b); 
                //setContentView(view); 
            } catch (Exception e) { 
                Log.v(logTag, e.getMessage()); 
                throw new RuntimeException(e); 
            } 
        } 
    }
  • 相关阅读:
    HD1205吃糖果(鸽巢、抽屉原理)
    POJ3628 Bookshelf 2(01背包+dfs)
    poj1631Bridging signals(最长单调递增子序列 nlgn)
    【转】KMP算法
    Intern Day1
    记 MINIEYE C++应用开发实习生技术一面
    解决Mac下CLion无法编译运行多个cpp的问题
    记赛目科技C++开发工程师实习生技术面
    Git总结
    Docker学习大纲
  • 原文地址:https://www.cnblogs.com/xjmm/p/13085218.html
Copyright © 2011-2022 走看看