Android开发:用getDrawingCache方法获取ImageView中的图(5)

                             // ImageView对象(iv_photo)必须做如下设置后,才能获取其中的图像

                             iv_photo.setDrawingCacheEnabled(true);

                             // 获取ImageView中的图像

                             Bitmap sbmp =Bitmap.createBitmap(iv_photo.getDrawingCache());

                             // 从ImaggeView对象(iv_photo)中获取图像后,要记得调用setDrawingCacheEnabled(false)

                            // 清空画图缓冲区

                            iv_photo.setDrawingCacheEnabled(false);      

                            

                             // 将得到sbmp写入文件

                             FileOutputStream  m_fileOutPutStream = null;

                             String filepath = Environment.getExternalStorageDirectory() +File.separator + "tempPhoto1.png";

                             try

                             {

                                       m_fileOutPutStream= new FileOutputStream(filepath);

                             }

                             catch (FileNotFoundException e)

                             {

                                       e.printStackTrace();

                             }

           

                             sbmp.compress(CompressFormat.PNG, 100, m_fileOutPutStream);

           

                             try

                             {

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wwzfsz.html