使用此方法对图像进行编码后:
```{r, echo=TRUE}
htmltools::tagList(lapply(1:4,myfun))
```
然后我将其上传到服务器:
public String getStringImage(Bitmap bmp) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.JPEG, 0, baos);
byte[] imageBytes = baos.toByteArray();
String encodedImage = Base64.encodeToString(imageBytes, Base64.DEFAULT);
return encodedImage;
}
我注意到字符串中缺少一些空格,并且在将其上传到MySQLi数据库后图片被破坏了。我尝试了不同的标题,但它们没有用。 我该如何解决这个问题?
编辑: 这是将pic插入数据库的php文件:
ImageString = getStringImage(bitmap);
String content="image="+ImageString;
final OkHttpClient client = new OkHttpClient();
Request request;
MediaType contentType = MediaType.parse("application/x-www-form-urlencoded; charset=UTF-8");
RequestBody body = RequestBody.create(contentType, content);
request = new Request.Builder().url(uploadURL).post(body).build();
Response response = null;
try {
response = client.newCall(request).execute();
} catch (IOException e) {
e.printStackTrace();
}
try {
String json = response.body().string();
} catch (IOException e) {
e.printStackTrace();
}