C# - picturebox,graphics.DrawImage和picturebox.Image = null,为什么?

时间:2017-09-14 12:11:36

标签: c# winforms graphics picturebox

我试图在PictureBox1中裁剪并调整图片大小。我的代码:

//original image for eventually undo
undoImage = pictureBox1.BackgroundImage.Clone() as Image;
Bitmap sourceBitmap = new Bitmap(pictureBox1.BackgroundImage, pictureBox1.Width, pictureBox1.Height);
Graphics g = pictureBox2.CreateGraphics();
g.DrawImage(sourceBitmap, new Rectangle(0, 0, pictureBox2.Width, pictureBox2.Height), rectCropArea, GraphicsUnit.Pixel);
sourceBitmap.Dispose();

它在两个PictureBox es上正常工作。 但是PictureBox2.ImagePictureBox2.BackgroundImage(以及任何其他包括ErrorImage ...)= null。 我尝试了PictureBox.DrawToBitmap和其他广告,例如谷歌上发现的g.GetHdc(),但未成功。

我的问题:
如何将编辑过的图像从PictureBox2正确复制到PictureBox1

1 个答案:

答案 0 :(得分:-2)

琐碎的解决方案:

cross_entropy = tf.losses.log_loss(labels, predictions)