Code example for YuvImage

Methods: compressToJpeggetHeightgetWidth

1
    
     
     
    public static File cropYuv(YuvImage origYuv, int targetSize, Context ctx) {
    	 
    	int w = origYuv.getWidth();
    	int h = origYuv.getHeight();
    	 
    	int left   = (int)(targetSize >= w ? 0 : (float)( (w-targetSize)/2 ) );
    	int right  = (int)(targetSize >= w ? w : (float)( (w-targetSize)/2 ) + targetSize);
    	int top    = (int)(targetSize >= h ? 0 : (float)( (h-targetSize)/2 ) );
    	int bottom = (int)(targetSize >= h ? h : (float)( (h-targetSize)/2 ) + targetSize);
    	 
    	File dir = ctx.getDir("snapshots", Context.MODE_PRIVATE);
        File of = new File(dir, "snapshot.jpg");
        try { 
            FileOutputStream fo = new FileOutputStream(of);
             
            try { 
                origYuv.compressToJpeg(new Rect(left, top, right, bottom), 80, fo);
            }finally { 
                fo.close();
            } 
             
        }catch (IOException e) {	
Connect your IDE to all the code out there  Get Codota for Java