解决C#中的类型加载异常

发布于 2024-11-06 06:55:33 字数 5064 浏览 0 评论 0原文

在我的 Windows Mobile 6.5 应用程序中,我尝试使用一种方法创建缩略图。但是在调用该方法时,我收到了typtload 异常。

谁能告诉我如何解决这个问题。下面粘贴的是我的代码。

using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Newtonsoft.Json.Linq;
using System.Runtime.Serialization;
using System.Reflection;
using System.IO;
using System.Net;
using Microsoft.WindowsMobile.Forms;
using System.Diagnostics;
using DirectShowLib;
using System.Drawing.Imaging;
using System.Runtime.InteropServices;

namespace MyAppl
{  
  public partial class HomeForm : Form
    {

       public HomeForm()
        {
            InitializeComponent();
        }


        public class GetCamera
        {
            public static String videoFilePath;
            public static Bitmap myBitmap;

            CameraCaptureDialog ccd = new CameraCaptureDialog();

            public void getCameraDialogue()
            {
                ccd.Mode = CameraCaptureMode.VideoWithAudio;
                ccd.StillQuality = CameraCaptureStillQuality.Low;
                ccd.Title = "sweet";
                ccd.VideoTimeLimit = TimeSpan.FromMinutes(60);
                DialogResult dlgResult = ccd.ShowDialog();

                if (dlgResult == DialogResult.OK)
                {
                    videoFilePath = ccd.FileName;
                }
            }

            public void MyThumb(String path)
            {
                IGraphBuilder graphbuilder = (IGraphBuilder)new FilterGraph();
                ISampleGrabber samplegrabber = (ISampleGrabber)new SampleGrabber();
                graphbuilder.AddFilter((IBaseFilter)samplegrabber, "samplegrabber");

                AMMediaType mt = new AMMediaType();
                mt.majorType = MediaType.Video;
                mt.subType = MediaSubType.RGB24;
                mt.formatType = FormatType.VideoInfo;
                samplegrabber.SetMediaType(mt);
                int hr = graphbuilder.RenderFile(path, null);

                IMediaEventEx mediaEvt = (IMediaEventEx)graphbuilder;
                IMediaSeeking mediaSeek = (IMediaSeeking)graphbuilder;
                IMediaControl mediaCtrl = (IMediaControl)graphbuilder;
                IBasicAudio basicAudio = (IBasicAudio)graphbuilder;
                IVideoWindow videoWin = (IVideoWindow)graphbuilder;

                basicAudio.put_Volume(-10000);
                videoWin.put_AutoShow(OABool.False);

                samplegrabber.SetOneShot(true);
                samplegrabber.SetBufferSamples(true);

                long d = 0;
                mediaSeek.GetDuration(out d);
                long numSecs = d / 10000000;

                long secondstocapture = (long)(numSecs * 0.10f);


                DsLong rtStart, rtStop;
                rtStart = new DsLong(secondstocapture * 10000000);
                rtStop = rtStart;
                mediaSeek.SetPositions(rtStart, AMSeekingSeekingFlags.AbsolutePositioning, rtStop, AMSeekingSeekingFlags.AbsolutePositioning);

                mediaCtrl.Run();
                EventCode evcode;
                mediaEvt.WaitForCompletion(-1, out evcode);

                VideoInfoHeader videoheader = new VideoInfoHeader();
                AMMediaType grab = new AMMediaType();
                samplegrabber.GetConnectedMediaType(grab);
                videoheader = (VideoInfoHeader)Marshal.PtrToStructure(grab.formatPtr,
                typeof(VideoInfoHeader));


                int width = videoheader.SrcRect.right;
                int height = videoheader.SrcRect.bottom;
                Bitmap b = new Bitmap(width, height, PixelFormat.Format24bppRgb);

                uint bytesPerPixel = (uint)(24 >> 3);
                uint extraBytes = ((uint)width * bytesPerPixel) % 4;
                uint adjustedLineSize = bytesPerPixel * ((uint)width + extraBytes);
                uint sizeOfImageData = (uint)(height) * adjustedLineSize;


                System.Drawing.Imaging.BitmapData bd1 = b.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
                int bufsize = (int)sizeOfImageData;
                int n = samplegrabber.GetCurrentBuffer(ref bufsize, bd1.Scan0);
                b.UnlockBits(bd1);
                //         b.RotateFlip(RotateFlipType.RotateNoneFlipY);
                //        b.Save("C:\\aaa\\out.bmp");
                Marshal.ReleaseComObject(graphbuilder);
                Marshal.ReleaseComObject(samplegrabber);


                // return b;

            }

        }

        private void pbRecord_Click(object sender, EventArgs e)
        {

            GetCamera camera = new GetCamera();
            camera.getCameraDialogue();

            if (GetCamera.videoFilePath != null)
            {
                camera.MyThumb(GetCamera.videoFilePath);
            }

        }

         }
}

在camera.MyThumb(GetCamera.videoFilePath)行中接收TypeloadException;

请转发您的宝贵建议。

提前致谢 :)

In my application for windows mobile 6.5 i am trying to create a thumbnail using a method.But on call of that method i am receiving typtload exception.

Could anyone please let me know how can i resolve this.Below pasted is my code.

using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Newtonsoft.Json.Linq;
using System.Runtime.Serialization;
using System.Reflection;
using System.IO;
using System.Net;
using Microsoft.WindowsMobile.Forms;
using System.Diagnostics;
using DirectShowLib;
using System.Drawing.Imaging;
using System.Runtime.InteropServices;

namespace MyAppl
{  
  public partial class HomeForm : Form
    {

       public HomeForm()
        {
            InitializeComponent();
        }


        public class GetCamera
        {
            public static String videoFilePath;
            public static Bitmap myBitmap;

            CameraCaptureDialog ccd = new CameraCaptureDialog();

            public void getCameraDialogue()
            {
                ccd.Mode = CameraCaptureMode.VideoWithAudio;
                ccd.StillQuality = CameraCaptureStillQuality.Low;
                ccd.Title = "sweet";
                ccd.VideoTimeLimit = TimeSpan.FromMinutes(60);
                DialogResult dlgResult = ccd.ShowDialog();

                if (dlgResult == DialogResult.OK)
                {
                    videoFilePath = ccd.FileName;
                }
            }

            public void MyThumb(String path)
            {
                IGraphBuilder graphbuilder = (IGraphBuilder)new FilterGraph();
                ISampleGrabber samplegrabber = (ISampleGrabber)new SampleGrabber();
                graphbuilder.AddFilter((IBaseFilter)samplegrabber, "samplegrabber");

                AMMediaType mt = new AMMediaType();
                mt.majorType = MediaType.Video;
                mt.subType = MediaSubType.RGB24;
                mt.formatType = FormatType.VideoInfo;
                samplegrabber.SetMediaType(mt);
                int hr = graphbuilder.RenderFile(path, null);

                IMediaEventEx mediaEvt = (IMediaEventEx)graphbuilder;
                IMediaSeeking mediaSeek = (IMediaSeeking)graphbuilder;
                IMediaControl mediaCtrl = (IMediaControl)graphbuilder;
                IBasicAudio basicAudio = (IBasicAudio)graphbuilder;
                IVideoWindow videoWin = (IVideoWindow)graphbuilder;

                basicAudio.put_Volume(-10000);
                videoWin.put_AutoShow(OABool.False);

                samplegrabber.SetOneShot(true);
                samplegrabber.SetBufferSamples(true);

                long d = 0;
                mediaSeek.GetDuration(out d);
                long numSecs = d / 10000000;

                long secondstocapture = (long)(numSecs * 0.10f);


                DsLong rtStart, rtStop;
                rtStart = new DsLong(secondstocapture * 10000000);
                rtStop = rtStart;
                mediaSeek.SetPositions(rtStart, AMSeekingSeekingFlags.AbsolutePositioning, rtStop, AMSeekingSeekingFlags.AbsolutePositioning);

                mediaCtrl.Run();
                EventCode evcode;
                mediaEvt.WaitForCompletion(-1, out evcode);

                VideoInfoHeader videoheader = new VideoInfoHeader();
                AMMediaType grab = new AMMediaType();
                samplegrabber.GetConnectedMediaType(grab);
                videoheader = (VideoInfoHeader)Marshal.PtrToStructure(grab.formatPtr,
                typeof(VideoInfoHeader));


                int width = videoheader.SrcRect.right;
                int height = videoheader.SrcRect.bottom;
                Bitmap b = new Bitmap(width, height, PixelFormat.Format24bppRgb);

                uint bytesPerPixel = (uint)(24 >> 3);
                uint extraBytes = ((uint)width * bytesPerPixel) % 4;
                uint adjustedLineSize = bytesPerPixel * ((uint)width + extraBytes);
                uint sizeOfImageData = (uint)(height) * adjustedLineSize;


                System.Drawing.Imaging.BitmapData bd1 = b.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
                int bufsize = (int)sizeOfImageData;
                int n = samplegrabber.GetCurrentBuffer(ref bufsize, bd1.Scan0);
                b.UnlockBits(bd1);
                //         b.RotateFlip(RotateFlipType.RotateNoneFlipY);
                //        b.Save("C:\\aaa\\out.bmp");
                Marshal.ReleaseComObject(graphbuilder);
                Marshal.ReleaseComObject(samplegrabber);


                // return b;

            }

        }

        private void pbRecord_Click(object sender, EventArgs e)
        {

            GetCamera camera = new GetCamera();
            camera.getCameraDialogue();

            if (GetCamera.videoFilePath != null)
            {
                camera.MyThumb(GetCamera.videoFilePath);
            }

        }

         }
}

Receiving Typeloadexception in the line camera.MyThumb(GetCamera.videoFilePath);

Please forward your valuable suggestions.

Thanks in advance :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

长亭外,古道边 2024-11-13 06:55:33

可能是静态变量没有按时初始化,

请在代码中包含此行:

static GetCamera() {}

it may be the static vars not getting initialized on time

include this line in your code:

static GetCamera() {}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文