简体   繁体   English

如何在 Flutter 中的图像上添加水印文本?

[英]How can i add watermark text over image in Flutter?

I am trying to add watermark text over the image.我正在尝试在图像上添加水印文本。 I am able to set Single text to image but i don't know how to repeat watermark text like below Image.我可以将单个文本设置为图像,但我不知道如何像下面的图像一样重复水印文本。

在此处输入图像描述

Code block:代码块:


    Container(           
    child: ColorFiltered(      
    colorFilter: 
    ColorFilter.matrix(filters[index]),
     child: Stack(children: [
    Image.file(widget.editedImage,
    filterQuality: FilterQuality.high),
         Positioned(        
                top: yPosition,
                left: xPosition,
                child: GestureDetector(
                    onPanUpdate: (tapInfo) {
                      setState(() {
                        xPosition += tapInfo.delta.dx;
                        yPosition += tapInfo.delta.dy;           
                      });          
                    },           
            child: Container(    
                 alignment: Alignment.center,  
                 child: Text(            
                    'Confidential',     
                style: TextStyle(            
                  fontWeight: FontWeight.bold,        
                  fontSize: 20,      
                 color: Colors.grey[600])),
    ),),)                     
    ])),                
    ),             
    ),            
    );

The best solution is to make those 'confidential' watermark text as an image and place it as background using stack.最好的解决方案是将那些“机密”水印文本制作成图像并使用堆栈将其放置为背景。

Here is your solution,这是您的解决方案,

return Stack(
          children: [
            Material(
              child: Container(
                color: Colors.white,
                child: SingleChildScrollView(
                  child: Column(
                    children: [
                      for(var i=0;i<=10;i++)
                        SingleChildScrollView(
                          scrollDirection: Axis.horizontal,
                          child: Row(
                            children: [
                              for(var i=0;i<=5;i++)
                                Padding(
                                  padding: EdgeInsets.symmetric(vertical: 50 ,horizontal: 20),
                                  child: Transform.rotate(
                                    angle: -51,
                                    child: Text('CONFIDENTIAL', style: TextStyle(fontSize: 16, color: Colors.grey),),
                                  ),
                                )
                            ],
                          ),
                        )
                    ],
                  ),
                ),
              ),
            ),

            Scaffold(
              backgroundColor: Colors.transparent,
              appBar: AppBar(
                backgroundColor: Colors.black.withOpacity(0.6),
                elevation: 0,
              ),
              body: Center(
                child: Text('Welcome', style: Theme.of(context).textTheme.headline2,),
              ),
            ),
          ],
        );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM