Take a path of a bitmap image and convert it into Base64 - java

I'm trying to take a path of an image like:
"content://media/external/images/media/3"
and convert it into a base64 string.
Here is the code I have now:
public String ConvertandSetImagetoBase64(String imagePath) {
String base64 = null;
byte[] input = null;
try{
FileInputStream fd = new FileInputStream(imagePath);
Bitmap bmt = BitmapFactory.decodeFileDescriptor(fd.getFD());
try{
ByteArrayOutputStream stream = new ByteArrayOutputStream();
Bitmap tmp = ProfileActivity.scaleDownBitmap(bmt, 10, this);
tmp.compress(Bitmap.CompressFormat.JPEG, 10, stream);
input = stream.toByteArray();
base64 = Base64.encodeToString(input, Base64.DEFAULT);
//LocalProfileActivity.input = input;
}catch(Exception e){
Log.e(LOG_TAG,"[ONACTIVITYRESULT] Could not bind input to the bytearray: " + e.getMessage());
}
}
catch (Exception e){
Log.e("LocalProfile", "ConvertandSetImagetoBase64: Could not load selected profile image");
}
return base64;
}
content://media/external/images/media/3 is what I'm passing into the the method. Can anyone help me?

Since you are specifying the location as a URI, you could try something like:
URL url = new URL(imagePath);
Bitmap bmt = BitmapFactory.decodeStream(url.openStream());

Related

convert to base 64 with A reapeat in result?

I get url in android and convert data stream to 64 bit data string with this code:
URL url = new URL("http://iranassistance.com/images/sos-logo.png");
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setRequestMethod("GET");
//urlConnection.setDoOutput(true);
urlConnection.connect();
File SDCardRoot = Environment.getExternalStorageDirectory().getAbsoluteFile();
String filename="downloadedFile.png";
Log.i("Local filename:",""+filename);
File file = new File(SDCardRoot,filename);
if(file.createNewFile()) {
file.createNewFile();
}
FileOutputStream fileOutput = new FileOutputStream(file);
InputStream inputStream = urlConnection.getInputStream();byte[] imageBytes = new byte[urlConnection.getContentLength()];
inputStream.read(imageBytes, 0, imageBytes.length);
inputStream.close();
String base64Image = Base64.encodeToString(imageBytes, Base64.DEFAULT);
But the base64Image result is not complete and gave something like this :
......nUTJaJnb7PLyscfBMQLLiexyKSEh/o2RfctcZtc8Hr5xcAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA........
The repeated 'A' show something is wrong and image is not complete! Why this not work properly ?
Simple:
inputStream.read(imageBytes, 0, imageBytes.length);
You assume that the above always reads all bytes in one shot.
Wrong. This method reads as many bytes as it wants to read. Therefore it is returning you the number of bytes read. See its javadoc:
Returns: the total number of bytes read into the buffer, or -1 if there is no more data because the end of the stream has been reached.
In other words: you have to loop and accumulate these numbers until you got exactly the amount of bytes you are looking for!
And you get those A chars: your array is initially all 0. As explained: you are only filling parts of that array. So the rest of the arrays has still 0s in it - which results as AAAAAs after encoding.
You can use the following function to convert image into base64 just pass on your image....
private String encodeImage(Bitmap mphoto)
{
ByteArrayOutputStream baos = new ByteArrayOutputStream();
mphoto.compress(Bitmap.CompressFormat.JPEG,100,baos);
byte[] b = baos.toByteArray();
String encImage = Base64.encodeToString(b, Base64.DEFAULT);
return encImage;
}
GhostCat said the correct answer ,
i change my code as bellow and it worked find :
InputStream is = null;
try {
URL url = new URL("http://iranassistance.com/images/sos-logo.png");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
is = url.openStream ();
byte[] byteChunk = new byte[4096];
int n;
while ( (n = is.read(byteChunk)) > 0 ) {
baos.write(byteChunk, 0, n);
}
String base64Image2 = Base64.encodeToString(baos.toByteArray(), Base64.DEFAULT);
db.UpdateImage64(base64Image2);
productModel pd = db.GetProductById(2);
}
catch (IOException e) {
e.printStackTrace ();
}
finally {
if (is != null) {
try{
is.close();
}
catch (IOException s){
}
}
}

Xamarin android image URI to Byte array

i'm simply trying to upload image to server.
when i choose image from , i get URI to that image.
the question is how can i convert this URI to byte[] byte array?
no more no less. thats my question
this is what ive been trying.
i tried to rewrite this https://colinyeoh.wordpress.com/2012/05/18/android-convert-image-uri-to-byte-array/
to C#
public byte[] convertImageToByte(Android.Net.Uri uri)
{
byte[] data = null;
try
{
ContentResolver cr = this.ContentResolver;
var inputStream = cr.OpenInputStream(uri);
Bitmap bitmap = BitmapFactory.DecodeStream(inputStream);
var baos = new ByteArrayOutputStream();
bitmap.Compress(Bitmap.CompressFormat.Jpeg, 100, baos);
data = baos.ToByteArray();
}
catch (FileNotFoundException e)
{
e.PrintStackTrace();
}
return data;
}
but the error...
Error CS1503: Argument `#3' cannot convert `Java.IO.ByteArrayOutputStream' expression to type `System.IO.Stream' (CS1503) (Foodle.Droid)
how to fix this? or new code to get image from gallery and convert that to byte array is fine.
help!
public byte[] convertImageToByte(Android.Net.Uri uri)
{
Stream stream = ContentResolver.OpenInputStream(uri);
byte[] byteArray;
using (var memoryStream = new MemoryStream())
{
stream.CopyTo(memoryStream);
byteArray = memoryStream.ToArray();
}
return byteArray;
}

Convert base64 string to image

I am trying to crop/resize user profile image using jquery plugin namely crop.js which sends user image as base64 via ajax to my controller as
$.ajax({
type: "post",
dataType: "json",
url: "${g.createLink(controller: 'personalDetail', action:'uploadUserImage')}",
data: { avatar: canvas.toDataURL() }
});
but I unable to decode this base64
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAPAAAADwCAYAAAA+VemSAAAgAEl...=='
string as Image,Can you guys guide me how can I save my base64 string as image on my server?.
In the server, do something like this:
Suppose
String data = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAPAAAADwCAYAAAA+VemSAAAgAEl...=='
Then:
String base64Image = data.split(",")[1];
byte[] imageBytes = javax.xml.bind.DatatypeConverter.parseBase64Binary(base64Image);
Then you can do whatever you like with the bytes like:
BufferedImage img = ImageIO.read(new ByteArrayInputStream(imageBytes));
This assumes a few things, that you know what the output file name will be and that your data comes as a string. I'm sure you can modify the following to meet your needs:
// Needed Imports
import java.io.ByteArrayInputStream;
import sun.misc.BASE64Decoder;
def sourceData = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAPAAAADwCAYAAAA+VemSAAAgAEl...==';
// tokenize the data
def parts = sourceData.tokenize(",");
def imageString = parts[1];
// create a buffered image
BufferedImage image = null;
byte[] imageByte;
BASE64Decoder decoder = new BASE64Decoder();
imageByte = decoder.decodeBuffer(imageString);
ByteArrayInputStream bis = new ByteArrayInputStream(imageByte);
image = ImageIO.read(bis);
bis.close();
// write the image to a file
File outputfile = new File("image.png");
ImageIO.write(image, "png", outputfile);
Please note, this is just an example of what parts are involved. I haven't optimized this code at all and it's written off the top of my head.
ImageIO.write() will compress the image by default - the compressed image has a smaller size but looks strange sometimes. I use BufferedOutputStream to save the byte array data - this will keep the original image size.
Here is the code:
import javax.xml.bind.DatatypeConverter;
import java.io.*;
public class ImageTest {
public static void main(String[] args) {
String base64String = "data:image/jpeg;base64,iVBORw0KGgoAAAANSUhEUgAAAHkAAAB5C...";
String[] strings = base64String.split(",");
String extension;
switch (strings[0]) {//check image's extension
case "data:image/jpeg;base64":
extension = "jpeg";
break;
case "data:image/png;base64":
extension = "png";
break;
default://should write cases for more images types
extension = "jpg";
break;
}
//convert base64 string to binary data
byte[] data = DatatypeConverter.parseBase64Binary(strings[1]);
String path = "C:\\Users\\Ene\\Desktop\\test_image." + extension;
File file = new File(path);
try (OutputStream outputStream = new BufferedOutputStream(new FileOutputStream(file))) {
outputStream.write(data);
} catch (IOException e) {
e.printStackTrace();
}
}
}
Simplicity is:
import java.util.Base64;
To decode:
byte[] image = Base64.getDecoder().decode(base64string);
To encode:
String text = Base64.getEncoder().encodeToString(imageData);
Server side encoding files/Images to base64String ready for client side consumption
public Optional<String> InputStreamToBase64(Optional<InputStream> inputStream) throws IOException{
if (inputStream.isPresent()) {
ByteArrayOutputStream output = new ByteArrayOutputStream();
FileCopyUtils.copy(inputStream.get(), output);
//TODO retrieve content type from file, & replace png below with it
return Optional.ofNullable("data:image/png;base64," + DatatypeConverter.printBase64Binary(output.toByteArray()));
}
return Optional.empty();
}
Server side base64 Image/File decoder
public Optional<InputStream> Base64InputStream(Optional<String> base64String)throws IOException {
if (base64String.isPresent()) {
return Optional.ofNullable(new ByteArrayInputStream(DatatypeConverter.parseBase64Binary(base64String.get())));
}
return Optional.empty();
}
public Optional<String> InputStreamToBase64(Optional<InputStream> inputStream) throws IOException{
if (inputStream.isPresent()) {
ByteArrayOutputStream outpString base64Image = data.split(",")[1];
byte[] imageBytes = javax.xml.bind.DatatypeConverter.parseBase64Binary(base64Image);
Then you can do whatever you like with the bytes like:
BufferedImage img = ImageIO.read(new ByteArrayInputStream(imageBytes));ut = new ByteArrayOutputStream();
FileCopyUtils.copy(inputStream.get(), output);
//TODO retrieve content type from file, & replace png below with it
return Optional.ofNullable("data:image/png;base64," + DatatypeConverter.printBase64Binary(output.toByteArray()));
}
return Optional.empty();
Hi This is my solution
Javascript code
var base64before = document.querySelector('img').src;
var base64 = base64before.replace(/^data:image\/(png|jpg);base64,/, "");
var httpPost = new XMLHttpRequest();
var path = "your url";
var data = JSON.stringify(base64);
httpPost.open("POST", path, false);
// Set the content type of the request to json since that's what's being sent
httpPost.setRequestHeader('Content-Type', 'application/json');
httpPost.send(data);
This is my Java code.
public void saveImage(InputStream imageStream){
InputStream inStream = imageStream;
try {
String dataString = convertStreamToString(inStream);
byte[] imageBytes = javax.xml.bind.DatatypeConverter.parseBase64Binary(dataString);
BufferedImage image = ImageIO.read(new ByteArrayInputStream(imageBytes));
// write the image to a file
File outputfile = new File("/Users/paul/Desktop/testkey/myImage.png");
ImageIO.write(image, "png", outputfile);
}catch(Exception e) {
System.out.println(e.getStackTrace());
}
}
static String convertStreamToString(java.io.InputStream is) {
java.util.Scanner s = new java.util.Scanner(is).useDelimiter("\\A");
return s.hasNext() ? s.next() : "";
}
This is Ayano's excellent answer, but in Clojure:
(:import (java.awt.image BufferedImage)
(javax.xml.bind DatatypeConverter)
(java.io File BufferedOutputStream FileOutputStream))
(defn write-svg-encountered-image [svg-img-data base-filename]
(let [[meta img-data] (str/split svg-img-data #",")
extension (case meta
"data:image/jpeg;base64" ".jpeg"
"data:image/png;base64" ".png"
(throw (Error. (format "Unrecognised image metadata in SVG:" meta))))
path (str base-filename extension)
file (File. path)
data-bytes (DatatypeConverter/parseBase64Binary img-data)
os (BufferedOutputStream. (FileOutputStream. file))]
(.write os data-bytes)))
To Convert all file types
String[] strings = expense.getAttchBase64().split(",");
String extension;
switch (strings[0]) {//check image's extension
case "data:image/jpeg;base64":
extension = "jpeg";
break;
case "data:image/png;base64":
extension = "png";
break;
case "data:application/pdf;base64":
extension = "pdf";
break;
case "data:application/vnd.openxmlformats-officedocument.wordprocessingml.document;base64":
extension = "docx";
break;
default://should write cases for more images types
extension = "jpg";
break;
}
//convert base64 string to binary data
byte[] data = DatatypeConverter.parseBase64Binary(strings[1]);
String fileName = UUID.randomUUID().toString();
String path = "C:\\floridatrading\\" + fileName + "." + extension;
File file = new File(path);
try (OutputStream outputStream = new BufferedOutputStream(new FileOutputStream(file))) {
outputStream.write(data);
} catch (IOException e) {
e.printStackTrace();
}
if you need to add any new type just add It in switch .

Null returned from ImageIO.read(new ByteArrayInputStream(bs));

I am trying to convert Base64 encoded string (from image) [link to convertor]. Here is how I do this: First I convert the string, which is:
String str =
/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAAkGBxQHBhMTEhQWFBUUGBUZGRYXFxgXGBQWFRQYGBQVFxgaISogGBomGxUXITEiJSkrLi4uFx8zODMsNygtLisBCgoKDgwMFw8PFywcFB4sLCwsNyssLDcrLCwsKzcsNzc3NzcsKywsKysrLCsrKywsNysrLCsrKyssKysrKysrK//AABEIALEBHQMBIgACEQEDEQH/xAAbAAEAAgMBAQAAAAAAAAAAAAAABAUCAwYBB//EADcQAAIBAwEFBQcEAgIDAQAAAAABAgMEERIFITFBURMiMnGhFBU0UmGRsXKBweHR8EJDM2KCBv/EABQBAQAAAAAAAAAAAAAAAAAAAAD/xAAUEQEAAAAAAAAAAAAAAAAAAAAA/9oADAMBAAIRAxEAPwD7iAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA4ARb29jaR372+C/3gVU9rVJPdhft/ki3NV167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hvzu8KWMf9iPduXErazTg3FucI5UdTxKWHiOHl/QCwBWbDu5XMailJycJ4WqKhPS4ppyhyy843cDfsuvK4pTcnnFWrFfpjUaivsgJgKfbF3OjfU4xnKCcZt6KfaNuLgluw2l3nvLCxbdrFuTk3vzKOh73uzHCwBIAAAAAAAAAAAAARtoWvtltpzjvQecZ8E4yx++nH7mqrs2M9pwrLdKOU+kk4tLK6rPEnACBcWU/anUpVFBySUlKGpSa8MtzTUsbuPDHQ32Nr7Jb6cuTbblJ4zKUnlt4/3GCQAMakddNrqmvuaNn2isrSEFjMYxi5JY1OKxl/7zJIAjK1xtF1c8YRhjHSUpZz/9eh5bWapdrl6lVm5YxwTjGLi+vh9SUAKqOy6jpxpyq6qUWu7o70oxeYwlLOGuGdyzjzLSa1Qa6noAi21kqezI0Zd5KCg92NSUdL3EWGzaktMalXXTg09OjEpaXmCnLO/GFwSzgtAAIV/s9X9SGtvTBt6U3FuWMRepNNYy/uTQBE2dZewU5RTzHU3FPLcU97WW9+/L/cxtdnRttoVaqe+pjdjw4Xex5vDfkTQBW3Wx4XtzOVRt6oqKSlKKit+c4fey3z6IlU7drZ6pylqejS5Y47samupIAEGrs/tNjdhq/wCtQ1Y6RxnGf5NtpCrBvtJwl00wccdc5k8kkAVFbYUaznJyl2kpalNOSUXHGjuasPGFxJm0bR3dvFKSjKMoSTaysweeGVu3dSWAIdjZyoVpznPXOelNqOmKUM6Ull/M+L5mm0sqtrWeKkNEpzm49m9Xfk5NatX144LIAQb2znVvIVKc4wcYyj3oOSak4vlJY8JKt4yjRSm1KW/LUdK47t2Xy+psAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAH//2Q==
like this:
byte[] imageString = str.getBytes("UTF-8");
and then I want to save the file on machine like this:
public boolean uploadImage(byte[] imageString, String name, String extension)
{
BufferedImage image = null;
String path = EVENT_FOLDER + name + "." + extension;
try
{
image = ImageIO.read(new ByteArrayInputStream(imageString)); //null returned here
ImageIO.write(image, extension, new File(path));
}
catch (IOException e)
{
e.printStackTrace();
return false;
}
But I am getting null on this line: image = ImageIO.read(new ByteArrayInputStream(imageString));
What did I do wrong??
What did I do wrong?
You ignored the fact that the data is Base64-encoded, not UTF-8.
To convert the string to bytes to get the original data, you need to reverse that Base64 encoding, for example using this library.
byte[] imageData = Base64.decode(str);

Writing decoded base64 byte array as image file

String base64Code = dataInputStream.readUTF();
byte[] decodedString = null;
decodedString = Base64.decodeBase64(base64Code);
FileOutputStream imageOutFile = new FileOutputStream(
"E:/water-drop-after-convert.jpg");
imageOutFile.write(decodedString);
imageOutFile.close();
The problem is the data is transferred completely and if the data is in text format it is displayed correctly however when i am trying to decode image and write it on output file,it doesnt simply show up in photo viewer.
Any help would be highly appreciated
DataInputStream.readUTF may be the issue. This method assumes that the text was written to the file by DataOutputStream.writeUTF. If it is not so, and you are going to read a regular text, choose a different class, like BufferedReader or Scanner. Or Java 1.7's Files.readAllBytes.
Once I had to convert the Image into base 64 and sent that image as stream (encoding and decoding stuff here is the code)
To Convert a file into base64 :
String filePath = "E:\\water-drop-after-convert.jpg";
File bMap = new File(filePath);
byte[] bFile = new byte[(int) bMap.length()];
FileInputStream fileInputStream = null;
String imageFileBase64 = null;
try {
fileInputStream = new FileInputStream(bMap);
fileInputStream.read(bFile);
fileInputStream.close();
imageFileBase64 = Base64.encode(bFile);
}catch(Exception e){
e.printStackTrace();
}
then on service side I did thing like that to convert image in base 64 String back into file, so that i can display.
I had used this library on server side import sun.misc.BASE64Decoder;
//filePath is where you wana save image
String filePath = "E:\\water-drop-after-convert.jpg";
File imageFile = new File(filePath);
FileOutputStream fos = null;
try {
fos = new FileOutputStream(imageFile);
} catch (FileNotFoundException e1) {
e1.printStackTrace();
}
BASE64Decoder decoder = new BASE64Decoder();
byte[] decodedBytes = null;
try {
decodedBytes = decoder.decodeBuffer(imageFileBase64);//taking input string i.e the image contents in base 64
} catch (IOException e1) {
e1.printStackTrace();
}
try {
fos.write(decodedBytes);
} catch (IOException e) {
e.printStackTrace();
}
try {
fos.flush();
fos.close();
} catch (IOException e) {
e.printStackTrace();
}

Categories

Resources