【问题标题】:How to convert captured image to GIF and save to sd card in android如何将捕获的图像转换为 GIF 并保存到 android 中的 sd 卡
【发布时间】:2014-03-28 10:13:05
【问题描述】:

我正在使用自定义相机,我想以连拍模式捕获 3 张图像并将其作为动画保存到 SD 卡。扩展名为 .gif 并在其中组合了 3 个捕获的帧。 还想将图像捕获时间保存在数据库中。

【问题讨论】:

    标签: android android-camera android-image android-camera-intent


    【解决方案1】:

    你可以使用 ImageMagick 吗?它是免费的并且可以使用here。它有一套命令行工具,还绑定了 Perl、Java、PHP、C++、Python、Ruby 等。

    如果是这样,只需将当前文件夹中的所有 jpeg 转换为动画 GIF:

    convert -delay 20 -loop 0  *.jpg  animated.gif
    

    ImageMagick 适用于 Android。

    【讨论】:

      【解决方案2】:

      用于数据库工作

            ImageHandling ih = null;
             ih = new ImageHandling(this);
            ih.getBitmapAsByteArray(R.drawable.imgename); 
            insertData(ih.getBitmapAsByteArray(R.drawable.imgename));
            private void insertData( byte[] bitmapData){
             values.put("imagename", bitmapData);
              }
      

      然后是最后

            public class ImageHandling {
      
      Resources res;
      Activity activity;
      public ImageHandling(Activity a) {
          activity = a;
          res = a.getResources();
      }
      private Bitmap getBitmapFromResource(int resourceId){
      
          Bitmap bitmap = null;
          bitmap = BitmapFactory.decodeResource(res, resourceId);
          return bitmap;
      }   
      
      public byte[] getBitmapAsByteArray(int resourceId){
          ByteArrayOutputStream outputStream = null;
          byte[] bitmapByteArray = null;
          try {
              outputStream = new ByteArrayOutputStream();
              Bitmap bitmap = getBitmapFromResource(resourceId);
              bitmap.compress(CompressFormat.PNG, 0, outputStream);
              bitmapByteArray =  outputStream.toByteArray();
          } catch (Exception e) {
              e.printStackTrace();
          }finally{
              if(outputStream != null){
                  try {
                      outputStream.flush();
                      outputStream.close();
                  } catch (IOException e) {
                      // TODO Auto-generated catch block
                      e.printStackTrace();
                  }
      
              }
          }
      
          return bitmapByteArray;
      }}
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-04-19
        相关资源
        最近更新 更多