Can't figure out where these C # and Java code are different

I have C # code that converts an image to a base64 string. The code:

MemoryStream ms = new MemoryStream();
Image img = Image.FromFile(filename);
img.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
string s = Convert.ToBase64String(ms.GetBuffer());

I am trying to implement it using JAVA. my java code is:

BufferedImage img = null;
img = ImageIO.read(new File(filename));
byte[] bytes = ((DataBufferByte)img.getData().getDataBuffer()).getData();
String js = Base64.encodeBase64String(bytes);

this two code snippets should return the same line for the same image file. But they return different strings. I can’t understand why. Can anyone shed light on him?

+3
source share
1 answer

this two code snippets should return the same line for the same image file

No, they really shouldn't.

# base64 JPEG , , 0s , GetBuffer ToArray. ( ToArray .)

Java SampleModel. , , , #.

, , - .

, " base64", Image. , # :

string base64 = Convert.ToBase64String(File.ReadAllBytes(filename));

, , - , base64, .

+7

All Articles