我是c楼#接触管理的桌面应用程序,在这里你可以选择一个虚拟形象的图像,从文件和后来的作物。 原来像是正确的显示之后作,取代了原来的一个。 然而,后来,在尝试注册的帐户出现的图像是无这样的一个错误,正在显示:
系统。基础:"价值不能为空。 (参数 '编码')"
方法上传镜像到登记页面:
private void button_browse_Click(object sender, EventArgs e)
{
// select and display image in the picturebox
OpenFileDialog opf = new OpenFileDialog();
opf.Filter = "Select Image(*.jpg;*.png;*.gif)|*.jpg;*.png;*.gif";
if(opf.ShowDialog() == DialogResult.OK)
{
pictureBoxProfileImage.Image = Image.FromFile(opf.FileName);
setImage(pictureBoxProfileImage.Image);
}
}
该方法的剪切图片:
private void button_Select_Cropped_Area_Click(object sender, EventArgs e)
{
Cursor = Cursors.Default;
Bitmap bitmap2 = new Bitmap(pictureBoxProfileImage.Width, pictureBoxProfileImage.Height);
pictureBoxProfileImage.DrawToBitmap(bitmap2, pictureBoxProfileImage.ClientRectangle);
Bitmap croppedImage = new Bitmap(rectW, rectH);
for (int x = 0; x < rectW; x++)
{
for (int y = 0; y < rectH; y++)
{
Color pxlColor = bitmap2.GetPixel(cropX + x, cropY + y);
croppedImage.SetPixel(x, y, pxlColor);
}
}
pictureBoxProfileImage.Image.Dispose();
pictureBoxProfileImage.Image = (Image)croppedImage;
pictureBoxProfileImage.SizeMode = PictureBoxSizeMode.StretchImage;
}
这里的线路发生错误的时候救的形象:
MemoryStream picture = new MemoryStream();
pictureBoxProfileImage.Image.Save(picture, pictureBoxProfileImage.Image.RawFormat);
值得一提的是,登记册的工作正确,如果原始图像正在被传递。 我应该替换他们以某种方式(复盖原始一个与裁剪一种)?