示例#1
0
        public unsafe static RawDescriptionLoader FromFile(string filename)
        {
            IntPtr eximg_ptr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(SSRLWrapper.ExtractedDescription)));
            int    err       = SSRLWrapper.ExtractDescriptionFromFile(filename, eximg_ptr);

#if DEBUG
            Console.WriteLine("ExtractDescriptionFromFile returned " + err);
#endif
            if (err != 0)
            {
                throw new Exception();                  // TODO: Design a correct exception type
            }

            SSRLWrapper.ExtractedDescription eximg = (SSRLWrapper.ExtractedDescription)Marshal.PtrToStructure(eximg_ptr, typeof(SSRLWrapper.ExtractedDescription));

            RawDescriptionLoader ppml = new RawDescriptionLoader();

            // Handling
            ppml.mThumbnailData = new byte[eximg.data_size];
            ppml.mIsJpeg        = eximg.is_jpeg;
            ppml.mAperture      = eximg.aperture;
            ppml.mShutter       = eximg.shutter;
            ppml.mISOSpeed      = eximg.iso_speed;
            ppml.mFocalLength   = eximg.focal_len;
            ppml.mArtist        = Marshal.PtrToStringAnsi(eximg.artist);
            ppml.mDescription   = Marshal.PtrToStringAnsi(eximg.desc);
            ppml.mTimeStamp     = timeOrigin.AddSeconds(eximg.timestamp);
            ppml.mCameraMaker   = Marshal.PtrToStringAnsi(eximg.camera_maker);
            ppml.mCameraModel   = Marshal.PtrToStringAnsi(eximg.camera_model);
            int flip = eximg.flip;

            Marshal.Copy(eximg.data, ppml.mThumbnailData, 0, ppml.mThumbnailData.Length);

            SSRLWrapper.FreeExtractedDescription(eximg);

            // Rotating the image
            // flip: 0 - no rotation; 3 - 180-deg rotation; 5 - 90-deg counterclockwise, 6 - 90-deg clockwise
            if (flip == 0)
            {
                ppml.mFlip = FlipValues.None;
            }
            else if (flip == 3)
            {
                ppml.mFlip = FlipValues.UpsideDown;
            }
            else if (flip == 5)
            {
                ppml.mFlip = FlipValues.Counterclockwise;
            }
            else if (flip == 6)
            {
                ppml.mFlip = FlipValues.Clockwise;
            }

            return(ppml);
        }
        public static unsafe RawDescriptionLoader FromFile(string filename)
        {
            IntPtr eximg_ptr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(SSRLWrapper.ExtractedDescription)));
            int err = SSRLWrapper.ExtractDescriptionFromFile(filename, eximg_ptr);
            #if DEBUG
            Console.WriteLine("ExtractDescriptionFromFile returned " + err);
            #endif
            if (err != 0)
            {
                throw new Exception();	// TODO: Design a correct exception type
            }

            SSRLWrapper.ExtractedDescription eximg = (SSRLWrapper.ExtractedDescription)Marshal.PtrToStructure(eximg_ptr, typeof(SSRLWrapper.ExtractedDescription));

            RawDescriptionLoader ppml = new RawDescriptionLoader();

            // Handling
            ppml.mThumbnailData = new byte[eximg.data_size];
            ppml.mIsJpeg = eximg.is_jpeg;
            ppml.mAperture = eximg.aperture;
            ppml.mShutter = eximg.shutter;
            ppml.mISOSpeed = eximg.iso_speed;
            ppml.mFocalLength = eximg.focal_len;
            ppml.mArtist = Marshal.PtrToStringAnsi(eximg.artist);
            ppml.mDescription = Marshal.PtrToStringAnsi(eximg.desc);
            ppml.mTimeStamp = timeOrigin.AddSeconds(eximg.timestamp);
            ppml.mCameraMaker = Marshal.PtrToStringAnsi(eximg.camera_maker);
            ppml.mCameraModel = Marshal.PtrToStringAnsi(eximg.camera_model);
            int flip = eximg.flip;

            Marshal.Copy(eximg.data, ppml.mThumbnailData, 0, ppml.mThumbnailData.Length);

            SSRLWrapper.FreeExtractedDescription(eximg);

            // Rotating the image
            // flip: 0 - no rotation; 3 - 180-deg rotation; 5 - 90-deg counterclockwise, 6 - 90-deg clockwise
            if (flip == 0) ppml.mFlip = FlipValues.None;
            else if (flip == 3) ppml.mFlip = FlipValues.UpsideDown;
            else if (flip == 5) ppml.mFlip = FlipValues.Counterclockwise;
            else if (flip == 6) ppml.mFlip = FlipValues.Clockwise;

            return ppml;
        }