code: private VideoFormat getSizedVideoFormat(Dimension size) {
  
  		Format[] formats = device.getFormats();
  		VideoFormat format = null;
  
  		for (Format f : formats) {
  
  			if (!"RGB".equalsIgnoreCase(f.getEncoding()) || !(f instanceof VideoFormat)) {
  				continue;
  			}
  
  			Dimension d = ((VideoFormat) f).getSize();
  			if (d.width == size.width && d.height == size.height) {
  				format = (VideoFormat) f;
  				break;
  			}
  		}
  
  		return format;
  	}
docs: Get video format for size.
  
  @param device device to get format from
  @param size specific size to search
  @return VideoFormat