Android bitmap byte [] drawable

Source: Internet
Author: User

Android will perform some type conversion when processing a write image resource. Now I have time to sort it out:
1. drawable → bitmap
Java code

  1. Public static bitmap drawabletobitmap (drawable ){
  2. Bitmap bitmap = bitmap
  3. . Createbitmap (
  4. Drawable. getintrinsicwidth (),
  5. Drawable. getintrinsicheight (),
  6. Drawable. getopacity ()! = Pixelformat. opaque? Bitmap. config. argb_8888
  7. : Bitmap. config. rgb_565 );
  8. Canvas canvas = new canvas (Bitmap );
  9. // Canvas. setbitmap (Bitmap );
  10. Drawable. setbounds (0, 0, drawable. getintrinsicwidth (), drawable. getintrinsicheight ());
  11. Drawable. Draw (canvas );
  12. Return bitmap;
  13. }
  14. 2. Obtain bitmap from a resource
  15. Java code
  16. Resources res = getresources ();
  17. Bitmap BMP = bitmapfactory. decoderesource (Res, R. drawable. PIC );
  18. 3. Bitmap → byte []
  19. Java code
  20. Private byte [] bitmap2bytes (Bitmap BM ){
  21. Bytearrayoutputstream baos = new bytearrayoutputstream ();
  22. BM. Compress (bitmap. compressformat. PNG, 100, baos );
  23. Return baos. tobytearray ();
  24. }
  25. 4. byte [] → bitmap
  26. Java code
  27. Private bitmap bytes2bimap (byte [] B ){
  28. If (B. length! = 0 ){
  29. Return bitmapfactory. decodebytearray (B, 0, B. Length );
  30. }
  31. Else {
  32. Return NULL;
  33. }
  34. }

Some activity styles:
• Android: theme = "@ Android: style/theme. Dialog" shows an activity as a dialog box
• Android: theme = "@ Android: style/theme. notitlebar" does not display the application title bar
• Android: theme = "@ Android: style/theme. notitlebar. fullscreen": The application title bar is not displayed and displayed in full screen.
• Android: theme = "@ Android: style/theme. Light" the background is white
• Android: theme = "@ Android: style/theme. Light. notitlebar" the white background does not have a title bar.
• Android: theme = "@ Android: style/theme. Light. notitlebar. fullscreen" white background, no title bar, full screen
• Android: theme = "@ Android: style/theme. Black" background black
• Android: theme = "@ Android: style/theme. Black. notitlebar" the black background does not have a title bar.
• Android: theme = "@ Android: style/theme. Black. notitlebar. fullscreen" black background, no title bar, full screen
• Android: theme = "@ Android: style/theme. Wallpaper" uses the system desktop as the background of the application
• Android: theme = "@ Android: style/theme. wallpaper. notitlebar" uses the system desktop as the background of the application without a title bar.
• Android: theme = "@ Android: style/theme. wallpaper. notitlebar. fullscreen" uses the system desktop as the background of the application, with no title bar and full screen
• Android: theme = "@ Android: style/translucent" Translucent Effect
• Android: theme = "@ Android: style/theme. translucent. notitlebar" translucent and no title bar
• Android: theme = "@ Android: style/theme. translucent. notitlebar. fullscreen" Translucent effect, no title bar, full screen
• Android: theme = "@ Android: style/theme. Panel"

• Android: theme = "@ Android: style/theme. Light. Panel"

From: http://makeyouown.iteye.com/blog/1273319

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.