Results 1 to 10 of 10
  1. #1
    raj.mscking@gmail.com's Avatar
    raj.mscking@gmail.com is offline Senior Member
    Join Date
    Jan 2012
    Location
    TamilNadu
    Posts
    274
    Rep Power
    3

    Default Problem display image from base64

    Hi

    I am trying to save & retrieve image from server using php json..,

    But the retrieve result is showing only blank black image..,

    i can store the image by

    Java Code:
    ByteArrayOutputStream bao = new ByteArrayOutputStream();
    		Bitmap bit_map = Bitmap.createBitmap(ae_imv_img.getWidth(),
    				ae_imv_img.getHeight(), Bitmap.Config.ARGB_8888);
    		bit_map.compress(Bitmap.CompressFormat.JPEG, 75, bao);
    
    		byte[] byt_ara = bao.toByteArray();
    		String encoded_btmp = Base64.encodeToString(byt_ara, Base64.DEFAULT);
    the input is
    Java Code:
    "/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wAARCACFAIUDASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSExBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU1dbX2Nna4uPk5ebn6Onq8vP09fb3+Pn6/9oADAMBAAIRAxEAPwD5/ooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigD//Z";
    when retrieving image i can get the same output as json


    Java Code:
    "/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wAARCACFAIUDASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSExBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU1dbX2Nna4uPk5ebn6Onq8vP09fb3+Pn6/9oADAMBAAIRAxEAPwD5/ooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigD//Z"
    But if i try to convert as Base64 and put into image view as a bit map

    Java Code:
    byte[] decodedString = Base64.decode(json_my_img, Base64.DEFAULT);
    			Bitmap decodedByte = BitmapFactory.decodeByteArray(decodedString,
    					0, decodedString.length);
    			imv_emp_imv.setImageBitmap(decodedByte);
    it display blank black image only


    Can anyone guide me please..,

    Thank You!

    Have A happy Day..,
    Last edited by raj.mscking@gmail.com; 12-07-2013 at 08:40 AM.
    - Raj

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,846
    Rep Power
    19

    Default Re: Problem display image from base64

    Where are you drawing anything to the Bitmap?
    You just seem to create it, compress it, then store it.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    raj.mscking@gmail.com's Avatar
    raj.mscking@gmail.com is offline Senior Member
    Join Date
    Jan 2012
    Location
    TamilNadu
    Posts
    274
    Rep Power
    3

    Default Re: Problem display image from base64

    Thanks for your response Mr.Tolls!

    I am receiving image as base64 formate by json response as
    json_my_img
    and using it into the fallowing code,

    Java Code:
    byte[] decodedString = Base64.decode(json_my_img, Base64.DEFAULT);
                Bitmap decodedByte = BitmapFactory.decodeByteArray(decodedString,
                        0, decodedString.length);
                imv_emp_imv.setImageBitmap(decodedByte);
    imv_emp_imv
    is my imageview..,

    what i have to correct in my code Mr.Tolls..,

    Guide me please..,
    - Raj

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,846
    Rep Power
    19

    Default Re: Problem display image from base64

    No, this bit:
    Java Code:
    ByteArrayOutputStream bao = new ByteArrayOutputStream();
    		Bitmap bit_map = Bitmap.createBitmap(ae_imv_img.getWidth(),
    				ae_imv_img.getHeight(), Bitmap.Config.ARGB_8888);
    		bit_map.compress(Bitmap.CompressFormat.JPEG, 75, bao);
    
    		byte[] byt_ara = bao.toByteArray();
    		String encoded_btmp = Base64.encodeToString(byt_ara, Base64.DEFAULT);
    All you do is create a blank image and encode it.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  5. #5
    raj.mscking@gmail.com's Avatar
    raj.mscking@gmail.com is offline Senior Member
    Join Date
    Jan 2012
    Location
    TamilNadu
    Posts
    274
    Rep Power
    3

    Default Re: Problem display image from base64

    But i have set the image before encode it like..,


    Java Code:
    @Override
    	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    		// TODO Auto-generated method stub
    		super.onActivityResult(requestCode, resultCode, data);
    		switch (requestCode) {
    		case SELECT_IMAGE:
    			if (resultCode == RESULT_OK) {
    				Uri select_image = data.getData();
    				try {
    					InputStream i_strm = getContentResolver().openInputStream(
    							select_image);
    					Bitmap my_bitmap = BitmapFactory.decodeStream(i_strm);
    					ae_imv_img.setImageBitmap(my_bitmap);
    				} catch (FileNotFoundException e) {
    					// TODO Auto-generated catch block
    					e.printStackTrace();
    				}
    			}
    			break;
    		}
    	}
    the image also display on the imageview.., after that only i try to encode it Mr.Tolls..,

    what i have to correct in that.., Guide me please..,
    Last edited by raj.mscking@gmail.com; 12-09-2013 at 12:59 PM.
    - Raj

  6. #6
    raj.mscking@gmail.com's Avatar
    raj.mscking@gmail.com is offline Senior Member
    Join Date
    Jan 2012
    Location
    TamilNadu
    Posts
    274
    Rep Power
    3

    Default Re: Problem display image from base64

    is i have to do any correction Mr.Tolls?..,
    - Raj

  7. #7
    raj.mscking@gmail.com's Avatar
    raj.mscking@gmail.com is offline Senior Member
    Join Date
    Jan 2012
    Location
    TamilNadu
    Posts
    274
    Rep Power
    3

    Default Re: Problem display image from base64

    i am looking for your guide Mr.tolls
    Quote Originally Posted by Tolls View Post
    No, this bit:
    Java Code:
    ByteArrayOutputStream bao = new ByteArrayOutputStream();
    		Bitmap bit_map = Bitmap.createBitmap(ae_imv_img.getWidth(),
    				ae_imv_img.getHeight(), Bitmap.Config.ARGB_8888);
    		bit_map.compress(Bitmap.CompressFormat.JPEG, 75, bao);
    
    		byte[] byt_ara = bao.toByteArray();
    		String encoded_btmp = Base64.encodeToString(byt_ara, Base64.DEFAULT);
    All you do is create a blank image and encode it.
    - Raj

  8. #8
    gimbal2 is online now Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,742
    Rep Power
    5

    Default Re: Problem display image from base64

    Repeatedly posting that won't get you an answer quicker. Tolls is doing his job you know, wait until he has a moment free to respond to you. Be patient and do more investigation into your problem on your own while you're waiting.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  9. #9
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,846
    Rep Power
    19

    Default Re: Problem display image from base64

    Java Code:
    		Bitmap bit_map = Bitmap.createBitmap(ae_imv_img.getWidth(),
    				ae_imv_img.getHeight(), Bitmap.Config.ARGB_8888);
    The above line is only creating a blank (black) Bitmap.
    It is using the height and width from the ae_imv_img image, but not the image itself.
    And before you ask, no, I don't know how you paint onto a Bitmap. You need to look that part up.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  10. #10
    raj.mscking@gmail.com's Avatar
    raj.mscking@gmail.com is offline Senior Member
    Join Date
    Jan 2012
    Location
    TamilNadu
    Posts
    274
    Rep Power
    3

    Default Re: Problem display image from base64

    Thank You for your response sir..,

    i will concentrate on that part sir..,

    Thank You!

    Have A Happy Day Sir..,
    - Raj

Similar Threads

  1. Problem display image fro base64
    By raj.mscking@gmail.com in forum Android
    Replies: 0
    Last Post: 12-07-2013, 07:58 AM
  2. Problem display image fro base64
    By raj.mscking@gmail.com in forum Android
    Replies: 0
    Last Post: 12-07-2013, 07:56 AM
  3. Replies: 3
    Last Post: 06-04-2011, 08:44 PM
  4. Decode base64 string to an image(pdf, png, ....)
    By RohitBBorse in forum New To Java
    Replies: 0
    Last Post: 05-25-2011, 01:07 PM
  5. Encode Image into Base64 value.
    By onlyabhinav in forum New To Java
    Replies: 3
    Last Post: 01-25-2011, 07:44 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •