(39) 's Extra Blueprint Nodes for You as a Plugin, No C++ Required!

Save Linear Color Array To Disk as PNG Image!

Live as of 4/27/15

Dear Community,

I’ve created a new node that allows you to save a Linear Color array to disk as a PNG image!

So you can draw transparency using the Alpha channel of the Linear Color!

For those who have not used Linear Color much, it has 4 floats (R G B A) and so saving to PNG and supporting transparency is easy!


**Bonus ~ I create target directory for you!**

My node will create the directory you are trying to save to if it does not already exist!

 can be very helpful if you delete your whole generated image folder at once!

Absolute File Paths

node receives absolute file paths, you can use my Path nodes to get various absolute paths that are relative to your project directory!

Victory BP Library Path Nodes (link inside thread)


**Error String**

I provide you with an Error string to help narrow down the reason the node returned false, if it does! 

Even more debugging info for you!

**The most common error will be that your array size does not equal Width x Height** that you inputted into the node.

Solution:

**You can avoid  by using variables for Width and Height** and multiplying them together and using that as the  for the for loop where you initialize the image to black (see picture above)!

If you use my method, make sure the for loop first index is 1 not 0 !

Post Your BP-Generated Images!

Feel free to post images you create using node!


**My C++ Code For You!**

Here's the entire C++ code for my node! 

If you use it please credit me somewhere appropriate!



```


bool UVictoryBPFunctionLibrary::Victory_SavePixels(const FString& FullFilePath,int32 Width, int32 Height, const TArray<FLinearColor>& ImagePixels, FString& ErrorString)
{
	if(FullFilePath.Len() < 1) 
	{
		ErrorString = "No file path";
		return false;
	}
	//~~~~~~~~~~~~~~~~~
	
	//Ensure target directory exists, 
	//		_or can be created!_ <3 
	FString NewAbsoluteFolderPath = FPaths::GetPath(FullFilePath);
	FPaths::NormalizeDirectoryName(NewAbsoluteFolderPath);
	if(!VCreateDirectory(NewAbsoluteFolderPath)) 
	{
		ErrorString = "Folder could not be created, check read/write permissions~ " + NewAbsoluteFolderPath;
		return false;
	}
	
	//Create FColor version
	TArray<FColor> ColorArray;
	for(const FLinearColor& Each : ImagePixels)
	{
		ColorArray.Add(Each);
	}
	 
	if(ColorArray.Num() != Width * Height) 
	{
		ErrorString = "Error ~ height x width is not equal to the total pixel array length!";
		return false;
	}
	  
	//Remove any supplied file extension and/or add accurate one
	FString FinalFilename = FPaths::GetBaseFilename(FullFilePath, false) + ".png";  //false = dont remove path

	//~~~
	
	TArray<uint8> CompressedPNG;
	FImageUtils::CompressImageArray( 
		Width, 
		Height, 
		ColorArray, 
		CompressedPNG
	);
	    
	ErrorString = "Success! or if returning false, the saving of file to disk did not succeed for File IO reasons";
	return FFileHelper::SaveArrayToFile(CompressedPNG, *FinalFilename);
}


```


Most Recent Plugin Download From UE4 Wiki

:slight_smile: