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 > Development >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly explains "how to use LitePal to operate the database in Android". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to operate the database with LitePal in Android".
1. Convert the picture to bytes
Private byte [] img (Bitmap bitmap) {ByteArrayOutputStream baos = new ByteArrayOutputStream (); bitmap.compress (Bitmap.CompressFormat.PNG, 100, baos); return baos.toByteArray ();}
2. Store the pictures in the database
Suppose the acquired picture is bitmap, the database has a User table, and the stored attribute is byte [] headshot.
Public class User extends DataSupport {private byte [] headshot;// profile portrait public User () {super ();} public User (byte [] headshot) {super (); this.headshot=headshot;} public byte [] getHeadshot () {return headshot;} public void setHeadshot (byte [] headshot) {this.headshot=headshot;}}
Save the picture
/ / get the picture Bitmap headShot=BitmapFactory.decodeFile (imagePath); / / convert the picture to byte stream byte [] images=img (headShot); / / find the user User users=DataSupport.findFirst (User.class); / / Save users.setHeadshot (images); users.save ()
4. Get the picture
User mUser=DataSupport.findFrist (User.class); byte [] images=mUser.getHeadshot (); Bitmap bitmap=BitmapFactory.decodeByteArray (images,0,images.length); Thank you for reading, these are the contents of "how to use LitePal to operate the database in Android". After the study of this article, I believe you have a deeper understanding of how to use LitePal to operate the database in Android, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
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.