A generic error occurred in GDI+?

hsupowers

Client
Регистрация
26.12.2012
Сообщения
40
Благодарностей
3
Баллы
8
I run the C# in zenno:

HtmlElement he = instance.ActiveTab.FindElementByAttribute("body","fulltag","body","text",0);
int heHeight = Convert.ToInt32(he.GetAttribute("height"));
int heWidth = Convert.ToInt32(he.GetAttribute("width"));
int step =1000;
int countOfIterations = heHeight/step;
var bitmaps = new List<System.Drawing.Bitmap>();
int count =0;
for(int i =0;i<countOfIterations;i++)
{
var text = he.DrawPartToBitmap(0, i*step, heWidth, step, true);
byte[] imageBytes = Convert.FromBase64String(text);
var ms = new System.IO.MemoryStream(imageBytes, 0, imageBytes.Length);
var img = (System.Drawing.Bitmap)System.Drawing.Image.FromStream(ms);
img.Save(@"C:\images\part"+i.ToString()+@".jpg");
count++;
}
int lastPieceHeight = heHeight%step;
if (lastPieceHeight>10)
{
var text = he.DrawPartToBitmap(0, heHeight-lastPieceHeight, heWidth, lastPieceHeight, true);
byte[] imageBytes = Convert.FromBase64String(text);
var ms = new System.IO.MemoryStream(imageBytes, 0, imageBytes.Length);
var img = (System.Drawing.Bitmap)System.Drawing.Image.FromStream(ms);
img.Save(@"C:\images\part"+count.ToString()+@".jpg");
}

but show error:

A generic error occurred in GDI+.

What happened? thank you
 

Hungry Bulldozer

Moderator
Регистрация
12.01.2011
Сообщения
3 441
Благодарностей
834
Баллы
113
try img.Dispose(); before img.Save and after

so

img.Dispose();
img.Save(@"C:\images\part"+count.ToString()+@".jpg ");
img.Dispose();
 

hsupowers

Client
Регистрация
26.12.2012
Сообщения
40
Благодарностей
3
Баллы
8

Кто просматривает тему: (Всего: 1, Пользователи: 0, Гости: 1)