In recent years, with the country advocating the establishment of a resource-saving and environmentally friendly society, people have been pursuing a green and healthy quality of life. The non-toxic, harmless, and biodegradable characteristics of grass and wood dyeing have brought this method back to people's lives. Despite the presence of antibacterial substances such as tetrahydrocannabinol in cannabis fibers, they are still susceptible to microbial attacks. In recent years, scholars have conducted more research on the separation and purification of gardenia flower pigments, but there has been less analysis on the dyeing fibers and performance testing of gardenia flowers. The renewable characteristics, fewer side effects, and low cost increase the use of natural drugs as antibacterial agents in plant extracts or their active ingredients. This experiment used gardenia flowers as the raw material for dyeing experiments, and the dyeing percentage was used as the inspection index. Ultrasonic dyeing was carried out on hemp fibers after degumming treatment. It also aims to endow these dyed fabrics with natural antibacterial properties. During the sorting process, a liquid bath ratio of 1:20 was selected and experiments were conducted under different parameter variations. During the dyeing process, potassium aluminum sulfate (alum) is used as a mordant, and ultrasound is used as an auxiliary dyeing method. After dyeing, evaluate the fibers based on the percentage of exhaustion of obtained fiber and antibacterial activity against Staphylococcus aureus and Escherichia coli. At the same time, the FT-IR analysis, strength, and color fastness of the sorted samples were also checked. Single factor experiments were conducted by controlling the ultrasonic frequency, dyeing temperature, time, and mordant concentration to analyze the effect of gardenia pigment on the dyeing percentage. Response surface design experiments were used to optimize the dyeing process parameters. The research results indicate that the optimal process conditions for dyeing gardenia flowers are ultrasonic power of 85 %, dyeing temperature of 77 ℃, dyeing time of 60 min, and mordant concentration of 15 g/L. The main and secondary order of factors affecting the dyeing effect of hemp fibers is: mordant concentration>ultrasonic power>dyeing temperature. After optimal dyeing process, the hemp fiber shows a bright yellow color with a dyeing percentage of 57.32 %. The single fiber strength is not affected, and the color fastness to water washing and sun exposure meets the requirements for consumption. The infrared spectrum shows good dyeing effect. It has a certain antibacterial effect on Staphylococcus aureus, but the antibacterial effect on Escherichia coli is not significant. Due to these processes, it has been determined that hemp fiber can obtain antibacterial activity through the use of gardenia flowers and can be effectively colored.