JavascriptProva

mercoledì 8 febbraio 2017

Conversione di immagine bitmap in stringa.

Salviamo immagini in un database.
Ho appreso, e usato, il modo di salvare un'immagine sotto forma di stringa.
Vado a ripassarlo.
L'ho trovato

Ci provo. Converto l'immagine "bonazza" che ho già usato per porla in una ImageView.
public class MainActivity extends AppCompatActivity {

    TextView textView;
    ImageView imageView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        textView=(TextView)findViewById(R.id.textView);
        Bitmap bmp;
        bmp= BitmapFactory.decodeResource(getResources(),R.drawable.bonazza);


        ByteArrayOutputStream stream=new ByteArrayOutputStream();
        bmp.compress(Bitmap.CompressFormat.JPEG,100,stream);
        byte[] b=stream.toByteArray();
        String s= Base64.encodeToString(b,Base64.DEFAULT);
        System.out.println(s);

    }
}
Ed ecco:
02-08 18:27:58.807 4224-4224/? I/System.out: 5nX684z+PBzknqy/EZ3WdpYiPRWtDXVP+bs4rfZvW92cvtJa6vpbytvstb2Vu3m1r+Y2tfAu4hea
02-08 18:27:58.807 4224-4224/? I/System.out: eKGZYz/qikjgZy4bIVh0wvB6Eng7iTw8vw18VaW6PZXF4uHXCFyV4Ldix4PTr688nH6Z6n4fjj86
02-08 18:27:58.807 4224-4224/? I/System.out: 2LqyxkFeDjJMueoz1TPXuevNclN4atS8ZYRttkTOVJzy3qvHB/l1wc9086qYPETweKjGpWpqHPJp
02-08 18:27:58.807 4224-4224/? I/System.out: te+lNNWb2i4pavbo1d3GvVjflnaK6a23stnr53vp2Pz1mtfifog8zyFe3wDud3ViBu5wpAzgAn0z
02-08 18:27:58.807 4224-4224/? I/System.out: 3JotfHXimxdm1K0ugmxX3QhmUqCw3cnp3+pPOOv6BTeALXUwTJMojwQIypIwGYf3eOo6eg6daxJv
02-08 18:27:58.807 4224-4224/? I/System.out: hJpAnu4pVtpIv7N3xoYeV4kI5KdvqeO+ea76WOy7EwcsVQ5oLlaspfE21e1m1p083re7c1MbVoJP
02-08 18:27:58.807 4224-4224/? I/System.out: nbUmo6X7J317JJr5a3WvyPpPxdsHjhllluFbLIyyxdCpx2/U5P1Jro9P+KGjyyXDy3qpgEoGwAck
02-08 18:27:58.807 4224-4224/? I/System.out: gE55A6nuenUDiXT/AIW6KYNQMyxuHvHjh2pgx4aUH+EdRg9zwoyAM1zfiH4GaWLZruC+eIEFigaU
02-08 18:27:58.807 4224-4224/? I/System.out: Z5JA4Xpz0z685Oa2h/YVV+zp4dqdRqEXadlOT5U9Y9G427d3Z37MLmlZLnT5lFR3T15Wm9br+b08
02-08 18:27:58.807 4224-4224/? I/System.out: 3ZN9VJ42t7lTJFdRyxEcGNlZv4sHBPBPfr2yM4Nc5d+JrTLOjM5Y7iGIDdWxnDDqOvp6nO4+S3/w
...un frammento della stringa in cui è stata ridotta l'immagine.

Nessun commento:

Posta un commento