Why Bitmap to Base64 String showing black background on webview in android?
The JPEG
format does not support alpha transparency, which is why the transparent background becomes black when you convert your original image to JPEG
.
Use the PNG
format instead:
map1.compress(Bitmap.CompressFormat.PNG, 100, baos);
and
String imgTag = "<img src='data:image/png;base64," + imgToString
+ "' align='left' bgcolor='ff0000'/>";
Android: How to Display a Bitmap in a WebView?
Using the link from itsrajesh4uguys, I've created this code snippet:
// Desired Bitmap and the html code, where you want to place it
Bitmap bitmap = YOUR_BITMAP;
String html="<html><body><img src='{IMAGE_PLACEHOLDER}' /></body></html>";
// Convert bitmap to Base64 encoded image for web
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStream);
byte[] byteArray = byteArrayOutputStream.toByteArray();
String imgageBase64 = Base64.encodeToString(byteArray, Base64.DEFAULT);
String image = "data:image/png;base64," + imgageBase64;
// Use image for the img src parameter in your html and load to webview
html = html.replace("{IMAGE_PLACEHOLDER}", image);
webview.loadDataWithBaseURL("file:///android_asset/", html, "text/html", "utf-8", "");
Android TV: unfocused image contains black transparent background?
I found a way to fix this. VertiGridPresenter
's dimmer default is true
, set it to false
like:
VerticalGridPresenter gridPresenter = new VerticalGridPresenter(FocusHighlight.ZOOM_FACTOR_NONE, false);
or change the theme item <item name="overlayDimDimmedLevel">10%</item>
in @style/Theme.Leanback
, the percent value set the transparent value when set 100% the background will black.
Is this a bug for BitmapFactory while decoding InputStream?
Have you tried
Options options = new BitmapFactory.Options();
options.inScaled = false;
Bitmap source = BitmapFactory.decodeResource(activityName.getResources(), R.id.image, options);
Instead of:
cs = Bitmap.createBitmap(backgroungImage.getWidth(), backgroungImage.getHeight(), backgroungImage.getConfig());
try:
cs = Bitmap.createBitmap(backgroungImage.getWidth(), backgroungImage.getHeight(), Bitmap.Config.ARGB_8888);
how to improve image quality on Canvas.drawBitmap while merging two images?
oh yes, I just make the 3 images of hdpi,mdpi,ldpi "+" image with appropriate resolution. and it works for me.
How to load image (web_image) in Android WebView
f**k.I forgot add this code in the AndroidManifest.xml:
<uses-permission android:name="android.permission.INTERNET" />
Related Topics
Howto Do a Simple Ftp Get File on Android
Splash Screen While Loading a Url in a Webview in Android App
React Native Android Duplicate File Error When Generating APK
How to Filter Listview Using Getfilter() in Baseadapter
How to Clear the Volley Cache Automatically
Android M Write to Sd Card - Permission Denied
How Mdpi, Hdpi, Xhdpi Folder Works
Materialdatepicker Get Selected Dates
How to Add Firebase Database Rules Without Authentication
How to Set Build and Version Number of Flutter App
Fast Scroll Display Problem with Listadapter and Sectionindexer
How Do Popular Apps Authenticate User Requests from Their Mobile App to Their Server
Webview with Asynctask on Android
How to Make a Dialog Slide from Bottom to Middle of Screen in Android