`

添加图像版权信息

阅读更多

privatevoidbtnOpenFile_Click(objectsender, System.EventArgse)

{

//Stream myStream;

OpenFileDialogopenFileDialog1 =newOpenFileDialog();

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());

Imageithumbnail = originalimage.GetThumbnailImage(200, 200,null,newIntPtr());

pictureBox1.Image=ithumbnail;

btnAddCopyright.Enabled =true;

}

}

privatevoidbtnAddCopyright_Click(objectsender, System.EventArgse)

{

intimagewidth;

intimageheight;

intfontsize=300;

intx,y;

inta,re,gr,bl,x1,y1,z1;

intsize;

Bitmappattern;

SizeFsizeofstring;

boolfoundfont;

imagewidth=originalimage.Width;

imageheight=originalimage.Height;

size=imagewidth*imageheight;

pattern =newBitmap(imagewidth,imageheight);

Bitmaptemp =newBitmap(originalimage);

Graphicsg =Graphics.FromImage(pattern);

Graphicstempg =Graphics.FromImage(originalimage);

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

foundfont=false;

g.Clear(Color.White);

while(foundfont==false)

{

Fontfc =newFont("Georgia", fontsize, System.Drawing.FontStyle.Bold);

sizeofstring=newSizeF(imagewidth,imageheight);

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

if(sizeofstring.Width<pattern.Width)

{

if(sizeofstring.Height<pattern.Height)

{

foundfont=true;

g.DrawString("DOTNET", fc,newSolidBrush(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(newPen(newSolidBrush(Color.Black)),x,y+1,3,3);

tempg.DrawEllipse(newPen(newSolidBrush(Color.FromArgb(a,x1,y1,z1))),x,y,1,1);

}

}

}

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

tempg.Save();

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

}

}

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics