converting base64 to image is not working properly











up vote
0
down vote

favorite
1












I am converting base64 to image but when I set it to imageView it shows nothing.



I have tried almost every solution available on stackoverflow but same result. This is how I am trying to do it right now



var iconBase64String = "myBASE64StringWhichIsGivenBelow"
// remove 'data:image/svg+xml;base64,' from start of string
iconBase64String = iconBase64String.substring(iconBase64String.indexOf(",") + 1)
val image = findViewById<ImageView>(R.id.imageView)

val imageAsBytes = Base64.decode(iconBase64String.toByteArray(), Base64.DEFAULT)
val decodedString = Base64.decode(iconBase64String, Base64.DEFAULT)
val bitmap = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.size)
image.setImageBitmap(bitmap)


I have also tried with glide



var iconBase64String = "myBASE64StringWhichIsGivenBelow"
// remove 'data:image/svg+xml;base64,' from start of string
iconBase64String = iconBase64String.substring(iconBase64String.indexOf(",") + 1)
val image = findViewById<ImageView>(R.id.imageView)

val imageAsBytes = Base64.decode(iconBase64String.toByteArray(), Base64.DEFAULT)
Glide.with(this)
.asBitmap()
.load(imageAsBytes)
.into(image)


here is base64 which i am trying to convert:




data:image/svg+xml;base64,PHN2ZyBoZWlnaHQ9IjU0IiB2aWV3Qm94PSIwIDAgNDIuMTE3ODQgNDIuMTI5NDQ2IiB3aWR0aD0iNTQiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiPjxjbGlwUGF0aCBpZD0iYSI+PHBhdGggZD0ibTcyMC42IDMwNi40aDUwOC43djI2NmgtNTA4Ljd6IiBoZWlnaHQ9IjEwMCUiIHRyYW5zZm9ybT0iIiB3aWR0aD0iMTAwJSIvPjwvY2xpcFBhdGg+PGNsaXBQYXRoIGlkPSJiIj48cGF0aCBkPSJtNzIwLjYgMGgyNTQuNHY1NzIuNGgtMjU0LjR6IiBoZWlnaHQ9IjEwMCUiIHRyYW5zZm9ybT0iIiB3aWR0aD0iMTAwJSIvPjwvY2xpcFBhdG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NkKSIgZD0ibTcyMC42IDQ3MC4zIDI1NC40IDM1OC40di0yMDguMXoiIG9wYWNpdHk9Ii40NSIgdHJhbnNmb3JtPSJtYXRyaXgoLjA1MDgzNzk5IDAgMCAuMDUwODM3OTkgLTI4LjUxMDY2MiAwKSIvPjxwYXRoIGNsaXAtcGF0aD0idXJsKCNlKSIgZD0ibTk3NSA2MjAuNnYyMDguMWwyNTQuNS0zNTguNHoiIG9wYWNpdHk9Ii44IiB0cmFuc2Zvcm09Im1hdHJpeCguMDUwODM3OTkgMCAwIC4wNTA4Mzc5OSAtMjguNTEwNjYyIDApIi8+PC9nPjwvc3ZnPg==











share|improve this question
























  • That decodes to an SVG (provided you're correctly stripping that plaintext header junk first) – drive.google.com/file/d/1h9NCT4mGJ7q5G3iaCjCiRVNIRtBd5WXR/…. BitmapFactory can't do anything with that.
    – Mike M.
    Nov 17 at 8:56












  • @MikeM. so what should I do? if I dnt strip that header junk it gives me error while decoding. In short how can I make it work?
    – Zohab Ali
    Nov 17 at 8:59










  • Oh, never mind. I see where you're stripping that. Anyhoo, it's an SVG. As mentioned, BitmapFactory can't handle that, so it'll just return null.
    – Mike M.
    Nov 17 at 9:00






  • 1




    Here ya go: drive.google.com/file/d/1corT23o1SnXmkYDCSsYfGeqx2JF9ReKX/…. That's what that decodes to.
    – Mike M.
    Nov 17 at 9:07






  • 1




    thanks man! let me test that svg imageview solution. it seems like it should work
    – Zohab Ali
    Nov 17 at 9:09















up vote
0
down vote

favorite
1












I am converting base64 to image but when I set it to imageView it shows nothing.



I have tried almost every solution available on stackoverflow but same result. This is how I am trying to do it right now



var iconBase64String = "myBASE64StringWhichIsGivenBelow"
// remove 'data:image/svg+xml;base64,' from start of string
iconBase64String = iconBase64String.substring(iconBase64String.indexOf(",") + 1)
val image = findViewById<ImageView>(R.id.imageView)

val imageAsBytes = Base64.decode(iconBase64String.toByteArray(), Base64.DEFAULT)
val decodedString = Base64.decode(iconBase64String, Base64.DEFAULT)
val bitmap = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.size)
image.setImageBitmap(bitmap)


I have also tried with glide



var iconBase64String = "myBASE64StringWhichIsGivenBelow"
// remove 'data:image/svg+xml;base64,' from start of string
iconBase64String = iconBase64String.substring(iconBase64String.indexOf(",") + 1)
val image = findViewById<ImageView>(R.id.imageView)

val imageAsBytes = Base64.decode(iconBase64String.toByteArray(), Base64.DEFAULT)
Glide.with(this)
.asBitmap()
.load(imageAsBytes)
.into(image)


here is base64 which i am trying to convert:




data:image/svg+xml;base64,PHN2ZyBoZWlnaHQ9IjU0IiB2aWV3Qm94PSIwIDAgNDIuMTE3ODQgNDIuMTI5NDQ2IiB3aWR0aD0iNTQiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiPjxjbGlwUGF0aCBpZD0iYSI+PHBhdGggZD0ibTcyMC42IDMwNi40aDUwOC43djI2NmgtNTA4Ljd6IiBoZWlnaHQ9IjEwMCUiIHRyYW5zZm9ybT0iIiB3aWR0aD0iMTAwJSIvPjwvY2xpcFBhdGg+PGNsaXBQYXRoIGlkPSJiIj48cGF0aCBkPSJtNzIwLjYgMGgyNTQuNHY1NzIuNGgtMjU0LjR6IiBoZWlnaHQ9IjEwMCUiIHRyYW5zZm9ybT0iIiB3aWR0aD0iMTAwJSIvPjwvY2xpcFBhdGg+PGNsaXBQYXRoIGlkPSJjIj48cGF0aCBkPSJtOTc1IDBoMjU0LjR2NTcyLjRoLTI1NC40eiIgaGVpZ2h0PSIxMDAlIiB0cmFuc2Zvcm09IiIgd2lkdGg9IjEwMCUiLz48L2NsaXBQYXRoPjxjbGlwUGF0aCBpZD0iZCI+PHBhdGggZD0ibTcyMC42IDQ3MC4zaDI1NC40djM1OC40aC0yNTQuNHoiIGhlaWdodD0iMTAwJSIgdHJhbnNmb3JtPSIiIHdpZHRoPSIxMDAlIi8+PC9jbGlwUGF0aD48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4Mzc5OSAtMjguNTEwNjYyIDApIi8+PC9nPjwvc3ZnPg==











share|improve this question
























  • That decodes to an SVG (provided you're correctly stripping that plaintext header junk first) – drive.google.com/file/d/1h9NCT4mGJ7q5G3iaCjCiRVNIRtBd5WXR/…. BitmapFactory can't do anything with that.
    – Mike M.
    Nov 17 at 8:56












  • @MikeM. so what should I do? if I dnt strip that header junk it gives me error while decoding. In short how can I make it work?
    – Zohab Ali
    Nov 17 at 8:59










  • Oh, never mind. I see where you're stripping that. Anyhoo, it's an SVG. As mentioned, BitmapFactory can't handle that, so it'll just return null.
    – Mike M.
    Nov 17 at 9:00






  • 1




    Here ya go: drive.google.com/file/d/1corT23o1SnXmkYDCSsYfGeqx2JF9ReKX/…. That's what that decodes to.
    – Mike M.
    Nov 17 at 9:07






  • 1




    thanks man! let me test that svg imageview solution. it seems like it should work
    – Zohab Ali
    Nov 17 at 9:09













up vote
0
down vote

favorite
1









up vote
0
down vote

favorite
1






1





I am converting base64 to image but when I set it to imageView it shows nothing.



I have tried almost every solution available on stackoverflow but same result. This is how I am trying to do it right now



var iconBase64String = "myBASE64StringWhichIsGivenBelow"
// remove 'data:image/svg+xml;base64,' from start of string
iconBase64String = iconBase64String.substring(iconBase64String.indexOf(",") + 1)
val image = findViewById<ImageView>(R.id.imageView)

val imageAsBytes = Base64.decode(iconBase64String.toByteArray(), Base64.DEFAULT)
val decodedString = Base64.decode(iconBase64String, Base64.DEFAULT)
val bitmap = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.size)
image.setImageBitmap(bitmap)


I have also tried with glide



var iconBase64String = "myBASE64StringWhichIsGivenBelow"
// remove 'data:image/svg+xml;base64,' from start of string
iconBase64String = iconBase64String.substring(iconBase64String.indexOf(",") + 1)
val image = findViewById<ImageView>(R.id.imageView)

val imageAsBytes = Base64.decode(iconBase64String.toByteArray(), Base64.DEFAULT)
Glide.with(this)
.asBitmap()
.load(imageAsBytes)
.into(image)


here is base64 which i am trying to convert:




data:image/svg+xml;base64,P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iIG9wYWNpdHk9Ii42IiB0cmFuc2Zvcm09Im1hdHJpeCguMDUwODM3OTkgMCAwIC4wNTA4Mzc5OSAtMjguNTEwNjYyIDApIi8+PHBhdGggY2xpcC1wYXRoPSJ1cmwoI2IpIiBkPSJtNzIwLjYgNDIyLjEgMjU0LjQgMTUwLjN2LTU3Mi40eiIgb3BhY2l0eT0iLjQ1IiB0cmFuc2Zvcm09Im1hdHJpeCguMDUwODM3OTkgMCAwIC4wNTA4Mzc5OSAtMjguNTEwNjYyIDApIi8+PHBhdGggY2xpcC1wYXRoPSJ1cmwoI2MpIiBkPSJtOTc1IDB2NTcyLjRsMjU0LjMtMTUwLjN6IiBvcGFjaXR5PSIuOCIgdHJhbnNmb3JtPSJtYXRyaXgoLjA1MDgzNzk5IDAgMCAuMDUwODM3OTkgLTI4LjUxMDY2MiAwKSIvPjxwYXRoIGNsaXAtcGF0aD0idXJsKCNkKSIgZD0ibTcyMC42IDQ3MC4zIDI1NC40IDM1OC40di0yMDguMXoiIG9wYWNpdHk9Ii40NSIgdHJhbnNmb3JtPSJtYXRyaXgoLjA1MDgzNzk5IDAgMCAuMDUwODM3OTkgLTI4LjUxMDY2MiAwKSIvPjxwYXRoIGNsaXAtcGF0aD0idXJsKCNlKSIgZD0ibTk3NSA2MjAuNnYyMDguMWwyNTQuNS0zNTguNHoiIG9wYWNpdHk9Ii44IiB0cmFuc2Zvcm09Im1hdHJpeCguMDUwODM3OTkgMCAwIC4wNTA4Mzc5OSAtMjguNTEwNjYyIDApIi8+PC9nPjwvc3ZnPg==











share|improve this question















I am converting base64 to image but when I set it to imageView it shows nothing.



I have tried almost every solution available on stackoverflow but same result. This is how I am trying to do it right now



var iconBase64String = "myBASE64StringWhichIsGivenBelow"
// remove 'data:image/svg+xml;base64,' from start of string
iconBase64String = iconBase64String.substring(iconBase64String.indexOf(",") + 1)
val image = findViewById<ImageView>(R.id.imageView)

val imageAsBytes = Base64.decode(iconBase64String.toByteArray(), Base64.DEFAULT)
val decodedString = Base64.decode(iconBase64String, Base64.DEFAULT)
val bitmap = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.size)
image.setImageBitmap(bitmap)


I have also tried with glide



var iconBase64String = "myBASE64StringWhichIsGivenBelow"
// remove 'data:image/svg+xml;base64,' from start of string
iconBase64String = iconBase64String.substring(iconBase64String.indexOf(",") + 1)
val image = findViewById<ImageView>(R.id.imageView)

val imageAsBytes = Base64.decode(iconBase64String.toByteArray(), Base64.DEFAULT)
Glide.with(this)
.asBitmap()
.load(imageAsBytes)
.into(image)


here is base64 which i am trying to convert:




data:image/svg+xml;base64,PHN2ZyBoZWlnaHQ9IjU0IiB2aWV3Qm94PSIwIDAgNDIuMTE3ODQgNDIuMTI5NDQ2IiB3aWR0aD0iNTQiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiPjxjbGlwUGF0aCBpZD0iYSI+PHBhdGggZD0ibTcyMC42IDMwNi40aDUwOC43djI2NmgtNTA4Ljd6IiBoZWlnaHQ9IjEwMCUiIHRyYW5zZm9ybT0iIiB3aWR0aD0iMTAwJSIvPjwvY2xpcFBhdGg+PGNsaXBQYXRoIGlkPSJiIj48cGF0aCBkPSJtNzIwLjYgMGgyNTQuNHY1NzIuNGgtMjU0LjR6IiBoZWlnaHQ9IjEwMCUiIHRyYW5zZm9ybT0iIiB3aWR0aD0iMTAwJSIvPjwvY2xpcFBhdGg+PGNsaXBQYXRoIGlkPSJjIj48cGF0aCBkPSJtOTc1IDBoMjU0LjR2NTcyLjRoLTI1NC40eiIgaGVpZ2h0PSIxMDAlIiB0cmFuc2Zvcm09IiIgd2lkdGg9IjEwMCUiLz48L2NsaXBQYXRoPjxjbGlwUGF0aCBpZD0iZCI+PHBhdGggZD0ibTcyMC42IDQ3MC4zaDI1NC40djM1OC40aC0yNTQuNHoiIGhlaWdodD0iMTAwJSIgdHJhbnNmb3J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c2Zvcm09Im1hdHJpeCguMDUwODM3OTkgMCAwIC4wNTA4Mzc5OSAtMjguNTEwNjYyIDApIi8+PC9nPjwvc3ZnPg==








android kotlin base64 android-imageview






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 17 at 18:39









Jayson Minard

35.6k13103170




35.6k13103170










asked Nov 17 at 8:53









Zohab Ali

1,1431120




1,1431120












  • That decodes to an SVG (provided you're correctly stripping that plaintext header junk first) – drive.google.com/file/d/1h9NCT4mGJ7q5G3iaCjCiRVNIRtBd5WXR/…. BitmapFactory can't do anything with that.
    – Mike M.
    Nov 17 at 8:56












  • @MikeM. so what should I do? if I dnt strip that header junk it gives me error while decoding. In short how can I make it work?
    – Zohab Ali
    Nov 17 at 8:59










  • Oh, never mind. I see where you're stripping that. Anyhoo, it's an SVG. As mentioned, BitmapFactory can't handle that, so it'll just return null.
    – Mike M.
    Nov 17 at 9:00






  • 1




    Here ya go: drive.google.com/file/d/1corT23o1SnXmkYDCSsYfGeqx2JF9ReKX/…. That's what that decodes to.
    – Mike M.
    Nov 17 at 9:07






  • 1




    thanks man! let me test that svg imageview solution. it seems like it should work
    – Zohab Ali
    Nov 17 at 9:09


















  • That decodes to an SVG (provided you're correctly stripping that plaintext header junk first) – drive.google.com/file/d/1h9NCT4mGJ7q5G3iaCjCiRVNIRtBd5WXR/…. BitmapFactory can't do anything with that.
    – Mike M.
    Nov 17 at 8:56












  • @MikeM. so what should I do? if I dnt strip that header junk it gives me error while decoding. In short how can I make it work?
    – Zohab Ali
    Nov 17 at 8:59










  • Oh, never mind. I see where you're stripping that. Anyhoo, it's an SVG. As mentioned, BitmapFactory can't handle that, so it'll just return null.
    – Mike M.
    Nov 17 at 9:00






  • 1




    Here ya go: drive.google.com/file/d/1corT23o1SnXmkYDCSsYfGeqx2JF9ReKX/…. That's what that decodes to.
    – Mike M.
    Nov 17 at 9:07






  • 1




    thanks man! let me test that svg imageview solution. it seems like it should work
    – Zohab Ali
    Nov 17 at 9:09
















That decodes to an SVG (provided you're correctly stripping that plaintext header junk first) – drive.google.com/file/d/1h9NCT4mGJ7q5G3iaCjCiRVNIRtBd5WXR/…. BitmapFactory can't do anything with that.
– Mike M.
Nov 17 at 8:56






That decodes to an SVG (provided you're correctly stripping that plaintext header junk first) – drive.google.com/file/d/1h9NCT4mGJ7q5G3iaCjCiRVNIRtBd5WXR/…. BitmapFactory can't do anything with that.
– Mike M.
Nov 17 at 8:56














@MikeM. so what should I do? if I dnt strip that header junk it gives me error while decoding. In short how can I make it work?
– Zohab Ali
Nov 17 at 8:59




@MikeM. so what should I do? if I dnt strip that header junk it gives me error while decoding. In short how can I make it work?
– Zohab Ali
Nov 17 at 8:59












Oh, never mind. I see where you're stripping that. Anyhoo, it's an SVG. As mentioned, BitmapFactory can't handle that, so it'll just return null.
– Mike M.
Nov 17 at 9:00




Oh, never mind. I see where you're stripping that. Anyhoo, it's an SVG. As mentioned, BitmapFactory can't handle that, so it'll just return null.
– Mike M.
Nov 17 at 9:00




1




1




Here ya go: drive.google.com/file/d/1corT23o1SnXmkYDCSsYfGeqx2JF9ReKX/…. That's what that decodes to.
– Mike M.
Nov 17 at 9:07




Here ya go: drive.google.com/file/d/1corT23o1SnXmkYDCSsYfGeqx2JF9ReKX/…. That's what that decodes to.
– Mike M.
Nov 17 at 9:07




1




1




thanks man! let me test that svg imageview solution. it seems like it should work
– Zohab Ali
Nov 17 at 9:09




thanks man! let me test that svg imageview solution. it seems like it should work
– Zohab Ali
Nov 17 at 9:09












2 Answers
2






active

oldest

votes

















up vote
0
down vote













You can use glide for show Image



          String photoId="base64value"
Glide.with(getApplicationContext())
.load(photoId)
.apply(RequestOptions.circleCropTransform()) //If you get circule
.into(employeeImage); //xml file name





share|improve this answer





















  • i have already tried this as shown in question but this approach is not working aswell
    – Zohab Ali
    Nov 17 at 9:18


















up vote
-1
down vote













Try this    

String myImageData = null;
myImageData = model.getImagePath();
byte imageAsBytes = new byte[0];
if(null != myImageData) {
try {
imageAsBytes = Base64.decode(myImageData.getBytes(), Base64.DEFAULT);
imageView.setImageBitmap(BitmapFactory.decodeByteArray(imageAsBytes, 0, imageAsBytes.length));
} catch (Exception e) {
e.printStackTrace();
}
}





share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














     

    draft saved


    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53349680%2fconverting-base64-to-image-is-not-working-properly%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote













    You can use glide for show Image



              String photoId="base64value"
    Glide.with(getApplicationContext())
    .load(photoId)
    .apply(RequestOptions.circleCropTransform()) //If you get circule
    .into(employeeImage); //xml file name





    share|improve this answer





















    • i have already tried this as shown in question but this approach is not working aswell
      – Zohab Ali
      Nov 17 at 9:18















    up vote
    0
    down vote













    You can use glide for show Image



              String photoId="base64value"
    Glide.with(getApplicationContext())
    .load(photoId)
    .apply(RequestOptions.circleCropTransform()) //If you get circule
    .into(employeeImage); //xml file name





    share|improve this answer





















    • i have already tried this as shown in question but this approach is not working aswell
      – Zohab Ali
      Nov 17 at 9:18













    up vote
    0
    down vote










    up vote
    0
    down vote









    You can use glide for show Image



              String photoId="base64value"
    Glide.with(getApplicationContext())
    .load(photoId)
    .apply(RequestOptions.circleCropTransform()) //If you get circule
    .into(employeeImage); //xml file name





    share|improve this answer












    You can use glide for show Image



              String photoId="base64value"
    Glide.with(getApplicationContext())
    .load(photoId)
    .apply(RequestOptions.circleCropTransform()) //If you get circule
    .into(employeeImage); //xml file name






    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Nov 17 at 9:16









    Masum

    104




    104












    • i have already tried this as shown in question but this approach is not working aswell
      – Zohab Ali
      Nov 17 at 9:18


















    • i have already tried this as shown in question but this approach is not working aswell
      – Zohab Ali
      Nov 17 at 9:18
















    i have already tried this as shown in question but this approach is not working aswell
    – Zohab Ali
    Nov 17 at 9:18




    i have already tried this as shown in question but this approach is not working aswell
    – Zohab Ali
    Nov 17 at 9:18












    up vote
    -1
    down vote













    Try this    

    String myImageData = null;
    myImageData = model.getImagePath();
    byte imageAsBytes = new byte[0];
    if(null != myImageData) {
    try {
    imageAsBytes = Base64.decode(myImageData.getBytes(), Base64.DEFAULT);
    imageView.setImageBitmap(BitmapFactory.decodeByteArray(imageAsBytes, 0, imageAsBytes.length));
    } catch (Exception e) {
    e.printStackTrace();
    }
    }





    share|improve this answer

























      up vote
      -1
      down vote













      Try this    

      String myImageData = null;
      myImageData = model.getImagePath();
      byte imageAsBytes = new byte[0];
      if(null != myImageData) {
      try {
      imageAsBytes = Base64.decode(myImageData.getBytes(), Base64.DEFAULT);
      imageView.setImageBitmap(BitmapFactory.decodeByteArray(imageAsBytes, 0, imageAsBytes.length));
      } catch (Exception e) {
      e.printStackTrace();
      }
      }





      share|improve this answer























        up vote
        -1
        down vote










        up vote
        -1
        down vote









        Try this    

        String myImageData = null;
        myImageData = model.getImagePath();
        byte imageAsBytes = new byte[0];
        if(null != myImageData) {
        try {
        imageAsBytes = Base64.decode(myImageData.getBytes(), Base64.DEFAULT);
        imageView.setImageBitmap(BitmapFactory.decodeByteArray(imageAsBytes, 0, imageAsBytes.length));
        } catch (Exception e) {
        e.printStackTrace();
        }
        }





        share|improve this answer












        Try this    

        String myImageData = null;
        myImageData = model.getImagePath();
        byte imageAsBytes = new byte[0];
        if(null != myImageData) {
        try {
        imageAsBytes = Base64.decode(myImageData.getBytes(), Base64.DEFAULT);
        imageView.setImageBitmap(BitmapFactory.decodeByteArray(imageAsBytes, 0, imageAsBytes.length));
        } catch (Exception e) {
        e.printStackTrace();
        }
        }






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 17 at 11:08









        veerendran

        343




        343






























             

            draft saved


            draft discarded



















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53349680%2fconverting-base64-to-image-is-not-working-properly%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            "Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

            Alcedinidae

            Origin of the phrase “under your belt”?