Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/233.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/hadoop/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 是否有任何方式以编程方式将GIF图像保存在gallery中?_Android - Fatal编程技术网

Android 是否有任何方式以编程方式将GIF图像保存在gallery中?

Android 是否有任何方式以编程方式将GIF图像保存在gallery中?,android,Android,我是Android新手,正在实现图像库应用程序。我的问题是我想把GIF图像保存在gallery中。我已经在gallery中保存了图像,但当我在gallery中保存GIF图像时,它将显示普通图像而不是GIF图像。我正在使用glide库在imageview中显示GIF图像 这是我在画廊保存图片的代码 save.setOnClickListener(new View.OnClickListener() { @Override public void onClick(V

我是Android新手,正在实现图像库应用程序。我的问题是我想把GIF图像保存在gallery中。我已经在gallery中保存了图像,但当我在gallery中保存GIF图像时,它将显示普通图像而不是GIF图像。我正在使用glide库在imageview中显示GIF图像

这是我在画廊保存图片的代码

 save.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            drawable = getResources().getDrawable(imageRes);

            bitmap = ((BitmapDrawable)drawable).getBitmap();

            ImagePath = MediaStore.Images.Media.insertImage(
                    getContentResolver(),
                    bitmap,
                    "imageRes","imageRes"
            );

            URI = Uri.parse(ImagePath);

            Context context = getApplicationContext();

            // Create layout inflator object to inflate toast.xml file
            LayoutInflater inflater = getLayoutInflater();

            // Call toast.xml file for toast layout
            View toastRoot = inflater.inflate(R.layout.layout_toast3, null);

            Toast toast = new Toast(context);

            // Set layout to toast
            toast.setView(toastRoot);
            toast.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL,
                    0,0 );
            toast.setDuration(Toast.LENGTH_LONG);
            toast.show();
        }
    });
Imageadapter

public class ImageAdapter extends BaseAdapter {

static WallpaperInfo info;
private Context mContext;

public ImageAdapter() {


}

public int getCount() {
    return mThumbIds.length;
}
public Object getItem(int position) {
    return mThumbIds[position];
}
public long getItemId(int position) {
    return 0;
}
public ImageAdapter(Context c) {
    mContext = c;
}

public View getView(final int position, View convertView, ViewGroup parent) {
    ImageView imageView;
    if (convertView == null){
        imageView = new ImageView(mContext);
        imageView.setLayoutParams(new GridView.LayoutParams(200, 200));
        imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
        imageView.setPadding(3, 3, 3, 3);
        imageView.setMaxHeight(300);
        imageView.setMaxWidth(300);
        imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                MyPreferenceActivity myPref = new MyPreferenceActivity(mContext);
                myPref.setGifImage(position);


                Intent intent = new Intent(mContext, FullScreenImage.class);
                intent.putExtra("imageID", mThumbIds[position]);
                /*intent.putExtra(EXTRA_LIVE_WALLPAPER_INTENT, intent);
                intent.putExtra(EXTRA_LIVE_WALLPAPER_SETTINGS, info.getSettingsActivity());
                intent.putExtra(EXTRA_LIVE_WALLPAPER_PACKAGE, info.getPackageName());*/
                mContext.startActivity(intent);
            }
        });

        Animation anim = AnimationUtils.loadAnimation(mContext.getApplicationContext(), R.anim.fly);
        imageView.setAnimation(anim);
        anim.start();

    }
    else{
        imageView = (ImageView) convertView;
    }
    imageView.setImageResource(mThumbIds[position]);
    return imageView;
}
public Integer[] mThumbIds = {
        R.drawable.gpp1, R.drawable.gpp2,
        R.drawable.gpp3,R.drawable.gpp4,
        R.drawable.gpp5,R.drawable.gpp6,
        R.drawable.gpp7,R.mipmap.h8,
        R.mipmap.h9,R.mipmap.h10,
        R.mipmap.h11,R.drawable.gp3,
        R.drawable.gp2,R.drawable.gp,
        R.drawable.onehalloween
};
}
那么,我如何在我的应用程序中实现这类功能呢?

您可以使用以下方法生成图像:

public byte[] generateGIF() {
    ArrayList<Bitmap> bitmaps = adapter.getBitmapArray();
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    AnimatedGifEncoder encoder = new AnimatedGifEncoder();
    encoder.start(bos);
    for (Bitmap bitmap : bitmaps) {
        encoder.addFrame(bitmap);
    }
    encoder.finish();
    return bos.toByteArray();
}
您可以使用以下方法生成图像:

public byte[] generateGIF() {
    ArrayList<Bitmap> bitmaps = adapter.getBitmapArray();
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    AnimatedGifEncoder encoder = new AnimatedGifEncoder();
    encoder.start(bos);
    for (Bitmap bitmap : bitmaps) {
        encoder.addFrame(bitmap);
    }
    encoder.finish();
    return bos.toByteArray();
}

但是当我在存钱的时候。。。使用
MediaStore.Images.Media.insertImage(getContentResolver(),位图,“imageRes”,“imageRes”)您没有保存GIF@Selvin那么,我该怎么做呢?你检查过了吗?你在哪里使用glide??我看不到。但是当我保存GIF时。。。使用
MediaStore.Images.Media.insertImage(getContentResolver(),位图,“imageRes”,“imageRes”)您没有保存GIF@Selvin那么,我该怎么做呢?你检查过了吗?你在哪里使用glide??我看不到。看到我的imageadapter我能做什么?看到我的imageadapter我能做什么??