Generates a tag cloud bitmap using weighted strings and customizable options for font size, color, background, and more.
TagCloudGenerator is available as Nuget Package now.
Below are some sample images showing the output of the TagCloudGenerator:
You can use the TagCloudGenerator library by following these steps:
-
Create a dictionary of strings and their corresponding weights. The weights can be set to the number of occurrences of each string.
Dictionary<string, float> tagDic = new Dictionary<string, float>(); tagDic["J.C.STAFF"] = 32;
-
Create a
TagCloudOption
object, and set its properties as needed.TagCloudOption tagCloudOption = new TagCloudOption(); // Set tagCloudOption properties // tagCloudOption.Xxx = xxx;
-
If you want to specify special settings for individual characters, create a dictionary of
TagOption
objects.Dictionary<string, TagOption> tagOptionDic = new Dictionary<string, TagOption>(); // Set option for single text // tagOptionDic["J.C.STAFF"] = new TagOption() { Rotate = new Rotate(0) };
-
Create a
TagCloud
object using the dictionaries and theTagCloudOption
object, and then call theGet()
method to generate the bitmap image.Bitmap bmp = new TagCloud(tagDic, tagCloudOption, tagOptionDic).Get();
If you don't need to specify special settings for individual characters, you can omit the
tagOptionDic
parameter:Bitmap bmp = new TagCloud(tagDic, tagCloudOption).Get();
The TagCloudOption
object allows you to customize various aspects of the tag cloud. Below is a list of its properties and their descriptions:
Property | Description |
---|---|
Range RandomRotateRange | If not null, take random values from RandomRotateRange |
List<int> RotateList | If RandomRotateRange is null, take rotate randomly from RotateList |
int TagSpacing | Minimum pixel spacing between adjacent tags |
int HorizontalOuterMargin | Minimum horizontal outer margin |
int VerticalOuterMargin | Minimum vertical outer margin |
List<Color> FontColorList | Set possible font colors for bitmap tags |
ColorOption BackgroundColor | Set background color for bitmap tags |
FontFamily FontFamily | Set font family for bitmap tags |
Range FontSizeRange | Set minimum and maximum font sizes |
double AngleStep | Set angle step for spiral algorithm |
double RadiusStep | Set radius step for spiral algorithm |
double AngleDecreaseFactor | Angle step decreasing factor |
double RadiusDecreaseFactor | Radius step decreasing factor |
bool IsRandomInitAngle | Set if is random init angle or not for spiral algorithm |
int HorizontalCanvasGrowthStep | Horizontal canvas growth step |
int VerticalCanvasGrowthStep | Vertical canvas growth step |
ImgSize OutputSize | Output bitmap image size |
ImgSize InitSize | Init bitmap image size, the canvas will grow when the canvas is filled |
string MaskPath | If you need to generate a tag cloud through masking, set the path for the masking image |
bool ShowMask | Set whether to display mask image in generated bitmap image |
bool StretchMask | Set whether to stretch the mask to match the canvas |
int Accuracy | Accuracy of TagSpacing check, default = 1, if =0 then check all pixel. It is used to increase operating efficiency |
The TagOption
object allows you to specify special settings for individual charactersin the tag cloud. Below is a list of its properties and their descriptions:
Property | Description |
---|---|
Rotate Rotate | Rotate of tag |
FontColor FontColor | FontColor of tag |
FontFamily FontFamily | FontFamily of tag |
This project is licensed under the OMSPL.