예제 #1
0
        public System.Drawing.Bitmap LoadBitmap(int width, int height, string path)
        {
            if (height * width == 0)
            {
                return(null);
            }

            System.Drawing.Bitmap bitmap = null;
            try
            {
                bitmap = new System.Drawing.Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
            }
            catch (System.Exception)
            {
                GC.Collect();
                try
                {
                    bitmap = new System.Drawing.Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
                }
                catch (System.Exception)
                {
                    return(null);
                }
            }
            System.Drawing.Imaging.BitmapData bitmapData = new System.Drawing.Imaging.BitmapData();
            bitmapData = bitmap.LockBits(
                new System.Drawing.Rectangle(0, 0, width, height),
                System.Drawing.Imaging.ImageLockMode.WriteOnly,
                System.Drawing.Imaging.PixelFormat.Format32bppArgb,
                bitmapData);
            CoreDll.adBitmap[] pBitmap = new CoreDll.adBitmap[1];
            pBitmap[0].width  = (uint)bitmapData.Width;
            pBitmap[0].height = (uint)bitmapData.Height;
            pBitmap[0].stride = bitmapData.Stride;
            pBitmap[0].format = CoreDll.PixelFormatType.Argb32;
            pBitmap[0].data   = bitmapData.Scan0;
            CoreDll.Error error = m_dll.adLoadBitmapW(m_handle, path, Marshal.UnsafeAddrOfPinnedArrayElement(pBitmap, 0));
            bitmap.UnlockBits(bitmapData);
            return(error == CoreDll.Error.Ok ? bitmap : null);
        }