狠狠色丁香婷婷综合尤物/久久精品综合一区二区三区/中国有色金属学报/国产日韩欧美在线观看 - 国产一区二区三区四区五区tv

LOGO OA教程 ERP教程 模切知識(shí)交流 PMS教程 CRM教程 開(kāi)發(fā)文檔 其他文檔  
 
網(wǎng)站管理員

android照相及照片上傳實(shí)現(xiàn)代碼

admin
2013年2月25日 13:26 本文熱度 4492
本文章來(lái)介紹了關(guān)于手機(jī)開(kāi)發(fā)之a(chǎn)ndroid來(lái)實(shí)現(xiàn)android照相及照片功能,有需要學(xué)習(xí)的同學(xué)可以參考一下。
 代碼如下
package com.android.cist.camera.view; 
import java.io.ByteArrayOutputStream; 
import java.io.InputStream; 
import java.util.HashMap; 
import java.util.Map; 
import android.app.Activity; 
import android.app.AlertDialog; 
import android.content.ContentResolver; 
import android.content.DialogInterface; 
import android.content.Intent; 
import android.graphics.Bitmap; 
import android.graphics.BitmapFactory; 
import android.net.Uri; 
import android.os.Bundle; 
import android.os.Handler; 
import android.os.Message; 
import android.view.View; 
import android.view.View.OnClickListener; 
import android.widget.Button; 
import android.widget.EditText; 
import android.widget.ImageView; 
import android.widget.LinearLayout; 
import android.widget.Toast; 
import com.android.cist.R; 
import com.android.cist.network.HttpUtil; 
import com.android.cist.network.form.FormFile; 
import com.android.cist.network.form.HttpFormUtil; 
import com.android.cist.util.ApplicationUtil; 
import com.android.cist.util.ImageUtil; 
public class CameraActivity extends Activity implements OnClickListener{ 
    private ImageView preview; 
    private EditText carNo; 
    private EditText addres; 
    private EditText type; 
    private Button back; 
    private Button submit; 
    private Button capture; 
    private Button reCapture; 
    private OnClickListener imgViewListener; 
    private Bitmap myBitmap; 
    private byte[] mContent; 
    private Handler handler; 
    String returnString; 
    private CalendarView happenDate; 
    private static final int REQUEST_CAMERA = 1; 
    private static final int REQUEST_CALENDAR = 2; 
    @ Override 
    public void onCreate ( Bundle savedInstanceState ) 
    { 
        super.onCreate(savedInstanceState); 
        setContentView(R.layout.camera); 
        setUpViews(); 
        setUpListeners(); 
        ApplicationUtil.getInstance().addActivity(this); 
    } 
    @ Override 
    protected void onActivityResult ( int requestCode , int resultCode , Intent data ) 
    { 
        super.onActivityResult(requestCode, resultCode, data); 
        ContentResolver resolver = getContentResolver(); 
        /**
         * 因?yàn)閮煞N方式都用到了startActivityForResult方法,
         * 這個(gè)方法執(zhí)行完后都會(huì)執(zhí)行onActivityResult方法, 所以為了區(qū)別到底選擇了那個(gè)方式獲取圖片要進(jìn)行判斷,
         * 這里的requestCode跟startActivityForResult里面第二個(gè)參數(shù)對(duì)應(yīng)
         */ 
        if (requestCode == 0) 
        { 
            try 
            { 
                // 獲得圖片的uri 
                Uri originalUri = data.getData(); 
                // 將圖片內(nèi)容解析成字節(jié)數(shù)組 
                mContent = readStream(resolver.openInputStream(Uri.parse(originalUri.toString()))); 
                // 將字節(jié)數(shù)組轉(zhuǎn)換為ImageView可調(diào)用的Bitmap對(duì)象 
                myBitmap = getPicFromBytes(mContent, null); 
                // //把得到的圖片綁定在控件上顯示 
                preview.setImageBitmap(myBitmap); 
            } catch ( Exception e ) 
            { 
                System.out.println(e.getMessage()); 
            } 
        } else if (requestCode == REQUEST_CAMERA){ 
            try 
            { 
                super.onActivityResult(requestCode, resultCode, data); 
                Bundle extras = data.getExtras(); 
                myBitmap = (Bitmap) extras.get("data"); 
                ByteArrayOutputStream baos = new ByteArrayOutputStream(); 
                myBitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos); 
                mContent = baos.toByteArray(); 
            } catch ( Exception e ) 
            { 
                e.printStackTrace(); 
            } 
            // 把得到的圖片綁定在控件上顯示 
            preview.setImageBitmap(ImageUtil.toRoundCorner(myBitmap, 10));//把拍攝的照片轉(zhuǎn)成圓角顯示在預(yù)覽控件上 
        }else if(requestCode==REQUEST_CALENDAR){ 
            if(resultCode == RESULT_OK){ 
                happenDate.setCalendar(data.getIntExtra("year", 1900), data.getIntExtra("month", 0), data.getIntExtra("day", 1)); 
            } 
        } 
    } 
    public static Bitmap getPicFromBytes ( byte[] bytes , BitmapFactory.Options opts ) 
    { 
        if (bytes != null) 
            if (opts != null) 
                return BitmapFactory.decodeByteArray(bytes, 0, bytes.length, opts); 
            else 
                return BitmapFactory.decodeByteArray(bytes, 0, bytes.length); 
        return null; 
    } 
    public static byte[] readStream ( InputStream inStream ) throws Exception 
    { 
        byte[] buffer = new byte[1024]; 
        int len = -1; 
        ByteArrayOutputStream outStream = new ByteArrayOutputStream(); 
        while ((len = inStream.read(buffer)) != -1) 
        { 
            outStream.write(buffer, 0, len); 
        } 
        byte[] data = outStream.toByteArray(); 
        outStream.close(); 
        inStream.close(); 
        return data; 
    } 
    @Override 
    public void onClick(View v) { 
        int id = v.getId(); 
        switch(id){ 
            case R.id.capture:{ 
                final CharSequence[] items = 
                { "相冊(cè)", "拍照" }; 
                AlertDialog dlg = new AlertDialog.Builder(CameraActivity.this).setTitle("選擇圖片").setItems(items, 
                        new DialogInterface.OnClickListener() 
                        { 
                            public void onClick ( DialogInterface dialog , int item ) 
                            { 
                                // 這里item是根據(jù)選擇的方式, 
                                // 在items數(shù)組里面定義了兩種方式,拍照的下標(biāo)為1所以就調(diào)用拍照方法 
                                if (item == 1){ 
                                    Intent getImageByCamera = new Intent("android.media.action.IMAGE_CAPTURE"); 
                                    startActivityForResult(getImageByCamera, REQUEST_CAMERA); 
                                } else{ 
                                    Intent getImage = new Intent(Intent.ACTION_GET_CONTENT); 
                                    getImage.addCategory(Intent.CATEGORY_OPENABLE); 
                                    getImage.setType("image/jpeg"); 
                                    startActivityForResult(getImage, 0); 
                                } 
                            } 
                        }).create(); 
                dlg.show(); 
            } 
            break; 
            /*case R.id.reCapture:{
                final CharSequence[] items =
                { "相冊(cè)", "拍照" };
                AlertDialog dlg = new AlertDialog.Builder(CameraActivity.this).setTitle("選擇圖片").setItems(items,
                        new DialogInterface.OnClickListener()
                        {
                            public void onClick ( DialogInterface dialog , int item )
                            {
                                // 這里item是根據(jù)選擇的方式,
                                // 在items數(shù)組里面定義了兩種方式,拍照的下標(biāo)為1所以就調(diào)用拍照方法
                                if (item == 1)
                                {
                                    Intent getImageByCamera = new Intent("android.media.action.IMAGE_CAPTURE");
                                    startActivityForResult(getImageByCamera, 1);
                                } else
                                {
                                    Intent getImage = new Intent(Intent.ACTION_GET_CONTENT);
                                    getImage.addCategory(Intent.CATEGORY_OPENABLE);
                                    getImage.setType("image/jpeg");
                                    startActivityForResult(getImage, 0);
                                }
                            }
                        }).create();
                dlg.show();
            }
            break;*/ 
            case R.id.submit:{ 
                new PostThread().start();//開(kāi)啟線程提交數(shù)據(jù) 
            } 
            break; 
            case R.id.back:{ 
                CameraActivity.this.finish();//返回,銷(xiāo)毀當(dāng)前Activity 
            } 
            break; 
            default: 
            break; 
        } 
    } 

該文章在 2013/2/25 13:26:08 編輯過(guò)
關(guān)鍵字查詢
相關(guān)文章
正在查詢...
點(diǎn)晴ERP是一款針對(duì)中小制造業(yè)的專業(yè)生產(chǎn)管理軟件系統(tǒng),系統(tǒng)成熟度和易用性得到了國(guó)內(nèi)大量中小企業(yè)的青睞。
點(diǎn)晴PMS碼頭管理系統(tǒng)主要針對(duì)港口碼頭集裝箱與散貨日常運(yùn)作、調(diào)度、堆場(chǎng)、車(chē)隊(duì)、財(cái)務(wù)費(fèi)用、相關(guān)報(bào)表等業(yè)務(wù)管理,結(jié)合碼頭的業(yè)務(wù)特點(diǎn),圍繞調(diào)度、堆場(chǎng)作業(yè)而開(kāi)發(fā)的。集技術(shù)的先進(jìn)性、管理的有效性于一體,是物流碼頭及其他港口類企業(yè)的高效ERP管理信息系統(tǒng)。
點(diǎn)晴WMS倉(cāng)儲(chǔ)管理系統(tǒng)提供了貨物產(chǎn)品管理,銷(xiāo)售管理,采購(gòu)管理,倉(cāng)儲(chǔ)管理,倉(cāng)庫(kù)管理,保質(zhì)期管理,貨位管理,庫(kù)位管理,生產(chǎn)管理,WMS管理系統(tǒng),標(biāo)簽打印,條形碼,二維碼管理,批號(hào)管理軟件。
點(diǎn)晴免費(fèi)OA是一款軟件和通用服務(wù)都免費(fèi),不限功能、不限時(shí)間、不限用戶的免費(fèi)OA協(xié)同辦公管理系統(tǒng)。
Copyright 2010-2025 ClickSun All Rights Reserved