当前位置: 首页>>代码示例>>C#>>正文


C# IProgress.SetProgress方法代码示例

本文整理汇总了C#中IProgress.SetProgress方法的典型用法代码示例。如果您正苦于以下问题:C# IProgress.SetProgress方法的具体用法?C# IProgress.SetProgress怎么用?C# IProgress.SetProgress使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IProgress的用法示例。


在下文中一共展示了IProgress.SetProgress方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Fill_Image_Buffer

        public static byte[,,] Fill_Image_Buffer(Bitmap bmp, IProgress progress, ICurrentOperation operation)
        {
            if (operation != null)
                operation.SetOperation(CurrentOperation.FillImageBuffer);

            Point originalSize = GetActualDimension(new Point(bmp.Width, bmp.Height));
            byte[,,] Bitmap_Buffer = new byte[originalSize.X,originalSize.Y, 3];

            IntPtr hbmScreen = IntPtr.Zero;
            IntPtr hBmpInput = bmp.GetHbitmap();

            InteropGDI.BITMAP bmpInput = new InteropGDI.BITMAP();
            InteropGDI.GetObject(hBmpInput, 24, ref bmpInput);
            InteropGDI.BITMAPINFOHEADER bi;

            bi.biSize = 40;
            bi.biWidth = bmpInput.bmWidth;
            bi.biHeight = -bmpInput.bmHeight; // Negative to reverse the scan order.
            bi.biPlanes = 1;
            bi.biBitCount = 32;
            bi.biCompression = (uint)InteropGDI.BMP_Compression_Modes.BI_RGB;
            bi.biSizeImage = 0;
            bi.biXPelsPerMeter = 0;
            bi.biYPelsPerMeter = 0;
            bi.biClrUsed = 0;
            bi.biClrImportant = 0;

            ulong bitmapLengthBytes = (ulong)(((bmpInput.bmWidth * bi.biBitCount + 31) / 32) * 4 * bmpInput.bmHeight);

            byte[] bitmap_array = new byte[bitmapLengthBytes];

            IntPtr hdcWindow = InteropGDI.CreateCompatibleDC(IntPtr.Zero);

            InteropGDI.GetDIBits(hdcWindow, hBmpInput, (uint)0,
                (uint)bmpInput.bmHeight,
                bitmap_array,
                ref bi, (uint)InteropGDI.DIB_COLORS.DIB_RGB_COLORS);

            int k = 0, wd = bmpInput.bmWidth, ht = bmpInput.bmHeight;

            for (int j = 0; j < ht; j++)
            {
                if (progress != null)
                    progress.SetProgress((int)bitmapLengthBytes, k);

                for (int i = 0; i < wd; i++)
                {
                    Bitmap_Buffer[i, j, 2] = bitmap_array[k++];
                    Bitmap_Buffer[i, j, 1] = bitmap_array[k++];
                    Bitmap_Buffer[i, j, 0] = bitmap_array[k++];
                    k++;
                }
            }

            InteropGDI.DeleteObject(hdcWindow);
            InteropGDI.DeleteObject(hbmScreen);
            InteropGDI.DeleteObject(hBmpInput);

            return Bitmap_Buffer;
        }
开发者ID:b9chris,项目名称:ArpanJpegEncoder,代码行数:60,代码来源:Utils.cs

示例2: UploadFile

        private bool UploadFile(string strURL, string strFile, string strCompleteURI, IProgress pProgress)
        {
            VimeoLogger.Log("Vimeo::UploadFile");
             Debug.Assert(File.Exists(strFile));
             Debug.Assert(!String.IsNullOrWhiteSpace(strURL));

             m_strClipURI = null;

             FileInfo fi = new FileInfo(strFile);
             long lFileSize = fi.Length;

             FileStream fstream = File.OpenRead(strFile);

             long lChunkSize = m_lChunkSize;

             byte[] buffer = new byte[lChunkSize];
             long lStart = 0;
             while (true)
             {
            if (pProgress != null && pProgress.GetCanceled())
            {
               fstream.Close();
               return false;
            }

            long lEnd = Math.Min(lStart + lChunkSize, lFileSize);
            long lBytes = lEnd - lStart;

            HttpWebRequest request = WebRequest.CreateDefault(new Uri(strURL)) as HttpWebRequest;
            request.Method = @"PUT";
            request.Accept = @"application/vnd.vimeo.*+json; version=3.2";
            request.ContentType = @"video/mp4";
            request.Headers = new WebHeaderCollection()
            {
               {"Content-Range", String.Format("bytes {0}-{1}/{2}", lStart, lEnd, lFileSize)}
            };
            request.KeepAlive = false;

            try
            {
               {
                  long lRead = (long)fstream.Read(buffer, 0, (int)lBytes);
                  Debug.Assert(lRead == lBytes);
                  request.ContentLength = lRead;
                  Stream requestStream = request.GetRequestStream();
                  requestStream.Write(buffer, 0, (int)lRead);
                  requestStream.Close();
               }

               //Do call
               HttpWebResponse response = request.GetResponse() as HttpWebResponse;
               VimeoLogger.Log(response);

               HttpStatusCode status = response.StatusCode;
               //Successful uploads with have a HTTP 200 status code. A 501 error means you did not perform a PUT or the request was malformed.

               //Not sure exactly what to do if I get an error :(
               if (status != HttpStatusCode.OK)
                  return false;

               Stream responseStream = response.GetResponseStream();
               StreamReader r = new StreamReader(responseStream);
               string strResponse = r.ReadToEnd();
               VimeoLogger.Log("Vimeo::UploadFile; response: " + strResponse);
               r.Close();
               responseStream.Close();
               response.Close();

               if (pProgress != null)
               {
                  double dPercentage = lEnd * 100.0 / lFileSize;
                  pProgress.SetProgress(dPercentage);
               }

               lStart += lBytes;
               if (lEnd >= lFileSize)
                  break;
            }
            catch (WebException wex)
            {
               VimeoLogger.Log(wex);
               m_strErrorMessage = wex.Message;
               fstream.Close();
               return false;
            }
             }

             fstream.Close();

             //Verify the upload
             bool bOK = VerifyUpload(strURL);

             if (bOK)
             {
            bOK = CompleteUpload(strCompleteURI);
             }

             return bOK;
        }
开发者ID:TechSmith,项目名称:VimeoAPI,代码行数:99,代码来源:Vimeo.cs

示例3: Write_Bmp_From_Data

        public static Bitmap Write_Bmp_From_Data(byte [,,] pixel_data, Point dimensions, IProgress progress, ICurrentOperation operation)
        {
            operation.SetOperation(Utils.CurrentOperation.WriteChannelImages);

            int k = 0;
            Bitmap bmp = new Bitmap(dimensions.X,dimensions.Y);
            IntPtr hBmpOutput = bmp.GetHbitmap();
            byte[, ,] Bitmap_Buffer = new byte[dimensions.X, dimensions.Y, 3];

            InteropGDI.BITMAPINFOHEADER bi;

            bi.biSize = 40;
            bi.biWidth = dimensions.X;
            bi.biHeight = -dimensions.Y;
            bi.biPlanes = 1;
            bi.biBitCount = 32;
            bi.biCompression = (uint)InteropGDI.BMP_Compression_Modes.BI_RGB;
            bi.biSizeImage = 0;
            bi.biXPelsPerMeter = 0;
            bi.biYPelsPerMeter = 0;
            bi.biClrUsed = 0;
            bi.biClrImportant = 0;

            ulong bitmapLengthBytes = (ulong)(((dimensions.X * bi.biBitCount + 31) / 32) * 4 * dimensions.Y);

            byte[] bitmap_array = new byte[bitmapLengthBytes];

            for (int j = 0; j < dimensions.Y; j++)
            {
                progress.SetProgress((int)bitmapLengthBytes, k);
                for (int i = 0; i < dimensions.X; i++)
                {
                    bitmap_array[k++] = pixel_data[i, j, 2];
                    bitmap_array[k++] = pixel_data[i, j, 1];
                    bitmap_array[k++] = pixel_data[i, j, 0];
                    k++;
                }
            }

            IntPtr hdcWindow = InteropGDI.CreateCompatibleDC(IntPtr.Zero);

            InteropGDI.SetDIBits(hdcWindow, hBmpOutput, (uint)0,
                (uint)dimensions.Y,
                bitmap_array,
                ref bi, (uint)InteropGDI.DIB_COLORS.DIB_RGB_COLORS);

            bmp = Bitmap.FromHbitmap(hBmpOutput);

            InteropGDI.DeleteObject(hBmpOutput);
            InteropGDI.DeleteObject(hdcWindow);

            return bmp;
        }
开发者ID:b9chris,项目名称:ArpanJpegEncoder,代码行数:53,代码来源:Utils.cs


注:本文中的IProgress.SetProgress方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。