AlphaImage错误解决(zz)

AlphaImage中的这段代码出错 .... 不知道有谁知道怎样改??
public void Draw(Graphics gx, Rectangle bounds)
{
ImageInfo imgInfo;
_image.GetImageInfo(out imgInfo);

if (_alpha == 0)
{
// Draw the image, with alpha channel if any
IntPtr hdcDest = gx.GetHdc();
Rectangle dstRect = new Rectangle(bounds.X, bounds.Y, (int)imgInfo.Width + bounds.X, (int)imgInfo.Height + bounds.Y);
_image.Draw(hdcDest, ref dstRect, IntPtr.Zero);(这里产生异常...)
gx.ReleaseHdc(hdcDest);
}
else ....

异常信息:
位于 AlphaMobileControls.AlphaImage.Draw(Graphics gx, Rectangle bounds)
位于 AlphaMobileControls.AlphaPictureBox.Draw(Graphics gx)
位于 AlphaMobileControls.AlphaControl.DrawInternal(Graphics gx)
位于 AlphaMobileControls.AlphaContainer.OnPaint(PaintEventArgs e)
位于 AlphaMobileControls.AlphaForm.OnPaint(PaintEventArgs e)
位于 System.Windows.Forms.Control.WnProc(WM wm, Int32 wParam, Int32 lParam)
位于 System.Windows.Forms.ContainerControl.WnProc(WM wm, Int32 wParam, Int32 lParam)
位于 System.Windows.Forms.Form.WnProc(WM wm, Int32 wParam, Int32 lParam)
位于 System.Windows.Forms.Control._InternalWnProc(WM wm, Int32 wParam, Int32 lParam)
位于 Microsoft.AGL.Forms.EVL.EnterMainLoop(IntPtr hwnMain)
位于 System.Windows.Forms.Application.Run(Form fm)
位于 CMclient.Program.Main()
========================
{"未指明的错误 "} 未处理的COMException

  回复  引用  查看    
#13楼 2008-12-23 12:38 | suenihy      
http://www.codeplex.com/alphamobilecontrols/Thread/View.aspx?ThreadId=29775

是解决以上COM的错误的方法。

The problem is because a managed array is passed to the COM object. Once the garbage collector decides to free/move this array all hell break loose.
Here's a fix:
In IImagingFactory.cs, replace:

// We need the MarshalAs attribute here to keep COM interop from sending the buffer down as a Safe Array.
uint CreateImageFromBuffer([MarshalAs(UnmanagedType.LPArray)] byte[] buffer, uint size, BufferDisposalFlag disposalFlag, out IImage image);

With:

uint CreateImageFromBuffer(IntPtr buffer, uint size, BufferDisposalFlag disposalFlag, out IImage image);

In AlphaImage.cs add this in the top of the file:

using System.Runtime.InteropServices;

And replace:

factory.CreateImageFromBuffer(pbBuf, cbBuf, BufferDisposalFlag.BufferDisposalFlagNone, out alphaImage._image);

With:

// Copy stream data into an unmanaged global buffer that will be freed by the factory once image is decoded
// note that we cannot pass pbBuf directly since it might be moved around or freed by the gc.
IntPtr p = Marshal.AllocHGlobal((int)cbBuf);
Marshal.Copy(pbBuf, 0, p, (int)cbBuf);
factory.CreateImageFromBuffer(p, cbBuf, BufferDisposalFlag.BufferDisposalFlagGlobalFree, out alphaImage._image);

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值