解码Base 64图像到位图Android

时间:2013-10-17 14:57:53

标签: java android base64

我在服务器的base64中有这个图像

iVBORw0KGgoAAAANSUhEUgAAAKcAAABACAIAAADwNfCBAAABc0lEQVR42u3awU7EIBRA0f7/T+ti\r\nYtNQeIWBplTOXZpo9B1gaOP2o/XajIC6qIu6qIu6qIu6qIu6qIu6qIu6qIu6qIu6qFMXdVEXdVFP\r\nftxfE/2Fh3iPV9/HOsl8E2zw49WPA51huCVj8P9cvenr1HtH/PhkP79AdrtTH6M+4WR3dXv9AfWe\r\nEfdcvEvqyMeo15MHEz8Dd66bJvUFl8LD6smT1SiS8yERXOmpD1OvJK+8crfalE6OyV8wvEM9sLxU\r\nr18WwdXscqHEy2W2p823qmd3T/a8rXy2/mI7Vh4Msz1tvl69ybjmJVrP8Y78XvV93MFGz37iXq6D\r\nserxOUS97cH6fPPKLoLg9M6um9J3Nd024pWaRL1hu5ewE7PSi9LgI7yJpPL6tvJ7m204eelUr5xv\r\nP4MXcDeq33EhQj61+rR3YOorqusudeTUqa+njpy6FlBHvpy6fy9fTh35is/roi7qoi7qoi7qoi7q\r\noi7qoi7qyvYLRlwpio989F0AAAAASUVORK5CYA==

我正在测试在位图中显示图像,

byte [] byteArray = android.util.Base64.decode(input, android.util.Base64.DEFAULT);
Bitmap bitmap = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length);

但是位图总是为空,任何想法?感谢

1 个答案:

答案 0 :(得分:0)

您的Base64字符序列中有换行符。试着摆脱它们。我在说这个:\r\n。试试这个:(因为我不知道你是如何格式化字符串的):

input = input.replace("\r\n", "").replace("\\r\\n", "");