Home > Net >  (turn to 1) the base64 difference between Java and c # lead to decoding error
(turn to 1) the base64 difference between Java and c # lead to decoding error

Time:11-09

Recently to do a project requirements is the Android gallery images into base64 endures database
Then winfrom in c # to display
Turn out of the picture is after the bear sample check data, Android and c # base64 conversion out the results of different
Presence of bosses guidance from

Java:
Public String BitmapStrByBase64 (Bitmap bit) {
ByteArrayOutputStream bos=new ByteArrayOutputStream ();
Bit.com press (Bitmap.Com pressFormat. JPEG, 100, bos);//parameter 100 said without compression
Byte [] bytes=bos. ToByteArray ();
Return Base64. EncodeToString (bytes, Base64. DEFAULT);
}
C # :
Public Bitmap Base64StringToImage (string strbase64)
{
Try
{
Byte [] arr=the Convert. FromBase64String (strbase64);
MemoryStream ms=new MemoryStream (arr);
BMP=new Bitmap (ms);
Ms. Close ();
Return BMP.
}
The catch (Exception ex)
{
return null;
}
}

CodePudding user response:

SoS!!!!!!

CodePudding user response:

SOS!!!!!!

CodePudding user response:

Sosssssss!!!!!!

CodePudding user response:

You put in the same period of byte [] in c # and Java coding respectively, then, are the same, I think is not necessarily the base64 encoding of the problem, the problem of image format is possible,

CodePudding user response:

reference 4 floor tanta response:
you put in the same period of byte [] in c # and Java coding respectively, then, are the same, I think is not necessarily the base64 encoding of the problem, the problem of image format, likely also
I tried different format of picture JPG jpeg, PNG have tried

CodePudding user response:

refer to 6th floor HZTLTGG response:
upper part is not a normal picture? Behind to homogeneous, feeling as if transport or storage has been truncated
this is to my confusing place I turn out the value stored in TXT take out and then copied to the database and then pictures don't show out on winfrom don't know why

CodePudding user response:

Please let your android in parameter

Because Android Base64 encoding is the default line feed, for server authentication, there will be a validation failure, this is because the server side of the decoder does not support a newline mode, so the code needs to increase the flag symbol, Android there are the following flag,
Flag are as follows:
The DEFAULT DEFAULT mode
NO_WRAP filter line breaks
NO_PADDING filtering terminator=
Change URL_SAFE will +/-, _
CRLF newline mode selected Windows instead of Unix lf

You now the parameters, the android will wrap, but also use the Unix newline

CodePudding user response:

refer to the eighth floor wanghui0380 response:
android please let you change the parameter

Because Android Base64 encoding is the default line feed, for server authentication, there will be a validation failure, this is because the server side of the decoder does not support a newline mode, so the code needs to increase the flag symbol, Android there are the following flag,
Flag are as follows:
The DEFAULT DEFAULT mode
NO_WRAP filter line breaks
NO_PADDING filtering terminator=
Change URL_SAFE will +/-, _
CRLF newline mode selected Windows instead of Unix lf

You now the parameters, the android will wrap, but also use the Unix newline
I wrote that the android... Still like this after the change parameter to NO_WRAP
  •  Tags:  
  • C#
  • Related