Webservice的URL图像店到Android图库 [英] Webservice url images store in to android Gallery

查看:137
本文介绍了Webservice的URL图像店到Android图库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的ImageView在我的Andr​​oid应用程序在这里,我展示,所以我用UrlImageViewHelper从Web服务中的图像。我想这个图像存储到Android图库文件。

I am using ImageView in my android application here i show the images from webservice so i am using UrlImageViewHelper. i want to store this image into android Gallery files.

我的图像,例如:

    String Images = dataExtra.get("images").toString();
    System.out.println("image URL"+Images);     
    Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
    File f = new File(Images);
    Uri contentUri = Uri.fromFile(f);
    mediaScanIntent.setData(contentUri);
    this.sendBroadcast(mediaScanIntent);

我想这样的..但它不工作。任何一个可以帮助我如何存储这些图片到Android的画廊?

i tried like this.. but its not working. Any one can help me how to store these Images into Android Gallery?

推荐答案

我得到这个问题的解决方案,在这里,我的答案

i got solution for this problem, Here my answer

private void saveImagesIntoGallery(){
        BitmapDrawable drawable = (BitmapDrawable) imageView.getDrawable();
        Bitmap bitmap = drawable.getBitmap();
       // File sdCardDirectory = Environment.getExternalStorageDirectory();// its stores under sdcard not in a specific path
        String sdCardDirectory = Environment.getExternalStorageDirectory().toString()+"/Pictures/";
        String url = arrayForImages[i].toString();
        String file = url.substring(url.lastIndexOf('/')+1);
        System.out.println("PATH NAME"+sdCardDirectory);
        File image = new File(sdCardDirectory, file);
        boolean success = false;

        // Encode the file as a PNG image.
        FileOutputStream outStream;
        try {

            outStream = new FileOutputStream(image);
            bitmap.compress(Bitmap.CompressFormat.PNG, 100, outStream); 
            /* 100 to keep full quality of the image */
            outStream.flush();
            outStream.close();
            success = true;
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        if (success) {
            Toast.makeText(getApplicationContext(), "Image saved with success",
                    Toast.LENGTH_LONG).show();
        } else {
            Toast.makeText(getApplicationContext(),
                    "Error during image saving", Toast.LENGTH_LONG).show();
        }
    }

这篇关于Webservice的URL图像店到Android图库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆