android - Why PNG forms black edges around the image for PNG format? -
i select image gallery, convert base64 , sends server. jpeg image, works fine; image upload gallery on server same gets shown in server folder. however, when upload png format image mobile gallery, doesn't show same on server; instead creates black edges around it. don't know what's going wrong?
also, actual image equal given jpeg image.
reference images:
jpeg:
png:
i want rid of black borders should not appear png format images.
below code snippet
fileinputstream mfileinputstream = null; try { mfileinputstream = new fileinputstream(imagepathfromsdcard); bytearrayoutputstream bos = new bytearrayoutputstream(); byte[] b = new byte[1024]; int bytesread = 0; while ((bytesread = mfileinputstream.read(b)) != -1) { bos.write(b, 0, bytesread); } bitmap bitmap = safeimageprocessing.decodefile(uri); bitmap.compress(bitmap.compressformat.png, 100, bos); byte[] ba = bos.tobytearray(); string encodedimage = base64.encodetostring(ba, base64.no_wrap); //this line sends image base64 server & there decode original new imageasync().sendimageprocess(getactivity(), encodedimage, this); } catch (filenotfoundexception e) { e.printstacktrace(); } catch (ioexception e) { e.printstacktrace(); }
you want upload image files. use bitmapfactory make bitmap out of them first. compress bitmap jpg or png byte array. after base64 encode bytes string upload.
what waiste. , have changed files. away intermediate bitmap.
instead load files directly in byte array. continue byte array usual.
having said think bad idea base64 encode bytes of file first increases amount of bytes have transferred 30%.
Comments
Post a Comment