小尺寸图片问题 [英] small size picture problem

查看:219
本文介绍了小尺寸图片问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用ACTION_IMAGE_CAPTURE捕获图片后,如果图片变得非常小,它的分辨率是27X44我使用1.5 Android模拟器,这是代码,我会欣赏任何help:

  myImageButton02.setOnClickListener 

new OnClickListener()
{
@Override
public void onClick(View v)
{
//创建摄像机意图
意图intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
// Grant
intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
//保存如果有EXTRA_OUTPUT
intent.putExtra(MediaStore.EXTRA_OUTPUT,Uri.fromFile() new File
(Environment.getExternalStorageDirectory(),testExtra+ String.valueOf
(System.currentTimeMillis())+.jpg));
//启动相机意图并返回图像
startActivityForResult(intent,1);
}
}
);
@Override
protected void onActivityResult(int requestCode,int resultCode,Intent data)
{
super.onActivityResult(requestCode,resultCode,data);

//如果Activity被取消,显示一个Toast消息
if(resultCode == RESULT_CANCELED)
{
Toast toast = Toast.makeText已取消,10000);
toast.show();
return;
}

//检查我们是否真的处理图片
if(requestCode == 1&& resultCode == RESULT_OK)
{
String timestamp = Long.toString(System.currentTimeMillis());
//获取图片
Bitmap mPicture =(Bitmap)data.getExtras()。get(data);
//将图像保存到图库
MediaStore.Images.Media.insertImage(getContentResolver(),mPicture,timestamp,timestamp);
}
}
}


解决方案>

看看你在做什么:




  • 你指定一个你刚刚拍摄的图片存储的路径 intent.putExtra(MediaStore.EXTRA_OUTPUT,Uri.fromFile(new File(Environment.getExternalStorageDirectory(),testExtra+ String.valueOf(System.currentTimeMillis())+.jpg))); c>

  • 当你访问图片你拖动数据的意图与 Bitmap mPicture =(Bitmap)data.getExtras data);



显然,您不能从其文件访问图片。据我所知,意图不是设计来承载大量的数据,因为它们在例如活动。你应该做的是打开从相机意图创建的文件的图片。看起来像:

  BitmapFactory.Options bitmapOptions = new BitmapFactory.Options 
//限制文件大小,因为5MP图片会杀死你的RAM
bitmapOptions.inSampleSize = 6;
imgBitmap = BitmapFactory.decodeFile(pathToPicture,bitmapOptions);

它曾经以这种方式为我工作,但我遇到的问题,因为2.1在几个设备上。在Nexus One上运作(静态)。

查看 MediaStore.ACTION_IMAGE_CAPTURE



希望这有助于。

谨慎,

Steff


I've got a problem in saving a picture in a full size after capturing it using ACTION_IMAGE_CAPTURE intent the picture become very small , its resolution is 27X44 I'm using 1.5 android emulator, this is the code and I will appreciate any help:

myImageButton02.setOnClickListener
(
    new OnClickListener() 
    {
        @Override
        public void onClick(View v)
        {
            // create camera intent
            Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            //Grant permission to the camera activity to write the photo.
            intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
            //saving if there is EXTRA_OUTPUT
            intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File
            (Environment.getExternalStorageDirectory(), "testExtra" + String.valueOf
            (System.currentTimeMillis()) + ".jpg")));
            // start the camera intent and return the image
            startActivityForResult(intent,1); 
        } 
    }
);
@Override
protected void onActivityResult (int requestCode, int resultCode, Intent data)
{
    super.onActivityResult(requestCode, resultCode, data);

    // if Activity was canceled, display a Toast message
    if (resultCode == RESULT_CANCELED) 
    {
        Toast toast = Toast.makeText(this,"camera cancelled", 10000);
        toast.show();
        return;
    }

    // lets check if we are really dealing with a picture
    if (requestCode == 1 && resultCode == RESULT_OK)
    {
        String timestamp = Long.toString(System.currentTimeMillis());
        // get the picture
        Bitmap mPicture = (Bitmap) data.getExtras().get("data");
        // save image to gallery
        MediaStore.Images.Media.insertImage(getContentResolver(), mPicture, timestamp, timestamp);
    }
}
}

解决方案

Look at what you are doing:

  • you specify a path where your just taken picture is stored with intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File (Environment.getExternalStorageDirectory(), "testExtra" + String.valueOf (System.currentTimeMillis()) + ".jpg")));
  • when you access the picture you 'drag' the data out of the intent with Bitmap mPicture = (Bitmap) data.getExtras().get("data");

Obviously, you don't access the picture from its file. As far as I know Intents are not designed to carry a large amount of data since they are passed between e.g. Activities. What you should do is open the picture from the file created by the camera intent. Looks like that:

BitmapFactory.Options bitmapOptions = new BitmapFactory.Options();  
// Limit the filesize since 5MP pictures will kill you RAM  
bitmapOptions.inSampleSize = 6;  
imgBitmap = BitmapFactory.decodeFile(pathToPicture, bitmapOptions);

That should do the trick. It used to work for me this way but I am experiencing problems since 2.1 on several devices. Works (still) fine on Nexus One.
Take a look at MediaStore.ACTION_IMAGE_CAPTURE.

Hope this helps.
Regards,
Steff

这篇关于小尺寸图片问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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