Although, there used to be the kind of photo album inside, and then, by cutting the picture to get their own desired picture, then for if you want a batch of pictures of the processing effect, then, relative to the cut, we automatically in the code to achieve the proportion of the image we want to cut. Then come to get the proportions of the picture you want.
In fact, this is the first to convert the picture to bitmap, and then put it into the byte, and then according to their own proportions to get the compression of the picture, finally get.
Here is the key code: Then the implementation of this method is okay:
//To define a method to make the image PublicBitmap Getbitmap (byte[] Data,intWidthintheight) {Bitmap Bitmap=NULL; Options opts=NewOptions (); Opts.injustdecodebounds=true; Opts.insamplesize= 2; Opts.injustdecodebounds=false; Bitmap= Bitmapfactory.decodebytearray (data, 0, Data.length, opts); returnbitmap; }
You'll see that you'll need a parameter here, which is a byte, and of course, this byte is the okay of the image you need to convert to this byte:
//First to change the bitmapResources res =getresources (); Bitmap BMP=Bitmapfactory.decoderesource (res, r.drawable.demo); //To get the byteBytearrayoutputstream BAOs =NewBytearrayoutputstream (); Bmp.compress (Bitmap.CompressFormat.PNG,100, BAOs); byte[] data =Baos.tobytearray (); Bitmap bit= Getbitmap (data, 300, 300); //To exchangeBitmapdrawable draw =Newbitmapdrawable (bit); Img_two.setbackground (draw);
The above is to change the image of a resource into bitmap form, and then in Byte, then 叜 call the previous conversion method, and then return a bitmap, and then use the corresponding control to get the okay.
Hope this is useful for everyone!