添加图像版权信息

private void btnOpenFile_Click(object sender, System.EventArgs e)

        {

            //Stream myStream;

            OpenFileDialog openFileDialog1 = new OpenFileDialog();

 

            openFileDialog1.InitialDirectory = "c://" ;

            openFileDialog1.Filter= "All files (*.*)|*.*";

            openFileDialog1.FilterIndex = 2 ;

            openFileDialog1.RestoreDirectory = true ;

 

            if(openFileDialog1.ShowDialog() == DialogResult.OK)

            {

                originalimage = System.Drawing.Image.FromFile(openFileDialog1.FileName.ToString());

                Image ithumbnail = originalimage.GetThumbnailImage(200, 200, null, new IntPtr());

                pictureBox1.Image=ithumbnail;

                btnAddCopyright.Enabled = true;

            }

        }

 

        private void btnAddCopyright_Click(object sender, System.EventArgs e)

        {

            int imagewidth;

            int imageheight;

            int fontsize=300;

            int x,y;

            int a,re,gr,bl,x1,y1,z1;

            int size;

            Bitmap pattern;

            SizeF sizeofstring;

            bool foundfont;    

            imagewidth=originalimage.Width;

            imageheight=originalimage.Height;

            size=imagewidth*imageheight;

            pattern = new Bitmap(imagewidth,imageheight);

            Bitmap temp = new Bitmap(originalimage);

            Graphics g = Graphics.FromImage(pattern);

            Graphics tempg =Graphics.FromImage(originalimage);

            //find a font size that will fit in the bitmap

            foundfont=false;

            g.Clear(Color.White);

            while(foundfont==false)

            {

                Font fc = new Font("Georgia", fontsize, System.Drawing.FontStyle.Bold);

             

                sizeofstring=new SizeF(imagewidth,imageheight);

                sizeofstring=g.MeasureString("DOTNET",fc);

                if (sizeofstring.Width<pattern.Width)

                {

                    if (sizeofstring.Height<pattern.Height)

                    {

                        foundfont=true;

                        g.DrawString("DOTNET", fc, new SolidBrush(Color.Black),1,1);

                    }

 

                }

                else

                    fontsize=fontsize-1;        

            }

            MessageBox.Show("已创建新文件","给图像添加版权信息");

            for(x=1;x<pattern.Width;x++)

            {

                for(y=1;y<pattern.Height;y++)//

                {

                    if (pattern.GetPixel(x,y).ToArgb()==Color.Black.ToArgb())

                    {

                        a=temp.GetPixel(x,y).A;

                        re=temp.GetPixel(x,y).R;

                        gr=temp.GetPixel(x,y).G;

                        bl=temp.GetPixel(x,y).B;

                                         

                        x1=re;

                        y1=gr;

                        z1=bl;                  

                    

                        if (bl+25<255)

                            bl=bl+25;               

                        if (gr+25<255)

                            gr=gr+25;                  

                        if (re+25<255)

                            re=re+25;

                        if (x1-25>0)

                            x1=x1-25;               

                        if (y1-25>0)

                            y1=y1-25;                  

                        if (z1-25>0)

                            z1=z1-25;        

                    

                        tempg.DrawEllipse(new Pen(new SolidBrush(Color.Black)),x,y+1,3,3);

                        tempg.DrawEllipse(new Pen(new SolidBrush(Color.FromArgb(a,x1,y1,z1))),x,y,1,1);

                    }             

                }   

            }

            MessageBox.Show("输出文件是c://output.jpeg","给图像添加版权信息");

            tempg.Save();

            originalimage.Save("c://output.jpeg",ImageFormat.Jpeg);

        }

    }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值