In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
For the question of how to java the base64-bit images generated by the front-end js in the back-end, this article introduces the corresponding analysis and solutions in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible method.
/ / 1. Packages to be introduced
Import java.awt.image.BufferedImage
Import java.io.File
Import java.io.FileInputStream
Import java.io.FileOutputStream
Import java.io.IOException
Import java.io.InputStream
Import java.io.OutputStream
Import javax.imageio.ImageIO
Import com.google.zxing.BinaryBitmap
Import com.google.zxing.MultiFormatReader
Import com.google.zxing.client.j2se.BufferedImageLuminanceSource
Import com.google.zxing.common.HybridBinarizer
Import sun.misc.BASE64Decoder
Import sun.misc.BASE64Encoder
/ / 2. The methods used are:
/ * *
* transfer the picture to BASE64
* @ param imagePath path
* @ return
, /
Public static String imageChangeBase64 (String imagePath) {
InputStream inputStream = null
Byte [] data = null
Try {
InputStream = new FileInputStream (imagePath)
Data = new byte [inputStream.available ()]
InputStream.read (data)
InputStream.close ()
} catch (IOException e) {
E.printStackTrace ()
}
/ / encryption
BASE64Encoder encoder = new BASE64Encoder ()
Return encoder.encode (data)
}
/ * *
* BASE to transfer pictures
* @ param baseStr base64 string
* @ param imagePath generated picture
* @ return
, /
Public static boolean base64ChangeImage (String baseStr,String imagePath) {
If (baseStr = = null) {
Return false
}
BASE64Decoder decoder = new BASE64Decoder ()
Try {
/ / decrypt
Byte [] b = decoder.decodeBuffer (baseStr)
/ / processing data
For (int I = 0; I < b.resume; + + I) {
If (b [I] < 0) {
B [I] + = 256
}
}
OutputStream out = new FileOutputStream (imagePath)
Out.write (b)
Out.flush ()
Out.close ()
Return true
} catch (Exception e) {
Return false
}
}
/ / 3 the method of parsing test:
Public static void test1 () {
/ / the address of the picture to be generated
String pp = imageChangeBase64 ("E:\\ 58744.jpg")
/ / print the generated base64 location code
System.out.println ("pp:" + pp)
String pp3= ""; / / the base64 image code returned to you for the front end is omitted here
Base64ChangeImage (pp2.split (",") [1], "E:\\ bb.jpg")
}
/ / generate a Base64-bit network address for the image:
Http://imgbase64.duoshitong.com/
This is the answer to the question about how the base64-bit images generated by the front-end js can be used in the back-end java. I hope the above content can be of some help to you. If you still have a lot of doubts to solve, you can follow the industry information channel for more related knowledge.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.