The recent Android self-study just learned to use asynchronous threads, for opening the asynchronous line loads network pictures used in the bitmap a little bit of a little, what is this??? So I was confident to open the Baidu!! The following is the knowledge I learned!
Baidu Definition:
Bitmap file (Bitmap), the extension can be a. bmp or. dib. A bitmap is a Windows standard format graphics file that defines an image as composed of dots (pixels), each of which can be represented by multiple colors, including 2, 4, 8, 16, 24, and 32-bit colors. For example, a 1024x768 resolution of 32-bit true color picture, which occupies the storage bytes: 1024x768x32/(8*1024) =3072kb (anyway is the image file!! )
While our wirelessly bitmap is defined as a class , it can be said that bitmap is one of the most important classes of image processing in an Android system. It can get image file information, make image cut, rotate, zoom and so on, and can save image file in specified format.
how the bitmap is generated:
The bitmap is implemented in the Android.graphics package. However, the constructors of the bitmap class are private and cannot be instantiated outside, only through JNI instantiation. This is necessarily a helper class that provides an interface for creating bitmap, and the implementation of this class is instantiated bitmap by the JNI interface, which is bitmapfactory
1. convert Files to bitmap
Public Static Final floatDisplay_width = 200; Public Static Final floatDisplay_height = 200;/*** Get picture information from Path */PrivateBitmap Decodebitmap (String path) {bitmapfactory.options op=Newbitmapfactory.options (); //Injustdecodebounds//If set to True, the decoder would return null (no bitmap), but the ...Op.injustdecodebounds =true; Bitmap BMP= Bitmapfactory.decodefile (path, op);//Get dimension information//Get scale size intWratio = (int) Math.ceil (op.outwidth/display_width); intHratio = (int) Math.ceil (op.outheight/display_height); //If the specified size is exceeded, the corresponding scale is scaled down if(Wratio > 1 && hratio > 1){ if(Wratio >hratio) {Op.insamplesize=Wratio; }Else{op.insamplesize=Hratio; }} op.injustdecodebounds=false; BMP=bitmapfactory.decodefile (Path, op); returnbmp;}
When you turn a breakout into bitmap with the Bitmapfactory.decodefile (String path) method, you encounter larger images, and we often encounter the problem of Oom (out of Memory). So we've used the bitmapfactory.options mentioned above to load a scaled-down version to memory (load a scaled down-version into memories).
The following two methods are available for Android to get thumbnail properties:
Public Boolean Injustdecodebounds
If set to True, the decoder would return null (no bitmap), but the ... fields would still be set, allowing the caller to Query the bitmap without has to allocate the memory for its pixels.
If the parameter of Injustdecodebounds (Boolean flag) is true, bitmap is not returned, but the width and height of the bitmap (Op.outwidth and op.outwidth) can be obtained.
Op.insamplesize = ratio;
Setting this property enables compression of the picture
2.Bitmap objects can also be obtained via stream binary stream
/** * stream read from URL */
PublicBitmap Getbitmapfromurl (String urlstring) {Bitmap Bitmap; InputStream InputStream; Try{URL URL=NewURL (urlstring); //returns a URLConnection object that represents the connection to the remote object referenced by the URL//HttpURLConnection is a urlconnection that supports HTTP-specific featuresHttpURLConnection connection =(HttpURLConnection) url.openconnection (); InputStream=NewBufferedinputstream (Connection.getinputstream ()); Try { //load the network under the condition of bad networkThread.Sleep (2000); } Catch(interruptedexception e) {e.printstacktrace (); } //the blog will write a brief introduction about Bitmapfactory bitmap = bitmapfactory.decodestream (inputstream); returnbitmap; } Catch(malformedurlexception e) {e.printstacktrace (); } Catch(IOException e) {e.printstacktrace (); } return NULL; }
Not to be continued.
"Android Self-study diary" about bitmap's understanding and use-incomplete version