目前我仍在使用 Nav2009R2 经典版,使用 C# 库和 COM 类通过互操作。我的大约 20000 张图片是 Jpeg,不存储在 DB blob 中,而是存储在简单的网络共享上。为了转换为 bmp 并缩放这些图片,几年前我编写了一个 litte C# 函数,它仍然可以正常工作。它从文件中读取 jpeg,对其进行转换和缩放,并将该 bmp 写入 Nav 可以访问它的流。在 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);
将流与 Nav 和 C# 一起使用有点棘手,但它有效:
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();
}
虽然一切都很好,但我们现在正在开发Nav 2016更新。使用 RTC,COM 控件仍然可以在客户端使用;但。。没有机会,如果你正在使用流!另一方面,不能不使用在导航服务器上运行的互操作 COM 函数。
这意味着,我必须将此代码实现为纯 .Net 类中的方法,而无需互操作接口。不幸的是,我不知道如何将流从 Nav 传递到 .Net 方法,因此可以像上面的示例中一样读取和写入它。使用通用的"对象"类型并将其转换为 IStream 仍然是最好的方法吗?
提前致谢
皮迪
这是一个代码,它使用 DotNet 来调整图像大小
ResizePhoto(Filename : Text;NewFilePath : Text;MaxHeight : Integer)
IF Filename = '' THEN
IF GUIALLOWED THEN ERROR(NoFilename) ELSE EXIT;
IF NewFilePath = '' THEN BEGIN
DirectoryInfo := DirectoryInfo.DirectoryInfo(Path.GetDirectoryName(NewFilePath));
IF NOT DirectoryInfo.Exists THEN
IF GUIALLOWED THEN ERROR(STRSUBSTNO(NewDirectoryDoesntExists,DirectoryInfo.Name)) ELSE EXIT;
END;
IF MaxHeight = 0 THEN
IF GUIALLOWED THEN ERROR(NoNewSize) ELSE EXIT;
AuctionSetup.GET;
IF GUIALLOWED THEN Setup.TESTFIELD("Photo Pool Path")
ELSE IF Setup."Photo Pool Path" = '' THEN ERROR(NoPhotoPoolPath);
Filepath := Path.Combine(Setup."Photo Pool Path",Filename);
IF NewFilePath = '' THEN NewFilePath := Filepath;
Image := Image.FromFile(Filepath);
Pct := MaxHeight / Image.Height;
NewWidth := ROUND(Image.Width * Pct,1);
NewHeight := ROUND(Image.Height * Pct,1);
Bitmap := Bitmap.Bitmap(NewWidth,NewHeight);
Graphics := Graphics.FromImage(Bitmap);
InterpolationMode := InterpolationMode.HighQualityBicubic;
Graphics.InterpolationMode := InterpolationMode;
SmoothingMode := SmoothingMode.HighQuality;
Graphics.SmoothingMode := SmoothingMode;
PixelOffsetMode := PixelOffsetMode.HighQuality;
Graphics.PixelOffsetMode := PixelOffsetMode;
Graphics.DrawImage(Image,0,0,NewWidth,NewHeight);
Graphics.Dispose;
Image.Dispose;
ImageFormat := ImageFormat.Jpeg;
Bitmap.Save(NewFilePath,ImageFormat);
变量:
Name DataType Subtype Length
Setup Record Setup
Filepath Text
Path DotNet System.IO.Path.'mscorlib'
DirectoryInfo DotNet System.IO.DirectoryInfo.'mscorlib'
Image DotNet System.Drawing.Image.'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'
InterpolationMode DotNet System.Drawing.Drawing2D.InterpolationMode.'System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
SmoothingMode DotNet System.Drawing.Drawing2D.SmoothingMode.'System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
PixelOffsetMode DotNet System.Drawing.Drawing2D.PixelOffsetMode.'System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
ImageFormat DotNet System.Drawing.Imaging.ImageFormat.'System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
Pct Decimal
HeightPct Decimal
WidthPct Decimal
NewWidth Integer
NewHeight Integer
NewWidthDec Decimal
NewHeightDec Decimal
DecimalZero Decimal
用法:
ConvertFileNameDotNet(FileName : Text;Resolution : Integer;VAR Image : TEMPORARY Record TempBitmapBlob)
IF Resolution = 0 THEN Resolution := 300;
Setup.GET;
Setup.TESTFIELD("Photo Pool Path");
GUID := FORMAT(CREATEGUID);
ConvertedServerTempFilePath := 'C:TEMP' + GUID + '_CONVERTED.JPG';
IF EXISTS(ConvertedServerTempFilePath) THEN IF ERASE(ConvertedServerTempFilePath) THEN;
IF NOT EXISTS(Setup."Photo Pool Path" + FileName) THEN EXIT;
ResizePhoto(FileName,ConvertedServerTempFilePath,Resolution);
IF EXISTS(ConvertedServerTempFilePath) THEN BEGIN
FileManagement.BLOBImportFromServerFile(TempBlob,ConvertedServerTempFilePath);
Image.Blob := TempBlob.Blob;
IF EXISTS(ConvertedServerTempFilePath) THEN IF ERASE(ConvertedServerTempFilePath) THEN;
END;
如果你愿意,我可以在txt中向您发送对象。
干杯!