安卓:不能够得到原始照片用相机拍摄(可读取COM preSS照片只) [英] Android: Not able to get original photo captured by camera (Able to read compress photo only)

查看:191
本文介绍了安卓:不能够得到原始照片用相机拍摄(可读取COM preSS照片只)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序拍摄的照片通过Android摄像头,然后我想将它发送到服务器。为此,我使用客户端Socket编程。我转换拍摄的相片变成字节组(字节[]),然后将其发送到服务器。每一件事情的工作perfactally。

In my application I capture photo by android camera and then I want to send it to the server. For this I use Client Socket programming. I convert the capture photo into bytearray(byte[]) and then send it to the server. Every thing work perfactally.

问题是存在的,我不能发送原始照片给服务器。缩略图照片是由android手机sended。但是,当我用相机拍摄的照片则原始照片是存在于库中。

Problem is there I am not able to send original photo to the server. Thumbnail photo is sended by the android mobile phone. But when I capture photo by the camera then original photo is there in Gallery.

如何获取原始照片在我的应用程序中使用?

How to get this original photo to use in my application?

我的code:

Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        cameraIntent.putExtra("outputFormat",Bitmap.CompressFormat.JPEG);
        cameraIntent.putExtra("return-data", true);
    startActivityForResult(Intent.createChooser(cameraIntent, "Select Picture"),
                    CAMERA_REQUEST);

而在onActivityResult方法:

And in onActivityResult method:

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == CAMERA_REQUEST) {
        Bitmap photo = (Bitmap) data.getExtras().get("data");
//          byte[] a = (byte[]) data.getExtras().getByteArray("data"); // I also use this but not work


        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        photo.compress(CompressFormat.JPEG, 100, bos);
        byte[] bitmapdata = bos.toByteArray();


    }
}

的BitmapData 照片是有,但COM pressed照片不是原来的。 有些人说,改变质量领域的 COM preSS(比较pressFormat.JPEG,100,BOS); 在0到100之间,但什么都不会发生。

in bitmapdata photo is there but compressed photo not the original. Some of people say that, change quality field of compress(CompressFormat.JPEG, 100, bos); in between 0 to 100 but nothing will happen.

- >> 有同样的任何其他方式获得原始照片是由摄像机拍摄的

-- >> is there any other way also to get original photo which is captured by the camera

- >> :当这张照片是在我的电脑中的文件夹,然后我通过给路径读取照片的文件中。 EX- 文件文件=新的文件(C:\ newphoto \ image.jpg文件); 。我可以用这个code在Android中读取原始照片,因为我知道这个名字和照片的位置。如果是的话那么什么是读取照片库的路径。这是工作,如果我给的路径为: \ DCIM \摄像头\ photoName.jpg

-- >> When The photo is in folder of my computer then I read this photo in the file by giving the path. ex- File file = new File(c:\newphoto\image.jpg); . can I use this code in android to read original photo because I know the name and location of photo. If yes then what is the path to read photo in gallery. Is this work if I give path as: \DCIM\Camera\photoName.jpg.

- >> 或一些变化需要在我目前的code,它会正常工作

-- >> Or some change need in my current code and it will work fine?

推荐答案

您正在使用的意图捕捉使用图像 ACTION_IM​​AGE_CAPTURE 。如果您在使用意向正常启动相机,然后它会返回形象在onActivityResult(位图),但是这将是缩略图的目的。

You are using the Intent to capture the image using ACTION_IMAGE_CAPTURE. If you normally starts your camera using Intent then it will return image as a bitmap in onActivityResult() but it will be for thumbnail purpose.

如果你想获得全分辨率图像从相机,那么你应该提供你所烧制启动相机活动的意图的文件。

If you want to get full resolution image from the camera then you should provide a file with the intent which you are firing to start the camera activity.

您可以像下面

Intent i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
File out = Environment.getExternalStorageDirectory();
out = new File(out, imagename);
i.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(out));
startActivityForResult(i, CAMERA_RESULT);

下面有一个 MediaStore.EXTRA_OUTPUT 参数,这需要在其中你希望你的相机写一个图像文件的URI。

Here there is a MediaStore.EXTRA_OUTPUT parameter which takes a Uri of the file in which you want your camera to write a images.

有关更多信息,你可以参考下面的例子

For more information you can refer below example

<一个href="http://stackoverflow.com/questions/10042695/how-to-get-camera-result-as-a-uri-in-data-folder">Capture从相机全分辨率图像

这篇关于安卓:不能够得到原始照片用相机拍摄(可读取COM preSS照片只)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆