如何在修改后保存图像

时间:2014-02-14 02:56:45

标签: java android

我可以将图片加载到背景然后我也能够“草绘”它但是当我尝试保存它以便我可以通过电子邮件将其作为附件发送时我只能想出要抓住原始图像和我在这里有什么使活动关闭

public void startCamera(View v) {
        Intent takePicture = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        seek.setVisibility(View.GONE);
        if (takePicture.resolveActivity(getPackageManager()) != null) {

            picSpot = new File(Environment.getExternalStorageDirectory(),
                    "sketch.png");

            outputFileUri = Uri.fromFile(picSpot);
            takePicture.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
            startActivityForResult(takePicture, REQUEST_IMAGE_CAPTURE);
        }
    }

    public void sendPic(View v) {
        Intent sharePic = new Intent(Intent.ACTION_SEND);
        if (didsketch == false) {

            sharePic.setType("image/png");
            sharePic.putExtra(Intent.EXTRA_STREAM, outputFileUri);
            sharePic.putExtra(Intent.EXTRA_SUBJECT, "Check This Out!");
            sharePic.putExtra(Intent.EXTRA_TEXT,
                    "I did this on my Sketchify App!");
            startActivity(Intent.createChooser(sharePic, "Send Email"));
        } else {
            try {
                FileOutputStream out = new FileOutputStream(finalSpot);
                back.compress(Bitmap.CompressFormat.PNG, 90, out);
                out.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
            outputFileUri = Uri.fromFile(finalSpot);
            sharePic.setType("image/png");
            sharePic.putExtra(Intent.EXTRA_STREAM, outputFileUri);
            sharePic.putExtra(Intent.EXTRA_SUBJECT, "Check This Out!");
            sharePic.putExtra(Intent.EXTRA_TEXT,
                    "I did this on my Sketchify App!");
            startActivity(Intent.createChooser(sharePic, "Send Email"));
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        sketchit.setEnabled(true);
        if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) {
            DisplayMetrics metrics = this.getResources().getDisplayMetrics();
            screenHeight = metrics.heightPixels;
            screenWidth = metrics.widthPixels;
            location = Environment.getExternalStorageDirectory()
                    + "/sketch.png";
            back = Camera_Helpers.processImage(location, screenHeight,
                    screenWidth);
            taken = true;
            sketchit.setEnabled(taken);
            shareit.setEnabled(taken);
            image.setImageBitmap(back);
        }
    }

back是我试图最终附加到电子邮件的修改后的位图 感谢!!!

1 个答案:

答案 0 :(得分:1)

创建文件夹目录并将图像保存到其中:创建要保存图像的目录。假设文件夹名称为 ImageFolder

String location = Environment.getExternalStorageDirectory() + "/ImageFolder/";

//Creating Folder Directory 
File imageDir = new File(location);
dir.mkdirs();

//Creating Image file
String imageName = "sketch.png";

File imageFile = new File(imageDir, imageName);

//If image file already exists then delete it.
if (imageFile.exists()) {
    imageFile.delete();
}

//Writing the image to SDCard
try {
    FileOutputStream out = new FileOutputStream(imageFile);
    back.compress(Bitmap.CompressFormat.JPEG, 100, out);
    out.flush();
    out.close();

} catch (Exception e) {
    e.printStackTrace();
}