【问题标题】:Save custom imageview bitmap on buttonclik()在 buttonclik() 上保存自定义图像视图位图
【发布时间】:2015-01-26 14:52:05
【问题描述】:

我使用自定义形状创建了图像视图 siyamed/android-shape-imageview 现在我想用形状将图像保存在 SD 卡上。 我怎样才能做到这一点?

【问题讨论】:

    标签: android imageview save


    【解决方案1】:

    由于自定义视图只是一个 ImageView,因此请尝试在单击事件的按钮上添加类似的内容,以将图像保存为位图;

    ImageView imageViewCustom = (ImageView) findViewById(R.id.image_view_to_save);
    try {
       imageViewCustom.setDrawingCacheEnabled(true);
       FileOutputStream fos = new FileOutputStream(new File(Environment.getExternalStorageDirectory()+"/ACustomShapeFolder/file1234.jpg"));
       Bitmap bitmap = imageViewCustom.getDrawingCache();
       bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos);
       fos.flush();
       fos.close();
    } catch (FileNotFoundException e) {
       Toast.makeText(this, "Error occured", Toast.LENGTH_SHORT).show();
       e.printStackTrace();
    } catch (IOException e) {
       Toast.makeText(this, "Error occured", Toast.LENGTH_SHORT).show();
       e.printStackTrace();
    }
    

    希望这会有所帮助!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-08
      • 1970-01-01
      • 1970-01-01
      • 2011-05-11
      相关资源
      最近更新 更多