• 团队冲刺第二阶段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); 
            } 
        } 
    }
  • 相关阅读:
    struts.xml文件中package元素的各大属性讲解
    strus2 struts.xml详解
    既使用maven编译,又使用lib下的Jar包
    Maven项目同时使用lib下的Jar包
    PreparedStatement ResultSet
    SearchBySql
    java 生成GUID
    获取当前时间的字符串
    C#字符串比较
    浮点数比较大小
  • 原文地址:https://www.cnblogs.com/xjmm/p/13085218.html
Copyright © 2020-2023  润新知