2

I am trying to write an image/png in an ESRI FileGDB field.

I use the Esri.FileGDB.API 1.4, both 32/64, in C#.

The type of the field is "esriFieldTypeBlob".

I am currently able to write the image, without errors, as follows:

Table table = gdb.OpenTable(tablename);
Row newRow = table.CreateRowObject();
byte[] fba = null;
System.Drawing.Image img = System.Drawing.Image.FromFile(imgpath);
using (MemoryStream ms = new MemoryStream()) {
    img.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
    fba = ms.ToArray();
}
ByteArray ba = new ByteArray((uint) fba.Length);
ba.byteArray = (byte[]) fba.Clone();
newRow.SetBinary(fieldname, ba);
table.Insert(newRow);

But when I re-read the field using GetBinary, the ByteArray is 0 length.

What am I doing wrong?

Has anyone had the same problem?

lele3p
  • 900
  • 1
  • 7
  • 14
  • Have you checked the contents of the FGDB row with Desktop? – Vince Mar 21 '17 at 10:38
  • Yes. The field is empty. – lele3p Mar 21 '17 at 12:55
  • Try adding a diagnostic print statement to check the input length. Is the "empty" field NULL or is a BLOB with length zero? – Vince Mar 21 '17 at 13:19
  • The field is not NULL. Is a BLOB with length zero. – lele3p Mar 22 '17 at 08:03
  • So the query results in the same value which was inserted? Please edit the question to reflect this information, and explain why this is a problem. – Vince Mar 22 '17 at 10:45
  • The query results is NOT the same value which was inserted. Value inserted: ByteArray with length of 76388. Value reread: ByteArray with length 0. This is the problem... – lele3p Mar 22 '17 at 12:49
  • Then edit the question to provide this information. I've read and written every supported datatype with the C++ API, so I don't think this is a common problem. The support mechanism is to post to GeoNet. – Vince Mar 22 '17 at 13:00

1 Answers1

1

When you populate the ByteArray with

ba.byteArray = (byte[]) fba.Clone();

the property ba.inUseLength remain 0.

To solve the problem you can set it manually :

ba.byteArray = (byte[]) fba.Clone();
ba.inUseLength = ba.allocatedLength;

With this workaround i can write and reread the blob field.

Lou Lou
  • 68
  • 6