2

我有这张来自服务器的 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);

但位图总是为空,知道吗?谢谢

4

1 回答 1

0

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

input = input.replace("\r\n", "").replace("\\r\\n", "");
于 2013-10-17T15:06:27.657 回答