简体   繁体   中英

Convert Base64 String to an Image File and Save it to File System?

I am trying to make a.Net 6 console application that would take in a base64string and then save it to the file system as an actual image file

Example

I have this image

https://cdn.pixabay.com/photo/2016/03/28/12/35/cat-1285634_960_720.png

I would have this image already as a base64 string.

Now I want to save to my file system as "cat-1285634_960_720.png"

I just can't figure out how to do it. All the examples I see say to use Image.Save() but I can't find that in.Net6 and looks like it is removed.

First convert the base64 string to a byte array and then use File.WriteAllBytes(...) to save it:

byte[] imageByteArray = Convert.FromBase64String(base64String);

File.WriteAllBytes("image.png", imageByteArray);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM