本文介绍了从图像视图图像保存到SD卡:机器人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

testButton.setOnClickListener(new Button.OnClickListener(){

        @Override
        public void onClick(View v)
        {
                    imageView.setImageBitmap(Bitmap);
                    imageView.buildDrawingCache();
                    Bitmap bm =imageView.getDrawingCache();

               Intent imageIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
                File imagesFolder = new File(Environment.getExternalStorageDirectory(), "Punch");
                imagesFolder.mkdirs();
                String fileName = "image"  + ".jpg";
                File output = new File(imagesFolder, fileName);
                Uri uriSavedImage = Uri.fromFile(output);
                imageIntent.putExtra(MediaStore.EXTRA_OUTPUT, uriSavedImage);
                OutputStream fos = null;

                try {
                    fos = getContentResolver().openOutputStream(uriSavedImage);
                    bm.compress(CompressFormat.JPEG, 100, fos);
                    fos.flush();
                    fos.close();
                    }
                catch (FileNotFoundException e)
                    {
                    e.printStackTrace();
                    }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
                finally
                {}
        }
        });

首先,我检索从SD卡的图像(640×480)分辨率的图像视图。话又说回来,我从图像视图到SD卡上保存的图像。但保存的图像分辨率为(188x113)。任何人都可以建议我怎么可以用相同的分辨率保存。任何建议将AP preciable。

First i retrieved an image from sd card to image view of resolution (640 x 480). Then again i saved the image from image view to sd card. But the image saved is of resolution is (188x113). Can anyone suggest how i can save with the same resolution. Any suggestions will be appreciable.

推荐答案

试试这个code:

BitmapDrawable btmpDr = (BitmapDrawable) ivPic.getDrawable();
Bitmap bmp = btmpDr.getBitmap();

/*File sdCardDirectory = Environment.getExternalStorageDirectory();*/
try
{
    File sdCardDirectory = new File(Environment.getExternalStorageDirectory() + File.separator + "MeeguImages");
    sdCardDirectory.mkdirs();

    imageNameForSDCard = "image_" + String.valueOf(random.nextInt(1000)) + System.currentTimeMillis() + ".jpg";

    File image = new File(sdCardDirectory, imageNameForSDCard);
    FileOutputStream outStream;

    outStream = new FileOutputStream(image);
    bmp.compress(Bitmap.CompressFormat.JPEG, 100, outStream);
    /* 100 to keep full quality of the image */
    outStream.flush();
    outStream.close();



    //Refreshing SD card
    sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://"+ Environment.getExternalStorageDirectory())));
}
catch (Exception e)
{
    e.printStackTrace();
    Toast.makeText(ViewImage.this, "Image could not be saved : Please ensure you have SD card installed " +
                                                                            "properly", Toast.LENGTH_LONG).show();
}

这篇关于从图像视图图像保存到SD卡:机器人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 18:58