On Fri, Jan 9, 2009 at 11:55 AM, [email protected]
<[email protected]> wrote:
>
> Hi,
>
> I need to send a bitmap to a server. I've written some code, however,
> I got stuck on the part where I need to transform my bitmap into byte
> []. Here is my code:
>
> public void updateBitmap(Bitmap bm){
>                URL url = null;
>                HttpURLConnection conn = null;
>                try {
>                        url = new URL("http://www.myurl.com?";);
>                } catch (MalformedURLException e) {
>                        e.printStackTrace();
>                }
>                try {
>                        conn = (HttpURLConnection) url.openConnection
> ();
>                } catch (IOException e) {
>                        e.printStackTrace();
>                }
>                try {
>                        conn.setRequestMethod("POST");
>                } catch (ProtocolException e) {
>                        e.printStackTrace();
>                }
>                conn.setDoOutput(true);
>                conn.setDoInput(true);
>                conn.addRequestProperty("user_id", user.getUsername
> ());
>                conn.addRequestProperty("pass", user.getPassword());
>                conn.addRequestProperty("id", pinId);
>
>               OutputStream os = null;
>                try {
>                        os = conn.getOutputStream();
>                } catch (IOException e) {
>                        e.printStackTrace();
>                }
>
>                // Encode bitmap and flush the os

bm.compress(CompressFormat.PNG, 100, os);

Note that PNG is lossless and will ignore the 2nd argument.
Now, the API *could* have a helper method called save(CompressFormat,
Stream) passing the max quality as a default 2nd parameter but that's
another story...

Cheers,
Stoyan

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to