zoukankan      html  css  js  c++  java
  • Android 调用系统自带的拍照,返回JPG文件

    /Files/jxgxy/testCamera1.rar


    package com.eboy.testcamera1;

    import java.io.File;
    import java.io.FileOutputStream;

    import android.app.Activity;
    import android.content.Intent;
    import android.graphics.Bitmap;
    import android.os.Bundle;
    import android.os.Environment;
    import android.provider.MediaStore;
    import android.view.Menu;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.widget.Button;
    import android.widget.Toast;

    public class MainActivity extends Activity {

        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            
            Button button = (Button) findViewById(R.id.button1);          
            button.setOnClickListener(new OnClickListener() {    
                @Override  
                public void onClick(View v) {  
                    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);  
                    startActivityForResult(intent, 1);  
                }  
            });
            
        }

        private void startCamera(View v) {
            Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            startActivityForResult(intent, 1);        
        }

        @Override
        public boolean onCreateOptionsMenu(Menu menu) {
            getMenuInflater().inflate(R.menu.activity_main, menu);
            return true;
        }
        
        @Override
        protected void onActivityResult(int requestCode, int resultCode, Intent data) {
            Bitmap bitmap = (Bitmap)data.getExtras().get("data");
            File file = new File(Environment.getExternalStorageDirectory() + "/myImage/");
            file.mkdirs();
            String fileName = Environment.getExternalStorageDirectory() + "/myImage/" + System.currentTimeMillis() + ".jpg";
            try {
                FileOutputStream b = new FileOutputStream(fileName);
                bitmap.compress(Bitmap.CompressFormat.JPEG, 100, b);
                b.flush();
                b.close();
                Toast.makeText(getApplicationContext(), "照片已保存到:" + fileName, Toast.LENGTH_LONG).show();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }    

  • 相关阅读:
    DNS 原理入门
    DiG HOWTO How to use dig to query DNS name servers.
    Top 10 Free Wireless Network hacking/monitoring tools for ethical hackers and businesses
    LoadRunner:视频教程、课件
    Android:开发环境搭建相关问题
    Android:使用代理服务器安装SDKs
    JavaSe:Cookie 管理的API介绍
    使用 Eclipse 玩转 C、C++
    C++: 主要知识点
    C、C++: 引用、指针、实例、内存模型、namespace
  • 原文地址:https://www.cnblogs.com/jxgxy/p/2623319.html
Copyright © 2011-2022 走看看