converting base64 to image is not working properly
up vote
0
down vote
favorite
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+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KSIgZD0ibTcyMC42IDQ3MC4zIDI1NC40IDM1OC40di0yMDguMXoiIG9wYWNpdHk9Ii40NSIgdHJhbnNmb3JtPSJtYXRyaXgoLjA1MDgzNzk5IDAgMCAuMDUwODM3OTkgLTI4LjUxMDY2MiAwKSIvPjxwYXRoIGNsaXAtcGF0aD0idXJsKCNlKSIgZD0ibTk3NSA2MjAuNnYyMDguMWwyNTQuNS0zNTguNHoiIG9wYWNpdHk9Ii44IiB0cmFuc2Zvcm09Im1hdHJpeCguMDUwODM3OTkgMCAwIC4wNTA4Mzc5OSAtMjguNTEwNjYyIDApIi8+PC9nPjwvc3ZnPg==
android kotlin base64 android-imageview
|
show 3 more comments
up vote
0
down vote
favorite
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,PHN2ZyBoZWlnaHQ9IjU0IiB2aWV3Qm94PSIwIDAgNDIuMTE3ODQgNDIuMTI5NDQ2IiB3aWR0aD0iNTQiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIg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kPSJtNzIwLjYgNDIyLjEgMjU0LjQgMTUwLjN2LTU3Mi40eiIgb3BhY2l0eT0iLjQ1IiB0cmFuc2Zvcm09Im1hdHJpeCguMDUwODM3OTkgMCAwIC4wNTA4Mzc5OSAtMjguNTEwNjYyIDApIi8+PHBhdGggY2xpcC1wYXRoPSJ1cmwoI2MpIiBkPSJtOTc1IDB2NTcyLjRsMjU0LjMtMTUwLjN6IiBvcGFjaXR5PSIuOCIgdHJhbnNmb3JtPSJtYXRyaXgoLjA1MDgzNzk5IDAgMCAuMDUwODM3OTkgLTI4LjUxMDY2MiAwKSIvPjxwYXRoIGNsaXAtcGF0aD0idXJsKCNkKSIgZD0ibTcyMC42IDQ3MC4zIDI1NC40IDM1OC40di0yMDguMXoiIG9wYWNpdHk9Ii40NSIgdHJhbnNmb3JtPSJtYXRyaXgoLjA1MDgzNzk5IDAgMCAuMDUwODM3OTkgLTI4LjUxMDY2MiAwKSIvPjxwYXRoIGNsaXAtcGF0aD0idXJsKCNlKSIgZD0ibTk3NSA2MjAuNnYyMDguMWwyNTQuNS0zNTguNHoiIG9wYWNpdHk9Ii44IiB0cmFuc2Zvcm09Im1hdHJpeCguMDUwODM3OTkgMCAwIC4wNTA4Mzc5OSAtMjguNTEwNjYyIDApIi8+PC9nPjwvc3ZnPg==
android kotlin base64 android-imageview
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 thatsvg imageview
solution. it seems like it should work
– Zohab Ali
Nov 17 at 9:09
|
show 3 more comments
up vote
0
down vote
favorite
up vote
0
down vote
favorite
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+PGNsaXBQYXRoIGlkPSJiIj48cGF0aCBkPSJtNzIwLjYgMGgyNTQuNHY1NzIuNGgtMjU0LjR6IiBoZWlnaHQ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MDUwODM3OTkgLTI4LjUxMDY2MiAwKSIvPjxwYXRoIGNsaXAtcGF0aD0idXJsKCNkKSIgZD0ibTcyMC42IDQ3MC4zIDI1NC40IDM1OC40di0yMDguMXoiIG9wYWNpdHk9Ii40NSIgdHJhbnNmb3JtPSJtYXRyaXgoLjA1MDgzNzk5IDAgMCAuMDUwODM3OTkgLTI4LjUxMDY2MiAwKSIvPjxwYXRoIGNsaXAtcGF0aD0idXJsKCNlKSIgZD0ibTk3NSA2MjAuNnYyMDguMWwyNTQuNS0zNTguNHoiIG9wYWNpdHk9Ii44IiB0cmFuc2Zvcm09Im1hdHJpeCguMDUwODM3OTkgMCAwIC4wNTA4Mzc5OSAtMjguNTEwNjYyIDApIi8+PC9nPjwvc3ZnPg==
android kotlin base64 android-imageview
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,PHN2ZyBoZWlnaHQ9IjU0IiB2aWV3Qm94PSIwIDAgNDIuMTE3ODQgNDIuMTI5NDQ2IiB3aWR0aD0iNTQiIHhtbG5zP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i8+PHBhdGggY2xpcC1wYXRoPSJ1cmwoI2IpIiBkPSJtNzIwLjYgNDIyLjEgMjU0LjQgMTUwLjN2LTU3Mi40eiIgb3BhY2l0eT0iLjQ1IiB0cmFuc2Zvcm09Im1hdHJpeCguMDUwODM3OTkgMCAwIC4wNTA4Mzc5OSAtMjguNTEwNjYyIDApIi8+PHBhdGggY2xpcC1wYXRoPSJ1cmwoI2MpIiBkPSJtOTc1IDB2NTcyLjRsMjU0LjMtMTUwLjN6IiBvcGFjaXR5PSIuOCIgdHJhbnNmb3JtPSJtYXRyaXgoLjA1MDgzNzk5IDAgMCAuMDUwODM3OTkgLTI4LjUxMDY2MiAwKSIvPjxwYXRoIGNsaXAtcGF0aD0idXJsKCNkKSIgZD0ibTcyMC42IDQ3MC4zIDI1NC40IDM1OC40di0yMDguMXoiIG9wYWNpdHk9Ii40NSIgdHJhbnNmb3JtPSJtYXRyaXgoLjA1MDgzNzk5IDAgMCAuMDUwODM3OTkgLTI4LjUxMDY2MiAwKSIvPjxwYXRoIGNsaXAtcGF0aD0idXJsKCNlKSIgZD0ibTk3NSA2MjAuNnYyMDguMWwyNTQuNS0zNTguNHoiIG9wYWNpdHk9Ii44IiB0cmFuc2Zvcm09Im1hdHJpeCguMDUwODM3OTkgMCAwIC4wNTA4Mzc5OSAtMjguNTEwNjYyIDApIi8+PC9nPjwvc3ZnPg==
android kotlin base64 android-imageview
android kotlin base64 android-imageview
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 thatsvg imageview
solution. it seems like it should work
– Zohab Ali
Nov 17 at 9:09
|
show 3 more comments
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 thatsvg 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
|
show 3 more comments
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
i have already tried this as shown in question but this approach is not working aswell
– Zohab Ali
Nov 17 at 9:18
add a comment |
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();
}
}
add a comment |
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
i have already tried this as shown in question but this approach is not working aswell
– Zohab Ali
Nov 17 at 9:18
add a comment |
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
i have already tried this as shown in question but this approach is not working aswell
– Zohab Ali
Nov 17 at 9:18
add a comment |
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
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
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
add a comment |
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
add a comment |
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();
}
}
add a comment |
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();
}
}
add a comment |
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();
}
}
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();
}
}
answered Nov 17 at 11:08
veerendran
343
343
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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