public WebcamConfig() { volta: string path = System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); path += @"\Agecom Soluções\Totem\user.config"; ExeConfigurationFileMap configMap = new ExeConfigurationFileMap(); configMap.ExeConfigFilename = path; try { config = ConfigurationManager.OpenMappedExeConfiguration(configMap, ConfigurationUserLevel.None); config_allkeys = config.AppSettings.Settings.AllKeys; } catch { try { System.IO.File.Delete(path); goto volta; } catch { } } WebcamName = config_ler_valor("WebcamName", "------"); string _Resolution = config_ler_valor("Resolution", "800x600"); if (_Resolution.ToUpper().Contains("X")) { Resolution = new Camera_NET.Resolution(Convert.ToInt32(_Resolution.ToUpper().Split('X')[0]), Convert.ToInt32(_Resolution.ToUpper().Split('X')[1])); } Focus = config_ler_valor("Focus", "Auto"); Zoom = Convert.ToInt32(config_ler_valor("Zoom", "100")); Exposure = Convert.ToInt32(config_ler_valor("Exposure", "0")); Brightness = Convert.ToInt32(config_ler_valor("Brightness", "0")); Contrast = Convert.ToInt32(config_ler_valor("Contrast", "0")); BacklightCompensation = Convert.ToInt32(config_ler_valor("BacklightCompensation", "0")); Gain = Convert.ToInt32(config_ler_valor("Gain", "0")); Gamma = Convert.ToInt32(config_ler_valor("Gamma", "0")); }
private static void SetSourceParams(IPin pinSourceCapture, Camera_NET.Resolution resolution_desired) { AMMediaType pmt = null; AMMediaType ppmt = null; IntPtr zero = IntPtr.Zero; bool flag = false; try { IAMStreamConfig config = pinSourceCapture as IAMStreamConfig; DsError.ThrowExceptionForHR(config.SetFormat(null)); int piCount = 0; int piSize = 0; DsError.ThrowExceptionForHR(config.GetNumberOfCapabilities(out piCount, out piSize)); for (int i = 0; i < piCount; i++) { zero = Marshal.AllocCoTaskMem(piSize); config.GetStreamCaps(i, out ppmt, zero); FreeSCCMemory(ref zero); bool flag2 = false; bool flag3 = false; bool flag4 = false; AnalyzeMediaType(ppmt, resolution_desired, out flag2, out flag3, out flag4); if (flag2 && flag4) { if (flag3) { DsError.ThrowExceptionForHR(config.SetFormat(ppmt)); flag = true; break; } if (pmt == null) { pmt = ppmt; ppmt = null; } } FreeMediaType(ref ppmt); } if (!flag) { if (pmt == null) { throw new Exception("Camera doesn't support media type with requested resolution and bits per pixel."); } DsError.ThrowExceptionForHR(config.SetFormat(pmt)); } } catch { throw; } finally { FreeMediaType(ref ppmt); FreeMediaType(ref pmt); FreeSCCMemory(ref zero); } }
private static void AnalyzeMediaType(AMMediaType media_type, Camera_NET.Resolution resolution_desired, out bool bit_count_ok, out bool sub_type_ok, out bool resolution_ok) { short bitCountForMediaType = GetBitCountForMediaType(media_type); bit_count_ok = IsBitCountAppropriate(bitCountForMediaType); sub_type_ok = ((((media_type.subType == MediaSubType.RGB32) || (media_type.subType == MediaSubType.ARGB32)) || ((media_type.subType == MediaSubType.RGB24) || (media_type.subType == MediaSubType.RGB16_D3D_DX9_RT))) || (media_type.subType == MediaSubType.RGB16_D3D_DX7_RT)) || (media_type.subType == MediaSubType.YUY2); resolution_ok = IsResolutionAppropiate(media_type, resolution_desired); }
private void PostActions_Renderer() { int num2; int num3; int num4; int num5; DsError.ThrowExceptionForHR(this.DX.WindowlessCtrl.GetNativeVideoSize(out num2, out num3, out num4, out num5)); this._Resolution = new Camera_NET.Resolution(num2, num3); this.DX.MixerBitmap = (IVMRMixerBitmap9)this.DX.VMRenderer; }
private static bool IsResolutionAppropiate(AMMediaType media_type, Camera_NET.Resolution resolution_desired) { if (resolution_desired != null) { VideoInfoHeader structure = new VideoInfoHeader(); Marshal.PtrToStructure(media_type.formatPtr, structure); if ((resolution_desired.Width > 0) && (structure.BmiHeader.Width != resolution_desired.Width)) { return(false); } if ((resolution_desired.Height > 0) && (structure.BmiHeader.Height != resolution_desired.Height)) { return(false); } } return(true); }
public void SetCamera(IMoniker moniker, Camera_NET.Resolution resolution) { this.CloseCamera(); if (moniker != null) { this._Camera = new Camera_NET.Camera(); if (!string.IsNullOrEmpty(this._DirectShowLogFilepath)) { this._Camera.DirectShowLogFilepath = this._DirectShowLogFilepath; } if (resolution != null) { this._Camera.Resolution = resolution; } this._Camera.Initialize(this, moniker); this._Camera.BuildGraph(); this._Camera.RunGraph(); this._Camera.OutputVideoSizeChanged += new EventHandler(this.Camera_OutputVideoSizeChanged); } }