コード例 #1
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="ComSerializable{T}" /> class.
        /// </summary>
        /// <param name="info">The information.</param>
        /// <param name="context">The context.</param>
        protected ComSerializable(SerializationInfo info, StreamingContext context)
        {
            byte[] data   = (byte[])info.GetValue("DATA", typeof(byte[]));
            string progId = info.GetString("PROGID");

            using (ComReleaser com = new ComReleaser())
            {
                IMemoryBlobStream blob = new MemoryBlobStreamClass();
                com.ManageLifetime(blob);

                IMemoryBlobStreamVariant variant = (IMemoryBlobStreamVariant)blob;
                variant.ImportFromVariant(data);

                IObjectStream stream = new ObjectStreamClass();
                stream.Stream = blob;

                com.ManageLifetime(stream);

                Type t = Type.GetTypeFromProgID(progId);

                IPersistStream persist = (IPersistStream)Activator.CreateInstance(t);
                persist.Load(stream);

                this.Value = (T)persist;
            }
        }
コード例 #2
0
        /// <summary>
        /// Each BuilderItem contains a Function Raster Dataset which is used to create the thumbnail.
        /// The thumbnail is created by Nearest Neighbor resampling of the Function Raster Dataset.
        /// The resampled raster is exported as a byte array and saved Into the IMemoryBlobStreamVariant.
        /// The blob is then inserted into the Thumbnail field.
        /// </summary>
        /// <param name="mybuilderItem">Item containing the Function Dataset to be added to the Mosaic Dataset</param>
        private void Resampling(IBuilderItem mybuilderItem)
        {
            try
            {
                IFunctionRasterDataset pFuncRasterDataset = mybuilderItem.Dataset; // Get the FunctionRasterDataset from mybuilderItem
                IRasterDataset         pRasterDataset;
                pRasterDataset = (IRasterDataset)pFuncRasterDataset;               // Cast the FunctionRasterDataset to Raster Dataset
                IPropertySet thePropSet = pFuncRasterDataset.Properties;           // Get the properties of the raster Dataset
                IRaster      praster    = pRasterDataset.CreateDefaultRaster();    // Create default raster from the above raster dataset
                praster.ResampleMethod = rstResamplingTypes.RSP_NearestNeighbor;   // The raster is resampled by RSP_NearestNeighbor
                IRasterProps pRasterProps = (IRasterProps)praster;                 // Raster properties are used to update the height, width of the raster
                pRasterProps.Height = 256;
                pRasterProps.Width  = 256;

                IRasterExporter pConverter = new RasterExporterClass();                           // IRasterExporter object is used to convert the raster to byte array.
                byte[]          pBytesArr;
                pBytesArr = pConverter.ExportToBytes(praster, "TIFF");                            // Convert the resampled Raster to a Byte array
                IMemoryBlobStream        memBlobStream = new MemoryBlobStream();                  // Create new IMemoryBlobStream
                IMemoryBlobStreamVariant varBlobStream = (IMemoryBlobStreamVariant)memBlobStream; // Assign to IMemoryBlobStreamVariant
                object anObject = pBytesArr;
                varBlobStream.ImportFromVariant(anObject);                                        // IMemoryBlobStreamVariant object is assigned the byte array
                thePropSet.SetProperty("ThumbNail", memBlobStream);                               // and saved to the property "ThumbNail"
            }
            catch (Exception ex)
            {
                System.Exception myExc = new System.Exception(
                    "Error: Failed to Re-Sampled the raster.Thumbnails will not be created." + ex.Message, ex);
                throw myExc;
            }
            return;
        }