android - Bitmap to Base64 String -


i trying following code encode bitmap base64 string, wrong encoding.

by way, filepath image file path.

public string encode(string filepath) {     bytearrayoutputstream stream = new bytearrayoutputstream();     bitmap bitmap = bitmapfactory.decodefile(filepath, options);     bitmap.compress(bitmap.compressformat.png, 100, stream);     byte[] byte_arr = stream.tobytearray();     return base64.encodetostring(byte_arr, base64.default); } 

how know if wrong encoding? use website:

http://codebeautify.org/base64-to-image-converter

try code proper encoding me. hope may you.

public string getstringimage(bitmap bmp) { bytearrayoutputstream baos = new bytearrayoutputstream(); bmp.compress(bitmap.compressformat.jpeg, 100, baos); byte[] imagebytes = baos.tobytearray(); string encodedimage = base64.encodetostring(imagebytes, base64.default); return encodedimage; } 

Comments

Popular posts from this blog

amazon web services - S3 Pre-signed POST validate file type? -

c# - Check Keyboard Input Winforms -