Android开发:用getDrawingCache方法获取ImageView中的图像需要注意的问题(三)

2014-11-24 11:36:41 来源: 作者: 浏览: 5



// 将得到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


{


m_fileOutPutStream.flush();


m_fileOutPutStream.close();


}


catch (IOException e)


{


e.printStackTrace();


}



if(!compare2Image(obmp, sbmp))


{


Toast.makeText(this, "new picture", Toast.LENGTH_LONG).show();


}


else


{


Toast.makeText(this, "old picture", Toast.LENGTH_LONG).show();


}


}


break;


}


return false;


}




@Override


protected void onActivityResult(int requestCode, int resultCode, Intent data)


{


if((requestCode == 1) &&(resultCode ==RESULT_FIRST_USER + 2))


{


Bitmap ret_bitmap =data.getParcelableExtra("ret_bitmap");


iv_photo.setScaleType(ScaleType.FIT_XY);


iv_photo.setImageBitmap(ret_bitmap);


}


super.onActivityResult(requestCode,resultCode, data);


}



// 简单的比较两个图像是否一致


private boolean compare2Image(Bitmap bmp1,Bitmap bmp2)


{


int iteration = 0;


int width = bmp1.getWidth();


int height = bmp1.getHeight();


if(width != bmp2.getWidth()) return false;


if(height != bmp2.getHeight()) return false;



if(width < height)


{


iteration = width;


}


else


{


iteration = height;


}



for(int i = 0; i < iteration; ++i)


{


if(bmp1.getPixel(i, i) != bmp2.getPixel(i,i)) return false;


}


return true;


}


}


-->

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: