38 const FGeometry CanvasGeometry =
Image_Canvas->GetCachedGeometry();
39 if (!CanvasGeometry.IsUnderLocation(InMouseEvent.GetScreenSpacePosition()))
41 return FReply::Unhandled();
51 if (InMouseEvent.IsMouseButtonDown(EKeys::LeftMouseButton))
55 else if (InMouseEvent.IsMouseButtonDown(EKeys::RightMouseButton))
60 return FReply::Handled();
76 if (!
bIsDrawing)
return Super::NativeOnMouseMove(InGeometry, InMouseEvent);
78 if (InMouseEvent.IsMouseButtonDown(EKeys::LeftMouseButton))
82 else if (InMouseEvent.IsMouseButtonDown(EKeys::RightMouseButton))
87 return FReply::Handled();
93 UCanvas* canvas =
nullptr;
95 FDrawToRenderTargetContext context;
96 UKismetRenderingLibrary::BeginDrawCanvasToRenderTarget(
this,
RT_Canvas, canvas, size, context);
99 float thickness = (drawColor == FLinearColor::Black) ? 10 : 30;
101 canvas->K2_DrawBox(mousePos, FVector2D(1, 1), thickness, drawColor);
103 UKismetRenderingLibrary::EndDrawCanvasToRenderTarget(
this, context);
109 UCanvas* canvas =
nullptr;
111 FDrawToRenderTargetContext context;
112 UKismetRenderingLibrary::BeginDrawCanvasToRenderTarget(
this,
RT_Canvas, canvas, size, context);
117 FVector2D drawOffset = (mousePos - currPos) / div;
120 for (int32 i = 1; i < div; ++i)
125 float thickness = (drawColor == FLinearColor::Black) ? 10 : 30;
127 canvas->K2_DrawLine(
prevMousePos, currPos, thickness, drawColor);
131 UKismetRenderingLibrary::EndDrawCanvasToRenderTarget(
this, context);
170 FTextureRenderTargetResource* RTResource = RenderTarget->GameThread_GetRenderTargetResource();
177 const int32 Width = RenderTarget->SizeX;
178 const int32 Height = RenderTarget->SizeY;
181 TArray<FColor> Bitmap;
182 Bitmap.AddUninitialized(Width * Height);
185 RTResource->ReadPixels(Bitmap);
188 IImageWrapperModule& ImageWrapperModule =
189 FModuleManager::LoadModuleChecked<IImageWrapperModule>(
"ImageWrapper");
191 TSharedPtr<IImageWrapper> ImageWrapper =
192 ImageWrapperModule.CreateImageWrapper(EImageFormat::PNG);
194 if (!ImageWrapper.IsValid())
199 ImageWrapper->SetRaw(
201 Bitmap.GetAllocatedSize(),
209 const TArray64<uint8>& PNGData = ImageWrapper->GetCompressed(100);
212 const FString Directory = FPaths::GetPath(FullFilePath);
213 IFileManager::Get().MakeDirectory(*Directory,
true);
215 return FFileHelper::SaveArrayToFile(PNGData, *FullFilePath);