Exemplo n.º 1
0
        private void RenderFitMode(PaintEventArgs pe, byte[] data, int width, int height, int rotation)
        {
            Graphics graphics = pe.Graphics;

            // 设置背景为全黑
            graphics.Clear(Color.Black);

            Bitmap     bmp     = new Bitmap(width, height, PixelFormat.Format32bppPArgb);
            BitmapData bmpData = bmp.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.WriteOnly, PixelFormat.Format32bppPArgb);

            // 获取图像参数
            int    stride    = bmpData.Stride;  // 扫描线的宽度
            IntPtr iptr      = bmpData.Scan0;   // 获取bmpData的内存起始位置
            int    scanBytes = stride * height; // 用stride宽度,表示这是内存区域的大小

            // 用Marshal的Copy方法,将刚才得到的内存字节数组复制到BitmapData中
            Marshal.Copy(data, 0, iptr, scanBytes);
            bmp.UnlockBits(bmpData);

            bmp = Util.Rotate(bmp, rotation);

            // 获取缩放后的矩形大小
            int     viewWidth  = this.ClientSize.Width;
            int     viewHeight = this.ClientSize.Height;
            PicSize size       = Util.AdjustSize(viewWidth, viewHeight, bmp.Width, bmp.Height);

            width  = size.width;
            height = size.height;
            int       x    = (viewWidth - width) / 2;
            int       y    = (viewHeight - height) / 2;
            Rectangle rect = new Rectangle(x, y, width, height);

            graphics.DrawImage(bmp, rect);
            bmp.Dispose();
        }
Exemplo n.º 2
0
        public static void RescalePic(Image <Rgba32> input, Stream output, PicSize size, IImageFormat format)
        {
            var dimensions = picDimensions[size];

            input.Mutate(x => x.Resize(dimensions.Item1, dimensions.Item2));
            input.Save(output, format);
        }
Exemplo n.º 3
0
        private void AddToPost(ListViewItem lvi)
        {
            ImageInformation ii = lvi.Tag as ImageInformation;

            if (!ii.uploadedToDevServer)
            {
                //FileUploadReturnInfo retval = UploadFile(ii, localdevserver);
                //if (retval == null) return;

                ii.uploadedToDevServer = true;

                using (Bitmap b = new Bitmap(ii.fullpath))
                {
                    PicSize sz = resizePic(new PicSize()
                    {
                        width = b.Width, height = b.Height
                    });
                    using (Bitmap med = new Bitmap(sz.width, sz.height))
                    {
                        using (Graphics g = Graphics.FromImage(med))
                        {
                            g.DrawImage(b, new Rectangle(0, 0, sz.width, sz.height));
                        }

                        string medpath = Path.Combine(postResources, GetMedFilename(ii, sz));
                        med.Save(medpath);
                        ii.medurl    = "http://localhost:" + webservport + "/" + GetMedFilename(ii, sz);
                        ii.medwidth  = sz.width;
                        ii.medheight = sz.height;
                    }

                    b.Save(Path.Combine(postResources, ii.filename));
                    ii.fullurl = "http://localhost:" + webservport + "/" + ii.filename;
                }
            }

            if (ii.medwidth == ii.bitmap.Width && ii.medheight == ii.bitmap.Height)
            {
                txt_Content.AppendText("<a href=\"" +
                                       Uri.EscapeUriString(ii.fullurl) +
                                       "\" rel=\"lightbox\"><img src=\"" + Uri.EscapeUriString(ii.fullurl) +
                                       "\" alt=\"\" title=\"Picture\" width=\"" + ii.medwidth +
                                       "\" height=\"" + ii.medheight +
                                       "\" class=\"alignnone size-medium wp-image-1204\" /></a>"
                                       );
            }
            else
            {
                txt_Content.AppendText("<a href=\"" +
                                       Uri.EscapeUriString(ii.fullurl) +
                                       "\" rel=\"lightbox\"><img src=\"" + Uri.EscapeUriString(ii.medurl) +
                                       "\" alt=\"\" title=\"Picture\" width=\"" + ii.medwidth +
                                       "\" height=\"" + ii.medheight +
                                       "\" class=\"alignnone size-medium wp-image-1204\" /></a>"
                                       );
            }
        }
Exemplo n.º 4
0
        private void RenderFitMode(PaintEventArgs pe, byte[] data, int width, int height)
        {
            Graphics graphics = pe.Graphics;

            // 设置背景为全黑
            graphics.Clear(Color.Black);

            Bitmap     bmp     = new Bitmap(width, height, PixelFormat.Format32bppPArgb);
            BitmapData bmpData = bmp.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.WriteOnly, PixelFormat.Format32bppPArgb);

            // 获取图像参数
            int    stride    = bmpData.Stride;  // 扫描线的宽度
            IntPtr iptr      = bmpData.Scan0;   // 获取bmpData的内存起始位置
            int    scanBytes = stride * height; // 用stride宽度,表示这是内存区域的大小

            // 下面把原始的显示大小字节数组转换为内存中实际存放的字节数组
            int posScan = 0, posReal = 0;             // 分别设置两个位置指针,指向源数组和目标数组

            byte[] pixelValues = new byte[scanBytes]; //为目标数组分配内存

            // 下面的循环节是模拟行扫描
            for (int i = 0; i < mArgbRenderFrame.data.Length; i++)
            {
                pixelValues[posScan++] = mArgbRenderFrame.data[posReal++];
            }

            // 用Marshal的Copy方法,将刚才得到的内存字节数组复制到BitmapData中
            Marshal.Copy(pixelValues, 0, iptr, scanBytes);
            bmp.UnlockBits(bmpData);

            if (mArgbRenderFrame.rotation == TRTCVideoRotation.TRTCVideoRotation90)
            {
                bmp = Util.Rotate(bmp, 90);
            }
            else if (mArgbRenderFrame.rotation == TRTCVideoRotation.TRTCVideoRotation180)
            {
                bmp = Util.Rotate(bmp, 180);
            }
            else if (mArgbRenderFrame.rotation == TRTCVideoRotation.TRTCVideoRotation270)
            {
                bmp = Util.Rotate(bmp, 270);
            }

            // 获取缩放后的矩形大小
            int     viewWidth  = this.ClientSize.Width;
            int     viewHeight = this.ClientSize.Height;
            PicSize size       = Util.AdjustSize(viewWidth, viewHeight, bmp.Width, bmp.Height);

            width  = size.width;
            height = size.height;
            int       x    = (viewWidth - width) / 2;
            int       y    = (viewHeight - height) / 2;
            Rectangle rect = new Rectangle(x, y, width, height);

            graphics.DrawImage(bmp, rect);
            bmp.Dispose();
        }
Exemplo n.º 5
0
        PicSize resizePic(PicSize size)
        {
            if (size.width > medsize.width)
            {
                size.height = size.height * medsize.width / size.width;
                size.width  = medsize.width;
            }

            if (size.height > medsize.height)
            {
                size.width  = size.width * medsize.height / size.height;
                size.height = medsize.height;
            }

            return(size);
        }
Exemplo n.º 6
0
        public WordLaunch(ServerInfo targetserver)
        {
            InitializeComponent();
            this.targetserver = targetserver;
            plugin            = new PluginRpc(targetserver.conn.URL);
            medsize           = plugin.GetMediumSize();

            txt_Content.NativeInterface.SetCodePage((int)Constants.SC_CP_UTF8);

            CategoryFullInfo[] cfi = targetserver.conn.GetCategories(0, targetserver.username, targetserver.password);
            foreach (CategoryFullInfo cf in cfi)
            {
                CheckBox cb = new CheckBox();
                cb.Name = "cb_" + cf.categoryName;
                cb.Text = cf.categoryName;
                cb.Tag  = cf;
                flow_Categories.Controls.Add(cb);
            }

            postResources = GetNextAvailableDir();
            Directory.CreateDirectory(postResources);

            var module = new FileModule();

            webserv = new Server();
            module.Resources.Add(new FileResources("/", postResources));
            webserv.Add(module);
            webserv.Add(new MultiPartDecoder());
            webserv.RequestReceived += new EventHandler <RequestEventArgs>(webserv_RequestReceived);

            // use one http listener.
            webserv.Add(HttpListener.Create(System.Net.IPAddress.Any, webservport));
            webserv.Start(5);

            // Find a valid post to use
            url = targetserver.conn.URL.Replace("xmlrpc.php", "?p=2147483646");
        }
Exemplo n.º 7
0
        public static PicSize AdjustSize(int spcWidth, int spcHeight, int orgWidth, int orgHeight)
        {
            PicSize size = new PicSize();

            // 原始宽高在指定宽高范围内,不作任何处理
            if (orgWidth <= spcWidth && orgHeight <= spcHeight)
            {
                size.Width  = orgWidth;
                size.Height = orgHeight;
            }
            else
            {
                // 取得比例系数
                float w = orgWidth / (float)spcWidth;
                float h = orgHeight / (float)spcHeight;
                // 宽度比大于高度比
                if (w > h)
                {
                    size.Width  = spcWidth;
                    size.Height = (int)(w >= 1 ? Math.Round(orgHeight / w) : Math.Round(orgHeight * w));
                }
                // 宽度比小于高度比
                else if (w < h)
                {
                    size.Height = spcHeight;
                    size.Width  = (int)(h >= 1 ? Math.Round(orgWidth / h) : Math.Round(orgWidth * h));
                }
                // 宽度比等于高度比
                else
                {
                    size.Width  = spcWidth;
                    size.Height = spcHeight;
                }
            }
            return(size);
        }
Exemplo n.º 8
0
        public WordLaunch(ServerInfo targetserver)
        {
            InitializeComponent();
            this.targetserver = targetserver;
            plugin = new PluginRpc(targetserver.conn.URL);
            medsize = plugin.GetMediumSize();

            txt_Content.NativeInterface.SetCodePage((int)Constants.SC_CP_UTF8);

            CategoryFullInfo[] cfi = targetserver.conn.GetCategories(0, targetserver.username, targetserver.password);
            foreach (CategoryFullInfo cf in cfi)
            {
                CheckBox cb = new CheckBox();
                cb.Name = "cb_" + cf.categoryName;
                cb.Text = cf.categoryName;
                cb.Tag = cf;
                flow_Categories.Controls.Add(cb);
            }

            postResources = GetNextAvailableDir();
            Directory.CreateDirectory(postResources);

            var module = new FileModule();
            webserv = new Server();
            module.Resources.Add(new FileResources("/",postResources));
            webserv.Add(module);
            webserv.Add(new MultiPartDecoder());
            webserv.RequestReceived+=new EventHandler<RequestEventArgs>(webserv_RequestReceived);

            // use one http listener.
            webserv.Add(HttpListener.Create(System.Net.IPAddress.Any, webservport));
            webserv.Start(5);

            // Find a valid post to use
            url = targetserver.conn.URL.Replace("xmlrpc.php", "?p=2147483646");
        }
Exemplo n.º 9
0
 private static string GetMedFilename(ImageInformation ii, PicSize sz)
 {
     return(Path.GetFileNameWithoutExtension(ii.filename)
            + "-" + sz.width + "x" + sz.height
            + Path.GetExtension(ii.filename));
 }
Exemplo n.º 10
0
 /// <summary>
 /// 宽高比例缩放业务逻辑代码
 /// </summary>
 /// <param name="spcWidth"></param>
 /// <param name="spcHeight"></param>
 /// <param name="orgWidth"></param>
 /// <param name="orgHeight"></param>
 /// <returns></returns>
 public static PicSize AdjustSize(int spcWidth, int spcHeight, int orgWidth, int orgHeight)
 {
     PicSize size = new PicSize();
     // 原始宽高在指定宽高范围内,不作任何处理 
     if (orgWidth <= spcWidth && orgHeight <= spcHeight)
     {
         size.Width = orgWidth;
         size.Height = orgHeight;
     }
     else {
         // 取得比例系数 
         float w = orgWidth / (float)spcWidth;
         float h = orgHeight / (float)spcHeight;
         // 宽度比大于高度比 
         if (w > h)
         {
             size.Width = spcWidth;
             size.Height = (int)(w >= 1 ? Math.Round(orgHeight / w) : Math.Round(orgHeight * w));
         }
         // 宽度比小于高度比 
         else if (w < h)
         {
             size.Height = spcHeight;
             size.Width = (int)(h >= 1 ? Math.Round(orgWidth / h) : Math.Round(orgWidth * h));
         }
         // 宽度比等于高度比 
         else {
             size.Width = spcWidth;
             size.Height = spcHeight;
         }
     }
     return size;
 }
Exemplo n.º 11
0
        PicSize resizePic(PicSize size)
        {
            if (size.width > medsize.width)
            {
                size.height = size.height * medsize.width / size.width;
                size.width = medsize.width;
            }

            if (size.height > medsize.height)
            {
                size.width = size.width * medsize.height / size.height;
                size.height = medsize.height;
            }

            return size;
        }
Exemplo n.º 12
0
 private static string GetMedFilename(ImageInformation ii, PicSize sz)
 {
     return Path.GetFileNameWithoutExtension(ii.filename)
                                 + "-" + sz.width + "x" + sz.height
                                 + Path.GetExtension(ii.filename);
 }