[英]Why I get access violation error from TBitmap.LoadFromStream method in datasnap ISAPI dll?
I've developed a datasnap rest server application in RAD Studio 10.3.2.我在 RAD Studio 10.3.2 中开发了一个 datasnap rest 服务器应用程序。 In one of my server methods I receive an image from the client app.在我的一种服务器方法中,我从客户端应用程序接收图像。 The image data is a base64 encoded string as a json value.图像数据是 base64 编码字符串作为 json 值。 My method is something like this:我的方法是这样的:
function TServerMethods1.getImage(JSONobj: TJSONObject): Boolean;
var
OutputStream : TMemoryStream;
InputStream : TStringStream;
theImage : TBitmap;
begin
var imageStr : string := JSONobj.GetValue('Image').Value;
InputStream := TStringStream.Create(imageStr);
//InputStream.saveToFile('C:\InputStream.txt');
OutputStream := TMemoryStream.Create;
theImage := TBitmap.Create;
try
InputStream.Position := 0;
TNetEncoding.Base64.Decode(InputStream, OutputStream);
//OutputStream.saveToFile('C:\OutputStream.txt');
OutputStream.Position := 0;
theImage.LoadFromStream(OutputStream); // in this line I get an access violation error!
finally
theStringStream.Free;
theMemoryStream.Free;
end;
.
.
.
end;
When I build the project as a standalone firemonkey app (.exe file) everything works fine but when I build an ISAPI dll and deploy it in IIS I got an access violation error in the line that I added a comment to it.当我将项目构建为独立的 firemonkey 应用程序(.exe 文件)时,一切正常,但是当我构建 ISAPI dll 并将其部署在 IIS 中时,我在添加注释的行中遇到访问冲突错误。 What's wrong?怎么了? I'm really confused!我真的很困惑!
PS附言
I saved both InputStream
and OutputStream
somewhere so that I get sure that I receive the stream and decode it properly and both streams are just fine.我将InputStream
和OutputStream
都保存在某处,以便确保收到 stream 并正确解码,两个流都很好。
The variable theImage: TBitmap;
变量theImage: TBitmap;
is an object of FMX.Graphics.TBitmap
class, because my stand-alone GUI is a firemonkey application.是 FMX.Graphics.TBitmap FMX.Graphics.TBitmap
的 object,因为我的独立 GUI 是 firemonkey 应用程序。
It seems that the TBitmap
class of fmx has problems with ISAPI dll. fmx 的TBitmap
class 似乎与 ISAPI dll 有问题。 So Instead of using FMX.Graphics
I utilized TJPEGImage
class of vcl.因此,我没有使用FMX.Graphics
,而是使用TJPEGImage
的 TJPEGImage class。 In order to achieve that I added Vcl.Imaging.jpeg
to uses
section of ServerMethodsUnit.为了实现这一点,我将Vcl.Imaging.jpeg
添加到 ServerMethodsUnit 的uses
部分。 Then I changed my previous function to this:然后我将之前的 function 更改为:
function TServerMethods1.getImage(JSONobj: TJSONObject): Boolean;
var
OutputStream : TMemoryStream;
InputStream : TStringStream;
theImage : TJPEGImage; // using TJPEGImage instead of FMX.Graphics.TBitmap
begin
var imageStr : string := JSONobj.GetValue('Image').Value;
InputStream := TStringStream.Create(imageStr);
OutputStream := TMemoryStream.Create;
theImage := TJPEGImage.Create;
try
InputStream.Position := 0;
TNetEncoding.Base64.Decode(InputStream, OutputStream);
OutputStream.Position := 0;
theImage.LoadFromStream(OutputStream); // Now this line works fine!
finally
theStringStream.Free;
theMemoryStream.Free;
end;
.
.
.
end;
Now I can load the received image from memorystream and save it as a jpeg image file.现在我可以从内存流中加载接收到的图像并将其保存为 jpeg 图像文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.