Posted on 2007-06-27 15:17
济公 阅读(832)
评论(3) 编辑 收藏 引用 所属分类:
WebService
[WebMethod]
public byte[] GetImage(string filename)
{
System.Drawing.Bitmap myBitmap;
System.Drawing.Bitmap box;
System.IO.MemoryStream stream;
stream=new System.IO.MemoryStream();
try
{
myBitmap=new System.Drawing.Bitmap(filename);
box=new Bitmap(filename);
Color c1=new Color();
Color c2=new Color();
Color c3=new Color();
Color c4=new Color();
Color c5=new Color();
Color c6=new Color();
Color c7=new Color();
Color c8=new Color();
Color c9=new Color();
int r1,r2,r3,r4,r5,r6,r7,r8,r9,fxr,rr;
//Bitmap box1=new Bitmap(pictureBox1.Image);
//Bitmap box2=new Bitmap(pictureBox1.Image);
for(int i=1;i<myBitmap.Width-2;i++)
{
for(int j=1;j<myBitmap.Height-2;j++)
{
c1=myBitmap.GetPixel(i,j-1);
c2=myBitmap.GetPixel(i-1,j);
c3=myBitmap.GetPixel(i,j);
c4=myBitmap.GetPixel(i+1,j);
c5=myBitmap.GetPixel(i,j+1);
c6=myBitmap.GetPixel(i-1,j-1);
c7=myBitmap.GetPixel(i-1,j+1);
c8=myBitmap.GetPixel(i+1,j-1);
c9=myBitmap.GetPixel(i+1,j+1);
r1=c1.R;
r2=c2.R;
r3=c2.R;
r4=c4.R;
r5=c5.R;
r6=c6.R;
r7=c7.R;
r8=c8.R;
r9=c9.R;
fxr=8*r3-r1-r2-r4-r5-r6-r7-r8-r9;
rr=Math.Abs(fxr);
if(rr<0) rr=0;
if(rr>255) rr=255;
Color cc=Color.FromArgb(rr,rr,rr);
box.SetPixel(i,j,cc);
}
//pictureBox2.Refresh();
//pictureBox2.Image=box2;
}
box.Save(stream,System.Drawing.Imaging.ImageFormat.Bmp);
return stream.ToArray();
}
catch(Exception err)
{
return null;
}
}
客户端代码
private void button1_Click(object sender, System.EventArgs e)
{
localhost1.Service1 serv;
byte[] bytes;
System.IO.MemoryStream stream;
Bitmap image;
serv=new localhost1.Service1();
bytes=serv.GetImage(textBox1.Text);
if(bytes!=null)
{
stream=new System.IO.MemoryStream(bytes);
image=new Bitmap(stream);
pictureBox1.Image=image;
}
else
{
MessageBox.Show("no image returned");
}
}