将原始数据复制到位图 [英] Copy raw data to bitmap
问题描述
我在项目的DLL中使用以下代码.在我将项目移至托管服务器之前,它一直运行良好,现在由于服务提供商仅允许中等信任度,因此它在AllocHGlobal上引发了安全错误.我不能将所有模块都交给GAC 或更改信任级别,所以我需要其他方法,有人可以建议替代此功能吗?
private Bitmap CreateBitMap() { IntPtr pImageData = 元帅 .AllocHGlobal( 此 .imageData.Length); 元帅.Copy( this .imageData, 0,  ; pImageData,此 .imageData.Length); 位图 bitmap = 新 位图(此 .header.Width, 此 .header.Height,此 .stride,此 .pixelFormat,pImageData ); 返回 位图; }
约翰·休斯二世
www.functioninternational.com
您好,jjhii,>
尝试以这种方式进行操作,该方式不使用AllocHGloable专门预留内存.它可能不如您的方法有效,但是请看它是否可以解决权限问题:
Bitmap existingbmp = new Bitmap(imageData);
I use the below code in a DLL in my project. It worked fine until I move the project to a hosted server and now it throw security errors on AllocHGlobal because the service provider only allows medium trust. I can not all the module to the GAC or change the trust level so I need to another method, can anyone suggest a replacement for this function?
private Bitmap CreateBitMap() { IntPtr pImageData = Marshal.AllocHGlobal(this.imageData.Length); Marshal.Copy(this.imageData, 0, pImageData, this.imageData.Length); Bitmap bitmap = new Bitmap(this.header.Width, this.header.Height, this.stride, this.pixelFormat, pImageData); return bitmap; }
John J. Hughes II
www.functioninternational.com解决方案Hi jjhii,
Try doing it this way, which doesn't use AllocHGloable to specifically set aside the memory. It may not be as efficient as your method but see if it gets around the permission issues:
Bitmap existingbmp = new Bitmap(imageData);
这篇关于将原始数据复制到位图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文