---
# System prepended metadata

title: data URI to `BufferedImage`
tags: [imaging, java]

---

# data URI to `BufferedImage`

[TOC]

###### tags: `java` `imaging`

---

```java
String encodingPrefix = "base64,";

int contentStartIndex = dataUrl.indexOf(encodingPrefix) + encodingPrefix.length();

byte[] imageData = Base64.decodeBase64(
	dataUrl.substring(contentStartIndex)
);
```

## References

- [StackOverflow: Convert Data-URL to BufferedImage](https://stackoverflow.com/questions/18569591/convert-data-url-to-bufferedimage)
- [Wikipedia: data URI scheme](https://en.wikipedia.org/wiki/Data_URI_scheme)
