```public class MainActivity extends Activity {
private ImageView iv1,iv2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initview();
//获取iv1的图片并将图片转成byte
Bitmap bitmap = ((BitmapDrawable)iv1.getDrawable()).getBitmap();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos);
byte[] byteArray = baos.toByteArray();
String sendString;
try {
//将byte转为String
sendString = new String(byteArray , "UTF-8" );
try {
//将String转回byte
byte[] data = sendString.getBytes("UTF-8");
// 为UTF8编吗
// 把二进制图片转成位图
YuvImage yuvimage = new YuvImage(data, ImageFormat.NV21, 100,
100, null); // 20、20分别是图的宽度与高度
ByteArrayOutputStream baos2 = new ByteArrayOutputStream();
// 80--JPG图片的质量[0-100],100最高
yuvimage.compressToJpeg(new Rect(0, 0, 20, 20), 80, baos2);
byte[] jdata = baos2.toByteArray();
Bitmap bitmap2 = BitmapFactory.decodeByteArray(jdata, 0,
jdata.length);
iv2.setImageBitmap(bitmap2);
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (UnsupportedEncodingException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
private void initview() {
// TODO Auto-generated method stub
iv1=(ImageView) findViewById(R.id.imageView1);
iv2=(ImageView) findViewById(R.id.imageView2);
}
}
转换完成之后图片不一样,这是怎么回事,求大神解惑