Name DataType Subtype Length LocalImage DotNet System.Drawing.Image.'System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' LocalImageFormat DotNet System.Drawing.Imaging.ImageFormat.'System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' Bitmap DotNet System.Drawing.Bitmap.'System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' Graphics DotNet System.Drawing.Graphics.'System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' Brushes DotNet System.Drawing.Brushes.'System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' InStr InStream
GlobalTempPicture.DELETEALL; Bitmap := Bitmap.Bitmap(300,50); LocalImage := Bitmap; Graphics := Graphics.FromImage(LocalImage); //This line fails - I don;'t know why Graphics.FillRectangle(Brushes.Green,0,0,300,50); GlobalTempPicture.Picture.CREATEINSTREAM(InStr); LocalImage.Save(InStr,LocalImageFormat.Jpeg); GlobalTempPicture.INSERT;
CLEAR(Item); Item.DELETEALL; Bitmap := Bitmap.Bitmap(300,50); Graphics := Graphics.FromImage(Bitmap); SolidBrush := SolidBrush.SolidBrush(Color.Green); Graphics.FillRectangle(SolidBrush,0,0,300,50); Item.Picture.CREATEINSTREAM(InputStream); Bitmap.Save(InputStream,ImageFormat.Jpeg); Item.INSERT;
Color DotNet System.Drawing.Color.'System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' SolidBrush DotNet System.Drawing.SolidBrush.'System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
Answers
Franz Kalchmair, MVP
Alias: Jonathan Archer
please like / agree / verify my answer, if it was helpful for you. thx.
Blog: http://moxie4nav.wordpress.com/
Hope, it helps
Oki
Equivalent code works well in C# but this C/SIDE code fails after the first two successful runs. I don't know why.
My test do show though that it sometimes crashes on the first pass.
I will keep testing various options to see if I can get something working.
A comment in this article led me to the answer.
The reason it fails is because the brush (in this case a system-defined brush) gets disposed after the first run. This means that Brushes.Green now refers to null and null is not an acceptable parameter for FillRectangle.
The following code works:
Variables are the same as you use with these added:
kaspermoerch - I would be interested to understand how you figured out that the Brushes was being disposed but that is probably a different discussion!
Many thanks for spending your time looking at this.