Ecco l'esercizio di conversione a stringa e riconversione a immagine:
public class MainActivity extends AppCompatActivity {
Bitmap bmp;
ImageView imageView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
imageView=(ImageView)findViewById(R.id.imageView);
bmp= BitmapFactory.decodeResource(getResources(),R.drawable.android);
ByteArrayOutputStream stream=new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.JPEG,80,stream);
byte[] b=stream.toByteArray();
String s= Base64.encodeToString(b,Base64.DEFAULT);
byte[]c=Base64.decode(s,Base64.DEFAULT);
bmp=BitmapFactory.decodeByteArray(c,0,c.length);
imageView.setImageBitmap(bmp);
}
}
Nessun commento:
Posta un commento