图片转为String传个给服务端(四)
g[in2 & 127];
if (in4 == '=') {
pad++;
if (in3 == '=') {
pad++;
} else {
c = valueDecoding[in3 & 127];
}
} else {
c = valueDecoding[in3 & 127];
d = valueDecoding[in4 & 127];
}
if (a < 0 || b < 0 || c < 0 || d < 0) {
throw new IOException("Invalid character in Base64 string");
}
// the first byte is the 6 bits of a and 2 bits of b
out[outOffset] = (byte) (((a << 2) & 0xfc) | ((b >>> 4) & 3));
if (pad < 2) {
// the second byte is 4 bits of b and 4 bits of c
out[outOffset + 1] = (byte) (((b << 4) & 0xf0) | ((c >>> 2) & 0xf));
if (pad < 1) {
// the third byte is 2 bits of c and 4 bits of d
out[outOffset + 2] = (byte) (((c << 6) & 0xc0) | (d & 0x3f));
}
}
}
/**
* 将字符串转换成Bitmap类型
*
* @param string
* @return
*/
public static Bitmap stringtoBitmap(String string) {
Bitmap bitmap = null;
try {
byte[] bitmapArray;
bitmapArray = decode(string);
bitmap = BitmapFactory.decodeByteArray(bitmapArray, 0,bitmapArray.length);
} catch (Exception e) {
e.printStackTrace();
}
return bitmap;
}
}
[java]
public class Base64Coder {
// The line separator string of the operating system.
private static final String systemLineSeparator = System
.getProperty("line.separator");
// Mapping table from 6-bit nibbles to Base64 characters.
private static char[] map1 = new char[64];
static {
int i = 0;
map1[i++] = c;
for (char c = 'a'; c <= 'z'; c++)
map1[i++] = c;
for (char c = '0'; c <= '9'; c++)
map1[i++] = c;
map1[i++] = '+';
map1[i++] = '/';
}
// Mapping table from Base64 characters to 6-bit nibbles.
private static byte[] map2 = new byte[128];
static {
for (int i = 0; i < map2.length; i++)
map2[i] = -1;
for (int i = 0; i < 64; i++)
map2[map1[i]] = (byte) i;
}
/**
* Encodes a string into Base64 format. No blanks or line breaks are
* inserted.
*
* @param s
* A String to be encoded.
* @return A String containing the Base64 encoded data.
*/
public static String encodeString(String s) {
return new String(encode(s.getBytes()));
}
/**
* Encodes a byte array into Base 64 format and breaks the output into lines
* of 76 characters. This method is compatible with
*
sun.misc.BASE64Encoder.encodeBuffer(byte[]).
*
* @param in
* An array containing the data bytes to be encoded.
* @return A String containing the Base64 encoded data, broken into lines.
*/
public static String encodeLines(byte[] in) {
return encodeLines(in, 0, in.length, 76, systemLineSeparator);
}
/**
* Encodes a byte array into Base 64 format and breaks the output into
* lines.
*
* @param in
* An array containing the data bytes to be encoded.
* @param iOff
* Offset of the first byte in
in to be processed.
* @param iLen
* Number of bytes to be processed in
in, starting
* at
iOff.
* @param lineLen
* Line length for the output data. Should be a multip