此代码未完全保存图像。似乎scrollLeft和scrollTop无法按要求工作。实际上,最终结果是一个jpg,其中保存了图片的左上角的帧,其余全部为黑色,如下所示:https://imgur.com/a/Cyfuz5a。请问如何改进/修复它?
public Bitmap GetEntireContent(RectangleF crop)
{
this.UpdateFromBrowser();
Bitmap bitmap = new Bitmap(this.screenWidth, this.screenHeight, PixelFormat.Format16bppRgb555);
Bitmap bitmap1 = new Bitmap(this.widthsize + this.URLExtraLeft - this.trimWidth, this.heightsize + this.URLExtraHeight - this.trimHeight, PixelFormat.Format16bppRgb555);
Graphics graphic = Graphics.FromImage(bitmap1);
Graphics graphic1 = null;
Image image = null;
int num = 0;
int num1 = 0;
int num2 = 0;
IntPtr handle = base.Handle;
handle.ToInt32();
IntPtr window = handle;
window = CaptureBrowser.GetWindow(window, 5);
StringBuilder stringBuilder = new StringBuilder(256);
try
{
while (num2 * this.screenHeight < this.heightsize)
{
int num3 = (this.screenHeight - 5) * num2;
this.myDoc.Body.SetAttribute("scrollTop", num3.ToString());
num2++;
}
num2--;
for (int i = 0; i * this.screenWidth < this.widthsize; i++)
{
int num4 = (this.screenWidth - 5) * i;
this.myDoc.Body.SetAttribute("scrollLeft", num4.ToString());
num1 = short.Parse(this.myDoc.Body.GetAttribute("scrollLeft"));
for (int j = num2; j >= 0; j--)
{
graphic1 = Graphics.FromImage(bitmap);
IntPtr hdc = graphic1.GetHdc();
int num5 = (this.screenHeight - 5) * j;
this.myDoc.Body.SetAttribute("scrollTop", num5.ToString());
num = short.Parse(this.myDoc.Body.GetAttribute("scrollTop"));
CaptureBrowser.PrintWindow(window, hdc, 0);
graphic1.ReleaseHdc(hdc);
graphic1.Flush();
image = Image.FromHbitmap(bitmap.GetHbitmap());
graphic.DrawImage(image, num1 + this.URLExtraLeft, num + this.URLExtraHeight);
}
}
}
finally
{
}
return bitmap1;
}