首页 > 解决方案 > 如何在android studio中的webview内画一条线

问题描述

下面的代码在我的 webview 中给了我位图

Bitmap bitmap = bm;
String html="<html><body><img src='dicomFile' /></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("dicomFile", image);
imageView.loadDataWithBaseURL("file:///android_asset/", html, "text/html", "utf-8", "");
imageView.getSettings().setBuiltInZoomControls(true);

我尝试使用下面的代码在 webview 内画线但不工作

paint=new Paint();
canvas.drawLine(50,128, 300, 128, paint);
imageView.draw(canvas);

现在我需要在这个图像内画线。这怎么可能?

标签: androidwebviewandroid-canvasandroid-drawable

解决方案


推荐阅读