Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
243 views
in Technique[技术] by (71.8m points)

c# - All Characters in my Bitmap Textfile are in Chinese

So I am currently working on a program that will extract materials from .fbm files. In the ASCII fbm files, the data to extracted looks as follows: /9j/4Sb7RXhpZgAATU0AKgAAAAgADAEAAAMAAAABEAAAAAEBAAMAAAABEAAAAAECAAMAAAADAAAAngEGAAMAAAABAAIAAAESAAMAAAABAAEAAAEVAAMAAAABAAMAAAEaAAUAAAABAAAApAEbAAUAAAABAAAArAEoAAMAAAABAAIAAAExAAIAAAAiAAAAtAEyAAIAAAAUAAAA1odpAAQAAAABAAAA7AAAASQACAAIAAgACvyAAAAnEAAK/IAAACcQQWRvYmUgUGhvdG9zaG9wIENDIDIwMTcgKFdpbmRvd3MpADIwMTk6MDc6MD ...

And there are several sets of these in the fbm file, each in quotations and comma-separated. Now, when I convert the first one of these strings in the file to a jpg, using the following:

                        //Convert ASCII data to binary
                        string asciiFileData = "";
                        StreamReader binaryDataReader = File.OpenText(Path.Combine(inputDirectory, convertedFBX + iterator.ToString() + ".txt"));
                        while (!binaryDataReader.EndOfStream)
                        {
                            var lineData = binaryDataReader.ReadLine();
                            if (String.IsNullOrEmpty(lineData)) continue;
                            asciiFileData += lineData;
                        }
                        string[] imageStrings = asciiFileData.Split(',');
                        List<byte[]> imageList = new List<byte[]>();
                        foreach (string imageString in imageStrings)
                        {
                            if(imageString.Length > 10)//A way of checking if there's actual data for the file to save
                                imageList.Add(Convert.FromBase64String(imageString.Trim().Replace(",", "").Replace(""", "")));
                        }
                        //Save images
                        int iterator2 = 1;
                        foreach(byte[] image in imageList)
                        {
                            File.WriteAllBytes(Path.Combine(inputDirectory, convertedFBX + iterator.ToString() + iterator2++ + ".jpg"), image);
                        }

The first string creates a proper jpg of the materials. When I open it up in a text file, it's the usual strange alien characters (not quite positive what those are called). However, the jpgs after the first one cannot open. I open up the text files for them, and all the characters are in Chinese! Why on earth is that happening? What does it mean, and is it supposed to be that way? Thanks in advance for your answers!

question from:https://stackoverflow.com/questions/65646219/all-characters-in-my-bitmap-textfile-are-in-chinese

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

This resource was mentioned in the comments; however, my answer was found at https://devblogs.microsoft.com/oldnewthing/20140930-00/?p=43953. Essentially, this error is what occurs when you try to force binary content to be some sort of specific encoding that it's not meant to be.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...