【问题标题】:Save Multiple Image In Android在 Android 中保存多个图像
【发布时间】:2012-07-03 14:58:27
【问题描述】:

我有一个可以从 sd 卡加载图像的基本图像视图。用户可以通过单击按钮将templates(bitmap images) 添加到此图像视图中,并且可以根据用户需要定位添加的图像。我想将这些多张图像作为单个图像保存到 sd 卡。我该怎么做?

【问题讨论】:

    标签: android save-image


    【解决方案1】:

    您可以简单地获取 ImageView 的 DrawingCache,然后将其转换为 Bitmap,然后将其保存到 SDCARD。

    imageview.setDrawingCacheEnabled(true);
    Bitmap b = imageview.getDrawingCache();
    b.compress(CompressFormat.JPEG, 100, new FileOutputStream("/sdcard/image.jpg"));
    

    您可能必须在清单中设置 SDCARD 写入权限。

    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    

    【讨论】:

      【解决方案2】:

      看看这个片段:

      How to merge multiple images into one image - Java ImageIO

      int rows = 2;   //we assume the no. of rows and cols are known and each chunk has equal width and height  
              int cols = 2;  
              int chunks = rows * cols;  
      
              int chunkWidth, chunkHeight;  
              int type;  
              //fetching image files  
              File[] imgFiles = new File[chunks];  
              for (int i = 0; i < chunks; i++) {  
                  imgFiles[i] = new File("archi" + i + ".jpg");  
              }  
      
             //creating a bufferd image array from image files  
              BufferedImage[] buffImages = new BufferedImage[chunks];  
              for (int i = 0; i < chunks; i++) {  
                  buffImages[i] = ImageIO.read(imgFiles[i]);  
              }  
              type = buffImages[0].getType();  
              chunkWidth = buffImages[0].getWidth();  
              chunkHeight = buffImages[0].getHeight();  
      
              //Initializing the final image  
              BufferedImage finalImg = new BufferedImage(chunkWidth*cols, chunkHeight*rows, type);  
      
              int num = 0;  
              for (int i = 0; i < rows; i++) {  
                  for (int j = 0; j < cols; j++) {  
                      finalImg.createGraphics().drawImage(buffImages[num], chunkWidth * j, chunkHeight * i, null);  
                      num++;  
                  }  
              }  
              System.out.println("Image concatenated.....");  
              ImageIO.write(finalImg, "jpeg", new File("finalImg.jpg"));  
      

      【讨论】:

      • Android BufferedImage、ImageIO 中是否提供这些类?
      • 我没试过..只是一个线索..这是基于 java 的文件。
      • 是的,我正在检查 Jar 的可用性,如果可以,我们可以使用它吗?
      猜你喜欢
      • 2017-03-13
      • 2014-08-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多