Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/193.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 保存jpeg以后查看_Android - Fatal编程技术网

Android 保存jpeg以后查看

Android 保存jpeg以后查看,android,Android,我正在开发一个应用程序,将绘制的画布作为jpeg图像存储在SD卡中。 问题是,当我试图查看保存的图像时,它加载的时间比其他图像长,我希望保存的图像在正常时间可以像其他图像一样查看 我保存图像的代码是: View content = drawView; content.setDrawingCacheEnabled(true); content.setDrawingCacheQuality(View.DRAWING_CACHE_

我正在开发一个应用程序,将绘制的画布作为jpeg图像存储在SD卡中。 问题是,当我试图查看保存的图像时,它加载的时间比其他图像长,我希望保存的图像在正常时间可以像其他图像一样查看 我保存图像的代码是:

            View content = drawView;
            content.setDrawingCacheEnabled(true);
            content.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_LOW);
            Bitmap bitmap = content.getDrawingCache();

            String path = Environment.getExternalStorageDirectory().getAbsolutePath();
            String file_name="Imatge"+System.currentTimeMillis()+".jpg";
            File file = new File(path,file_name);
            FileOutputStream ostream;
            try {                   
                ostream = new FileOutputStream(file);
                bitmap.compress(CompressFormat.PNG,50, ostream);
                ostream.flush();
                ostream.close();
                Toast.makeText(getApplicationContext(), " :) Image saved in "+ path+"/"+file_name, 5000).show();
            } catch (Exception e) {
                e.printStackTrace();
                Toast.makeText(getApplicationContext(), e.toString()+"error", 5000).show();
            }
                }

提前谢谢,请帮帮我

您的代码将图像保存为PNG文件(即使您为其指定了文件扩展名.jpg)。PNG文件是无损的,因此比JPEG文件大得多

要修复它,请将其另存为JPEG:

ostream = new FileOutputStream(file);
bitmap.compress(CompressFormat.JPEG, 50, ostream);
使用如下所示

        String extStorageDirectory = Environment.getExternalStorageDirectory().toString();
                     FileOutputStream out = null;
                     Log.e("h",""+mview.getMeasuredHeight()+" "+mview.getMeasuredWidth());
                    try {
                         out = new FileOutputStream(new File(extStorageDirectory + "/myAwesomeDrawing.jpg"));
                         mBitmap.compress(Bitmap.CompressFormat.JPEG, 90, out); 
                         out.flush(); 
                         out.close();
                    } catch (Exception e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }  
其中,mBitmap是您在urDrawview类中使用的global变量,因此使用该变量,您必须跳过此行,并在此行中添加注释

  /*View content = drawView;
     content.setDrawingCacheEnabled(true);
        content.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_LOW);
        Bitmap bitmap = content.getDrawingCache();
*/

但愿它能工作

我自己找到了解决方案,解决方案是通过媒体存储来存储图像。这里是我的代码,它工作正常

View content = drawView;
                content.setDrawingCacheEnabled(true);
                content.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_AUTO);
                Bitmap bitmap;
                bitmap = content.getDrawingCache();             
                String file_name="MyImage"+System.currentTimeMillis()+".jpg";

                ContentValues values = new ContentValues();
                values.put(Images.Media.TITLE,"MyImage");                   
                values.put(Images.Media.DESCRIPTION,"Advanced Practice");                   
                values.put(Images.Media.MIME_TYPE, "image/jpeg");
                Uri url = null;

                try 
                {   
                    url = getContentResolver().insert(MediaStore.Images.Thumbnails.getContentUri("external"), values);
                    MediaStore.Images.Media.insertImage(getContentResolver(), bitmap,"MyImage","Advanced Practice");                     
                    Toast.makeText(getApplicationContext(), " :) Image saved in /sdcard/DCIM/Camera/"+file_name, 5000).show();
                } 
                catch (Exception e) 
                {
                    e.printStackTrace();
                    Toast.makeText(getApplicationContext(), e.toString()+"error", 5000).show();
                }

你说它比其他图像加载时间长是什么意思?android mobile拍摄的fotos在正常时间在gallery中查看,但我的应用程序创建的图像在gallery中查看花费了很多时间不知道你为什么要检查图像的文件大小?可能它太大而无法加载抱歉无法正常工作在sd中查看保存的图像也需要很长时间card@ThiruVT你能给我们一些数字吗。保存的图像有多大,其他图像有多大(SD上的KB/MB以及宽度和高度)?您的图像加载需要多长时间?其他图像加载需要多长时间?图像大小不大,即使大小为5 kb,但此图像加载正常图像需要15秒到20秒,仅需2到3秒图像的尺寸(宽度和高度)是多少?你说的“负载”到底是什么意思?你使用查看器吗?你是直接在手机上加载还是从电脑上加载?您是否使用自己的代码来加载它?(注意:你的键盘坏了吗?你的问题和评论没有标点符号,很难阅读。)load是查看图像所花费的时间,我正在设备中查看图像,我没有在代码中为图像添加任何维度:(