What about the getsupportedpreviewsizes and getsupportedpicturesizes functions in the Android low version SDK?

Source: Internet
Author: User

When doing camera and Surfaceview to do webcam program, need to get camera support photo size, in the lower version of the SDK does not have getsupportedpicturesizes function, what to do, see the following key code:

1. Define Size class

 Public classSize {/** * Sets the dimensions for pictures. * * @param w the photo width (pixels) * @param h the photo height (pixels)*/     PublicSize (intWinth) {width=W; Height=h; }    /** * compares {@code obj} to this size.     * * @param obj The object to compare this size with. * @return {@code true} if the width and height of {@code obj} are the * Same as those of this size.     {@code false} otherwise. */@Override Publicboolean equals (Object obj) {if(!(obj instanceof Size)) {            return false; } Size S=(Size) obj; returnwidth = = S.width && height = =S.height; } @Override Public inthashcode () {returnWidth *32713+height; }    /** * Width of the picture*/     Public intwidth; /** * Height of the picture*/     Public intheight;}

2. Define Camerahelper Class

Import Java.util.arraylist;import Java.util.list;import java.util.stringtokenizer;import Android.hardware.Camera; Public classCamerahelper {Private StaticFinal String key_preview_size ="preview-size"; Private StaticFinal String key_picture_size ="picture-size"; Private StaticFinal String Supported_values_suffix ="-values"; Privatecamera.parameters mparms;  PublicCamerahelper (camera.parameters parm) { This. mparms =Parm; }     PublicList<size>getsupportedpreviewsizes () {String str= Mparms.Get(Key_preview_size +Supported_values_suffix); returnsplitsize (str); }     PublicList<size>getsupportedpicturesizes () {String str= Mparms.Get(Key_picture_size +Supported_values_suffix); returnsplitsize (str); }            PrivateArraylist<size>splitsize (String str) {if(str = =NULL)            return NULL; StringTokenizer Tokenizer=NewStringTokenizer (str,","); ArrayList<Size> sizelist =NewArraylist<size>();  while(Tokenizer.hasmoreelements ()) {Size size=strtosize (Tokenizer.nexttoken ()); if(Size! =NULL) sizelist.add (size); }        if(sizelist.size () = =0)            return NULL; returnsizelist; }    PrivateSize strtosize (String str) {if(str = =NULL)            return NULL; intpos = Str.indexof ('x'); if(POS! =-1) {String width= Str.substring (0, POS); String Height= str.substring (pos +1); return NewSize (Integer.parseint (width), integer.parseint (height)); }        return NULL; }}

In fact, mainly through the camera.parameters get method, and then parse the obtained string to replace those non-existent API.

What about the getsupportedpreviewsizes and getsupportedpicturesizes functions in the Android low version SDK?

Related Article

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.