Ich habe SetDeviceGammaRamp API in einer Konsole C# -Anwendung und es hat gut funktioniert. Aber wenn das gleiche in einer universellen Windows-App verwendet wird Fehler "CS1620 Argument 2 muss mit dem 'ref' Schlüsselwort übergeben werden" erscheint.SetDeviceGammaRamp API-Nutzung in Universal Windows App
Meine Anforderung ist, Gamma-Wert mit einem Schieberegler zu ändern.
-Code-Bereich:
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using System.Runtime.InteropServices;
// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409
namespace Brightness
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class MainPage : Page
{
[DllImport("user32.dll")]
public static extern IntPtr GetDC(IntPtr hWnd);
[DllImport("gdi32.dll")]
public static extern bool SetDeviceGammaRamp(IntPtr hDC, ref RAMP lpRamp);
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public struct RAMP
{
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 256)]
public UInt16[] Red;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 256)]
public UInt16[] Green;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 256)]
public UInt16[] Blue;
}
public MainPage()
{
this.InitializeComponent();
}
public static void SetGamma(int gamma)
{
if (gamma <= 256 && gamma >= 1)
{
RAMP ramp = new RAMP();
ramp.Red = new ushort[256];
ramp.Green = new ushort[256];
ramp.Blue = new ushort[256];
for (int i = 1; i < 256; i++)
{
int iArrayValue = i * (gamma + 128);
if (iArrayValue > 65535)
{
iArrayValue = 65535;
}
ramp.Red[i] = ramp.Blue[i] = ramp.Green[i] = (ushort)iArrayValue;
}
SetDeviceGammaRamp(GetDC(IntPtr.Zero), ref ramp);
}
}
private void Slider_ValueChanged(object sender, RangeBaseValueChangedEventArgs e)
{
Slider slider = sender as Slider;
if (slider != null)
{
int p = (int)slider.Value;
SetGamma(p);
}
}
}
}
enter code here
Fehler: CS1620: Argument 2 muss mit dem 'ref' Stichwort
Ich bin neu in C# und Universal Windows-App übergeben werden. Bitte helfen.
Es gibt eine große Anzahl von älteren Winapi-Funktionen, die Sie nicht in einer UWP-App verwenden können. Alles von user32.dll und gdi32.dll ist tabu. Es gibt keine Alternative für SetDeviceGammaRamp(). –