当前位置:首页 >> 跨学科知识体系 >> 【UE】UEC++获取屏幕颜色GetPixelFromCursorPosition(),eset nod32 antivirus 4

【UE】UEC++获取屏幕颜色GetPixelFromCursorPosition(),eset nod32 antivirus 4

cpugpu芯片开发光刻机 跨学科知识体系 1
文件名:【UE】UEC++获取屏幕颜色GetPixelFromCursorPosition(),eset nod32 antivirus 4 【UE】UEC++获取屏幕颜色GetPixelFromCursorPosition()

目录

【UE】UE C++ 获取屏幕颜色GetPixelFromCursorPosition()

一、函数声明与定义

二、函数的调用

三、运行结果


【UE】UE C++ 获取屏幕颜色GetPixelFromCursorPosition() 一、函数声明与定义

创建一个蓝图方法库方法 GetPixelFromCursorPosition(),并给他指定UFUNCTION(BlueprintCallable),这样就可以在蓝图里对函数做简单测试。

#pragma once#include "CoreMinimal.h"#include "Kismet/BlueprintFunctionLibrary.h"#include "ColorPickFunctionLibrary.generated.h"UCLASS()class COLORPICK_API UColorPickFunctionLibrary : public UBlueprintFunctionLibrary{GENERATED_BODY()public:UFUNCTION(BlueprintCallable)static FColor GetPixelFromCursorPosition();}; #include "ColorPickFunctionLibrary.h"#include "windows/AllowWindowsPlatformTypes.h"#include "WinUser.h"FColor UColorPickFunctionLibrary::GetPixelFromCursorPosition(){Windows::HDC hdc = ::GetDC(nullptr);POINT p;GetCursorPos(&p);COLORREF CursorPixel = ::GetPixel(hdc, p.x, p.y);::ReleaseDC(nullptr, hdc);return FColor(GetRValue(CursorPixel), GetGValue(CursorPixel), GetBValue(CursorPixel));} 二、函数的调用

为了检测获取的颜色,先准备一些文件:

1、UI

声明函数ShowColor(FLinearColor Color)来测试获取到的颜色。

2、Controller

说明一下,为了测试的方便,所以把创建UI这些操作全部都写在了Controller里面。

当点击鼠标左键的时候,就可以把从屏幕获取到的颜色,调用UI的ShowColor(FLinearColor Color)方法了。

三、运行结果

因为这次测试没有检测获取范围,所以全屏都可以获取颜色,实际开发的时候可以限制获取范围,只能在某个ColorBox范围内获取。

协助本站SEO优化一下,谢谢!
关键词不能为空
同类推荐
«    2025年12月    »
1234567
891011121314
15161718192021
22232425262728
293031
控制面板
您好,欢迎到访网站!
  查看权限
网站分类
搜索
最新留言
文章归档
网站收藏
友情链接