UE4获取鼠标位置的像素颜色

1.创建一个BlueprintFunctionLibrary类型的C++类,命名为MyBlueprintFunctionLibrary。
2…h的代码如下:

#pragma once

#include "CoreMinimal.h"
#include "Kismet/BlueprintFunctionLibrary.h"
#include "MyBlueprintFunctionLibrary.generated.h"

/**
 * 
 */
UCLASS()
class BYKERMAP_API UMyBlueprintFunctionLibrary : public UBlueprintFunctionLibrary
{
	GENERATED_BODY()

public:
	
	UFUNCTION(BlueprintCallable, Category = "WJX|Tools")
		static FColor NowMousePointColor();
	
	
	
	
};

3…cpp的代码如下:

#include "MyBlueprintFunctionLibrary.h"
#include "AllowWindowsPlatformTypes.h"
#include <shellapi.h>
#include "HideWindowsPlatformTypes.h"
FColor UMyBlueprintFunctionLibrary::NowMousePointColor()
{
	HDC hDC = ::GetDC(NULL);
	/*CPoint pt;*/
	POINT pt1;
	GetCursorPos(&pt1);
	COLORREF clr = ::GetPixel(hDC, pt1.x, pt1.y);
	int R = GetRValue(clr);
	int G = GetGValue(clr);
	int B = GetBValue(clr);
	::ReleaseDC(NULL, hDC);

	FColor Color;
	Color.R = R;
	Color.G = G;
	Color.B = B;
	Color.A = 255;
	return Color;

}

4.测试:
在这里插入图片描述
在这里插入图片描述


版权声明:本文为Solieyagai15409原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。