相机拍照_uniapp调用相机拍照 - CSDN
精华内容
参与话题
  • 看到代码,你不得不佩服这代码写得特别好,这是在网上找到的一个项目,非常感谢他,现在也已经整合成了Android Studio项目,方便大家的使用
  • h5调用相机拍照,并显示照片

    千次阅读 2019-07-18 17:43:48
    h5页面调用手机相机拍照,并将照片显示在手机或pc端; html代码块: <input type="file" capture="camcorder" accept="image/*" id="filetest" name="filetest"> <img src="" id="v_photoA" style=...

      h5页面调用手机相机拍照,并将照片显示在手机或pc端;

    html代码块:

    <input type="file" capture="camcorder" accept="image/*" id="filetest" name="filetest">

    <img src="" id="v_photoA" style="width:100%;"/>

    capture="camera"是为了兼容部分安卓机型。这里使用accept="image/*"而不使用accept="image/gif,image/jpeg,image/jpg,image/png,image/svg"是因为经测试华为部分机型在不使用”image/*”的时候无法调起摄像头,而是打开了文件管理器。

    js代码块:

    document.querySelector('#filetest').onchange = function () {
            alert(111);
            var fileTag = document.getElementById('filetest');
            console.log();
           var file = fileTag.files[0];

               var fileReader = new FileReader();

               fileReader.onloadend = function () {

                   if (fileReader.readyState == fileReader.DONE) {

                       document.getElementById('v_photoA').setAttribute('src', fileReader.result);

                   }

               };

               fileReader.readAsDataURL(file);
    };

    展开全文
  • 相机拍照

    2019-07-29 22:39:47
    通过UIImagePickerController来实现调用手机相机或则打开手机相册 (一)头文件 #import <UIKit/UIKit.h> @interface CameraViewController : UIViewController<UIImagePickerControllerDelegate, ...

    通过UIImagePickerController来实现调用手机相机或则打开手机相册

    (一)头文件

    #import <UIKit/UIKit.h>
    
    @interface CameraViewController : UIViewController<UIImagePickerControllerDelegate, UINavigationControllerDelegate>
    
    @end

    (二)初始化UIImagePickerController变量,并设置委托

    @interface CameraViewController ()
    {
        UIImagePickerController *imagePicker;
        UIImageView *imageView;
    }
    @end
    
    @implementation CameraViewController

    - (void)viewDidLoad {
        [super viewDidLoad];
        self.view.backgroundColor=[UIColor blackColor];
        
        imagePicker=[[UIImagePickerController alloc] init];
        imagePicker.modalPresentationStyle = UIModalPresentationOverCurrentContext;
        imagePicker.delegate=self;
        // Do any additional setup after loading the view.
    }

    @end

    (三)拍照

        imagePicker.allowsEditing = YES;
        if ([UIImagePickerController isSourceTypeAvailable:
             UIImagePickerControllerSourceTypeCamera])
        {
            imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
        }
        

    (四)相册选择照片

        imagePicker.allowsEditing = YES;
        imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

    (五)实现委托

    不管是新拍的照片还是在相册中选择照片,最终会在操作结束后通过委托形式传递到ui上

    -(void)imagePickerController:(UIImagePickerController *)picker
    didFinishPickingMediaWithInfo:(NSDictionary *)info
    {
        [self dismissViewControllerAnimated:YES completion:^{}];
        
        UIImage *image = [info objectForKey:UIImagePickerControllerEditedImage];
        if (image == nil) {
            image = [info objectForKey:UIImagePickerControllerOriginalImage];
            NSLog(@"Image null");
        }
        imageView.image = image;
        NSLog(@"Photo selected");
    }
    
    -(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker{
        [self dismissViewControllerAnimated:YES completion:^{}];
        NSLog(@"Photo dimiss");
    }

     

    //------------------------------------完整代码---------------------------------------------//

    #import "CameraViewController.h"
    
    @interface CameraViewController ()
    {
        UIImagePickerController *imagePicker;
        UIImageView *imageView;
    }
    @end
    
    @implementation CameraViewController
    
    - (void)viewDidLoad {
        [super viewDidLoad];
        self.view.backgroundColor=[UIColor blackColor];
        self.modalPresentationStyle=UIModalPresentationOverCurrentContext;
        
        imageView=[[UIImageView alloc] init];
        imageView.frame=CGRectMake(100, 50, 200, 300);
        UIImage *uiImage=[UIImage imageNamed:@"Example.png"];
        [imageView setImage:uiImage];
        [self.view addSubview:imageView];
        
        UIButton *pickBtn=[[UIButton alloc] initWithFrame:CGRectMake(90, 400, 100, 30)];
        pickBtn.backgroundColor=[UIColor redColor];
        [pickBtn setTitle:@"pick" forState:UIControlStateNormal];
        [pickBtn addTarget:self action:@selector(pickImage) forControlEvents:UIControlEventTouchDown];
        
        UIButton *takeBtn=[[UIButton alloc] initWithFrame:CGRectMake(210, 400, 100, 30)];
        takeBtn.backgroundColor=[UIColor redColor];
        [takeBtn setTitle:@"take" forState:UIControlStateNormal];
        [takeBtn addTarget:self action:@selector(takeImage) forControlEvents:UIControlEventTouchDown];
        
        [self.view addSubview:pickBtn];
        [self.view addSubview:takeBtn];
        
        imagePicker=[[UIImagePickerController alloc] init];
        imagePicker.modalPresentationStyle = UIModalPresentationOverCurrentContext;
        imagePicker.delegate=self;
        // Do any additional setup after loading the view.
    }
    
    - (void)didReceiveMemoryWarning {
        [super didReceiveMemoryWarning];
        // Dispose of any resources that can be recreated.
    }
    
    -(void) pickImage
    {
        NSLog(@"pick");
        imagePicker.allowsEditing = YES;
        imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
        
        [self presentViewController:imagePicker animated:YES completion:^{}];
    }
    
    -(void)takeImage
    {
        NSLog(@"take");
        imagePicker.allowsEditing = YES;
        if ([UIImagePickerController isSourceTypeAvailable:
             UIImagePickerControllerSourceTypeCamera])
        {
            imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
        }
        
        [self presentViewController:imagePicker animated:YES completion:^{}];
        
    }
    
    -(void)imagePickerController:(UIImagePickerController *)picker
    didFinishPickingMediaWithInfo:(NSDictionary *)info
    {
        [self dismissViewControllerAnimated:YES completion:^{}];
        
        UIImage *image = [info objectForKey:UIImagePickerControllerEditedImage];
        if (image == nil) {
            image = [info objectForKey:UIImagePickerControllerOriginalImage];
            NSLog(@"Image null");
        }
        imageView.image = image;
        NSLog(@"Photo selected");
    }
    
    -(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker{
        [self dismissViewControllerAnimated:YES completion:^{}];
        NSLog(@"Photo dimiss");
    }
    
    /*
    #pragma mark - Navigation
    
    // In a storyboard-based application, you will often want to do a little preparation before navigation
    - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
        // Get the new view controller using [segue destinationViewController].
        // Pass the selected object to the new view controller.
    }
    */
    
    @end

     

    转载于:https://www.cnblogs.com/llstart-new0201/p/9722183.html

    展开全文
  • android8.0中调用相机拍照

    千次阅读 2018-11-13 10:47:22
    网址:... 1.&lt;!--android8.0需要的配置,主要是调用相机--&gt;  &lt;provider    android:name="android.support.v4.content.FileProvider"    android:au...

    网址:https://blog.csdn.net/q992767879/article/details/79654733
      1.<!--android8.0需要的配置,主要是调用相机-->
      <provider
        
        android:name="android.support.v4.content.FileProvider"
        
        android:authorities="(你的包名).fileprovider"
        
        android:exported="false"
        
        android:grantUriPermissions="true">
        
        <meta-data
            
            android:name="android.support.FILE_PROVIDER_PATHS"
            
            android:resource="@xml/file_paths">
        </meta-data>
       
    </provider>
       2.在rec文件下创建xml文件夹,在里面创建xml文件


       <paths xmlns:android="http://schemas.android.com/apk/res/android">
        
          <external-path name="external_files" path="."/>
    </paths>
       3.使用
    private void useCamera() {
            
    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            
    file = new File(Environment.getExternalStorageDirectory().getAbsolutePath()
                    
    + "/test/" + System.currentTimeMillis() + ".jpg");
            
    file.getParentFile().mkdirs();

            
    //改变Uri  com.xykj.customview.fileprovider注意和xml中的一致
            
    Uri uri = FileProvider.getUriForFile(this, 
    "(你的包名).fileprovider", file);
            
    //添加权限
            
    intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);

            
    intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
            
    startActivityForResult(intent, REQUEST_CAMERA);
        }

    展开全文
  • Android--调用相机拍照(支持到8.0)

    千次阅读 2019-05-07 17:11:28
    import android.app.Activity; import android.content.ContentValues; import android.content.Intent; import android.net.Uri; import android.os.Bundle; import android.os.Environment;...import android.os.Pe.....
    import android.app.Activity;
    import android.content.ContentValues;
    import android.content.Intent;
    import android.net.Uri;
    import android.os.Bundle;
    import android.os.Environment;
    import android.os.PersistableBundle;
    import android.provider.MediaStore;
    import android.support.annotation.Nullable;
    
    import com.vm.shadowsocks.utils.MakeFile;
    
    import java.io.File;
    import java.text.SimpleDateFormat;
    import java.util.Date;
    
    /**
     * 拍照
     */
    
    public class photoActivity extends Activity {
        private static Uri imageUri;
        public static final int PHOTO_REQUEST_CAREMA = 1;// 拍照
        public static File tempFile;
    
        @Override
        public void onCreate(@Nullable Bundle savedInstanceState, @Nullable PersistableBundle persistentState) {
            super.onCreate(savedInstanceState, persistentState);
            
        }
        @Override
        protected void onActivityResult(int requestCode, int resultCode, Intent data) {
            switch (requestCode) {
                case PHOTO_REQUEST_CAREMA:
                    if (resultCode == RESULT_OK) {
                        Intent intent = new Intent("com.android.camera.action.CROP");
                        intent.setDataAndType(imageUri, "image/*");
                        intent.putExtra("scale", true);
                        intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
                    }
                    break;
            }
        }
        public static void openCamera(Activity activity) {
            //獲取系統版本
            int currentapiVersion = android.os.Build.VERSION.SDK_INT;
            // 激活相机
            Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            // 判断存储卡是否可以用,可用进行存储
            if (hasSdcard()) {
                SimpleDateFormat timeStampFormat = new SimpleDateFormat(
                        "yyyy_MM_dd_HH_mm_ss");
                String filename = timeStampFormat.format(new Date());
                MakeFile.makeRootDirectory(Environment.getExternalStorageDirectory().getPath()+ "/Android/photo");
                tempFile = new File(Environment.getExternalStorageDirectory().getPath()+ "/Android/photo",
                        filename + ".jpg");
                if (currentapiVersion < 24) {
                    // 从文件中创建uri
                    imageUri = Uri.fromFile(tempFile);
                    intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
                } else {
                    //兼容android7.0 使用共享文件的形式
                    ContentValues contentValues = new ContentValues(1);
                    contentValues.put(MediaStore.Images.Media.DATA, tempFile.getAbsolutePath());
    //                //检查是否有存储权限,以免崩溃
    //                if (ContextCompat.checkSelfPermission(photoActivity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE)
    //                        != PackageManager.PERMISSION_GRANTED) {
    //                    //申请WRITE_EXTERNAL_STORAGE权限
                        Toast.makeText(this,"请开启存储权限",Toast.LENGTH_SHORT).show();
    //                    return;
    //                }
                    imageUri = activity.getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, contentValues);
                    intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
                }
            }
            // 开启一个带有返回值的Activity,请求码为PHOTO_REQUEST_CAREMA
            activity.startActivityForResult(intent, PHOTO_REQUEST_CAREMA);
        }
    
        /*
    * 判断sdcard是否被挂载
    */
        public static boolean hasSdcard() {
            return Environment.getExternalStorageState().equals(
                    Environment.MEDIA_MOUNTED);
        }
    }

    调用方法:

    photoActivity.openCamera(this);

    记得添加读写权限和注册activity。

    封装一个调用类:

    private static void photo(){
            File outputImage = new File(Environment.getExternalStorageDirectory(), "/Water/Camera/Meter/"+
                    System.currentTimeMillis() + ".jpg");
            if (!outputImage.getParentFile().exists()){
                outputImage.getParentFile().mkdirs();
            }
            if (Build.VERSION.SDK_INT >= 24) {
                imageUri = FileProvider.getUriForFile(meterActivity.this, "com.example.water.fileprovider", outputImage);
            } else {
                imageUri = Uri.fromFile(outputImage);
            }
            Intent intent = new Intent();
            intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
            intent.setAction(MediaStore.ACTION_IMAGE_CAPTURE);
            intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
            startActivityForResult(intent, 1);
        }

    在AndroidManifest.xml的application标签下加入下面代码

    <provider
                android:name="android.support.v4.content.FileProvider"
                android:authorities="com.example.water.fileprovider" 包名+.fileprovider
                android:exported="false"
                android:grantUriPermissions="true">
                <meta-data
                    android:name="android.support.FILE_PROVIDER_PATHS"
                    android:resource="@xml/file_paths" />
            </provider>

    file_paths.xml

    <?xml version="1.0" encoding="utf-8"?>
    <paths xmlns:android="http://schemas.android.com/apk/res/android">
        <external-path name="external_files" path="."/>
    </paths>

     

    展开全文
  • iOS自定义相机拍照(仿微信),图片方向调整,图片裁剪
  • 在最开始接触Android相机功能之前,先来体验一下Android调用系统照相功能吧核心代码Intent intent = new Intent(); //调用照相机intent.setAction("android.media.action.STILL_IMAGE_CAMERA
  • html5网页调起相机拍照

    千次阅读 2018-03-01 18:18:15
    使用html5中 input的 capture属性,设定为camera,即可调起相机,页面显示跟上传文件一样,点击后调起camera。源码如下:&lt;html&gt; &lt;meta name="viewport" content="width=device-...
  • 手机的web页面调用相机拍照上传

    万次阅读 2015-07-29 03:58:43
    想在手机里的web页面里上传照片,又希望能调用摄像头拍完了再上传。 看这代码,重要的是capture="camera" accept="image/*"。 结束。
  • 在Fragment中调用系统相机拍照获取照片后,先跳到前一个activity或者桌面,然后再回到调用相机的Activity,这是啥原因呢?急急急·······在线等,求大神帮忙···
  • Android 调用系统相机怎样实现一键拍照、录像。而不是打开界面后还需要点击拍照以及确定。
  • 模拟器不能使用照相机功能

    千次阅读 2019-03-05 10:46:53
    看到这篇博文的各位,请死心吧,没用的。你们只能真机调试,看到这,绝望吗?^&amp;^
  • android 调用相机点击确定不返回

    千次阅读 2017-09-28 16:26:02
    android 调用相机点击确定不返回 出现问题的问题:相机照相成功后点击确定就是不放回,
  • Android调用系统相机拍照并保存到指定位置 @Click(R.id.btn_takePhoto) void onclick() { Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); File file = new File(imagePath, Utils.getCurrentDa
  • private static Intent getTakePhotoIntent(String fileName) { Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE, null); final String newPhotoPath = ContactPhotoUtils.pathForNewCameraPhoto(fileN
  • 比如 带一个人脸的框 不需要剪裁,只要拍的时候有这个框作为提示就好了
  • 相关链接:https://uniapp.dcloud.io/api/media/image?id=chooseimage
  • iOS 相机拍照声音消失方法

    千次阅读 2016-06-01 14:21:54
    iOS 相机拍照声音消失方法 通过在拍照的时候播放一个同拍照音频文件的一个反向音频,是两个音频的声波中和,从而达到无声具体如下:static SystemSoundID soundID = 0; if (soundID == 0) { NSString *path = [...
  • &lt;input type="file" accept="image/*" capture="camera" size="30"... 调用相机 图片或者相册     转发:https://blog.csdn.net/cai_ethan/articl
  • Android中如何后台开启照相机,就是点击拍照之后不显示预览界面,直接后台自动开启照相机进行拍照,并自动将照片保存!
1 2 3 4 5 ... 20
收藏数 62,169
精华内容 24,867
关键字:

相机拍照