Immediately after the last post, there was a problem getting the picture taken and setting it as the background.
The system gives such a warning:
Bitmap too large to being uploaded into a texture
The meaning is obvious: now the mobile phone hardware is getting tougher (-.-| |). The picture is too big to be displayed directly.
Online there are said to turn off hardware to speed up the way to drink fragmented loading. But that's not what I want. This kind of problem naturally compresses the image
What a!!
Zip Code:
/*** Image Quality Compression * **/ PrivateBitmap compressimage (Bitmap image) {Bytearrayoutputstream BAOs=NewBytearrayoutputstream (); Image.compress (Bitmap.CompressFormat.JPEG,, BAOs);//mass compression method, where 100 means no compression, the compressed data stored in the BAOs intoptions = 100; while(Baos.tobytearray (). length/1024>100) {//loop to determine if the image is larger than 100kb after compressionBaos.reset ();//Reset BAOs is empty BAOsOptions-= 10;//each time, it's reduced by tenImage.compress (Bitmap.CompressFormat.JPEG, Options, BAOs);//this compresses the options% and stores the compressed data in the BAOs .} bytearrayinputstream ISBM=NewBytearrayinputstream (Baos.tobytearray ());//Store the compressed data BAOs in the BytearrayinputstreamBitmap Bitmap = Bitmapfactory.decodestream (ISBM,NULL,NULL);//generate images from the Bytearrayinputstream data returnbitmap; } /*** Picture Proportional compression **/ PrivateBitmap getimage (String srcpath) {bitmapfactory.options newopts=Newbitmapfactory.options (); //start reading the picture, this time set the Options.injustdecodebounds back to TrueNewopts.injustdecodebounds =true; Bitmap Bitmap= Bitmapfactory.decodefile (srcpath,newopts);//return BM is empty at this timeNewopts.injustdecodebounds=false; intW =Newopts.outwidth; inth =Newopts.outheight; //now the mainstream phone is more 800*480 resolution, so the height and width we set to floatHH = 800f;//set height to 800f here floatWW = 480f;//This sets the width to 480f//scaling ratio. Because it is a fixed scale, only one of the data with high or wide is calculated intbe = 1;//be=1 indicates no scaling if(W > H && w > WW) {//If the width is large, scale according to the fixed width sizebe = (int) (Newopts.outwidth/ww); } Else if(W < h && h > hh) {//if height is high, it is scaled according to width fixed sizebe = (int) (Newopts.outheight/hh); } if(Be <= 0) be= 1; Newopts.insamplesize= be;//set the zoom ratio//re-read the picture and note that the Options.injustdecodebounds has been set back to false at this timeBitmap =bitmapfactory.decodefile (Srcpath, newopts); returnCompressimage (bitmap);//compress the proportions and then compress the mass.}
This is written by the great God of the script house to worship.
Big God Link: http://www.jb51.net/article/41117.htm
Android image Compression