Currently I´m still on Nav2009R2 classic using a C# library with COM classes through Interop. My some 20000 pictures are Jpegs and not stored within the DBs blobs, but on a simple network share. To convert to bmp and scale those pictures, I wrote a litte C# function a couple of years ago, which still works fine. It reads the jpeg from a file, converts and scales it, and writes that bmp to a stream through which Nav can access it. Very fast, very stable and easy to use within Nav:
// just bind "TempRec.BlobField" to the picture control, and that´s it within Nav
IF ISCLEAR(LocAutImaging) THEN CREATE(LocAutImaging, FALSE, TRUE);
TempRec.BlobField.CREATEINSTREAM(LocStreamPreviewPic);
LocAutImaging.ConvertFileToBmpStream(LocStreamPreviewPic, '\\..\..\Picture.jpg', 300, 300);
CLEAR(LocAutImaging);
Using streams with Nav and C# was a bit tricky, but it works:
public void ConvertFileToBmpStream(object ObjPictureStream, string StrSourceFile, int NewHeigth, int NewWidth)
{
Bitmap MyBitMap = null;
IStream StmPicStream = ObjPictureStream as IStream;
MemoryStream ms = new MemoryStream();
IntPtr rwBytes = Marshal.AllocHGlobal(4);
Image img = Image.FromFile(StrSourceFile);
Size MySize = new Size(NewWidth, NewHeigth);
if (NewHeigth == 0 & NewWidth == 0){ MyBitMap = new Bitmap(img); } else { MyBitMap = new Bitmap(img, MySize); }
MyBitMap.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);
int StreamLength = Convert.ToInt32(ms.Length);
byte[] buffer = new byte[StreamLength];
buffer = ms.ToArray();
StmPicStream.Write(buffer, StreamLength, rwBytes);
Marshal.FreeHGlobal(rwBytes);
ms.Dispose();
img.Dispose();
MyBitMap.Dispose();
}
While everything is fine with that, we are now working on the Nav 2016 Update. With the RTC, COM Controls can still be used on the client side; BUT .. NO CHANCE, if you are using streams! And on the other hand, you cannot not use a Interop COM function to be run on the Nav Server.
That means, that I´ll have to implement this code as a method within a pure .Net class, without the Interop-Interface. Unfortunately I have no idea, how to pass a stream from Nav to the .Net method, so it can be read and written as in the above sample. Is it still the best way, to use that general "object" type and to cast this to an IStream?
Thanks in advance
Pidi