2

I am creating android web application using RESTFul web services.i have declared code to save Image like this

onCreateMethod()

    ImageView iv = (ImageView) findViewById(R.id.hotelLogoImageView);
    iv.setDrawingCacheEnabled(true);

onSave()

    Bitmap b = ((BitmapDrawable) iv.getDrawable()).getBitmap();
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    b.compress(Bitmap.CompressFormat.PNG, 100, bos);
    logo = bos.toByteArray();

then i am using RESTFul webservices.so i converted logo(byte Array) to String and passed logo into NameValuePair like:

private ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("hotel_logo",String.valueOf(logo)));

In my server side code, again i converted my String value to byteArray like:

byte[] imgLogo = hotelParams.getFirst("hotel_logo").getBytes(
            Charset.forName("UTF-8"));

Finally i saved imgLogo value in my phpMyAdmin Database.it's also Stored in Database like [BLOB - 10 B]

Now I have to set that image into ImageView.so I have used this method.like

    JSONObject jsonObject = new JSONObject(response);
    byte[] logo = Base64.decode(jsonObject.getString("hotel_logo"),
            Base64.DEFAULT);
    Bitmap hotel_Logo = BitmapFactory.decodeByteArray(logo, 0, logo.length);
    hotelLogo.setImageBitmap(hotel_Logo);

After finish this code.there is no error.But Image Doesn't Show in ImageView.please Help me what i have done mistake?

user3543997
  • 121
  • 1
  • 1
  • 7
  • `String.valueOf(byteArray) == [B@xxxxxxx` not Base64 ... and -1 for asking the same question(yes, with more information, but you could edit the prev one) – Selvin Apr 24 '14 at 22:37
  • @selvin: i didn't get you.what are you telling? – user3543997 Apr 24 '14 at 22:39
  • just take a look at DB on server side .... your "[BLOB - 10 B]" is nothing but "[B@xxxxxxx" which is not Base64 data – Selvin Apr 24 '14 at 22:42
  • @Selvin: when i store image,that ll be stored like [Blob-10 B].is it having value?or what? – user3543997 Apr 24 '14 at 22:46
  • @selvin: i am new to webservice and android.so only i dnot have idea on handling image.cant you help me? – user3543997 Apr 24 '14 at 22:54
  • 1
    Have you tried just putting the images in res/drawable to make sure your image display code is working? I would work through it that way one step at a time. 1. images in res/drawable 2. base64 string saved in a raw file or assets or whatever, and decoded into an image 3. hard code base64 string in webservice 4. pull base64 from database – nasch Apr 25 '14 at 01:13
  • why you are converting logo to string, you can send it directly as a stream, please search in google how you can do that!! look for an example where image as a stream sends to server – Jitesh Upadhyay Apr 25 '14 at 10:27
  • also look what nasch has said in the previous comment, it will help you!! – Jitesh Upadhyay Apr 25 '14 at 10:30
  • @JiteshUpadhyay: i am using RestFull webservices.so i need to pass my values as String into List.so only i converted my Byte to string – user3543997 Apr 25 '14 at 10:30
  • it is ok i understand than do all what nasch has said before, try with that!! and also look in google that how you can send image to server with restfull web services – Jitesh Upadhyay Apr 25 '14 at 10:32
  • @JiteshUpadhyay: no friend i am directly store my image into db.and access from that.so i think that will not be usefull for me – user3543997 Apr 25 '14 at 10:32
  • please look at http://stackoverflow.com/questions/8726400/how-can-i-add-an-image-file-into-json-object...it may help you!! – Jitesh Upadhyay Apr 25 '14 at 10:34
  • @JiteshUpadhyay :thank you friend.can i have contact with you? – user3543997 Apr 25 '14 at 10:41
  • sure my mail id is given at my stackoverflow profile, however presently at office so not ol – Jitesh Upadhyay Apr 25 '14 at 10:42

0 Answers0