Exemplo n.º 1
0
        public virtual void ImageStreamFromFileID(HttpContext context)
        {
            YZRequest   request = new YZRequest(context);
            string      fileid  = request.GetString("fileid", null);
            ScaleMode   scale   = request.GetEnum <ScaleMode>("scale", ScaleMode.None);
            ImageFormat format  = YZImageHelper.ParseImageFormat(request.GetString("format", "png"));

            int width  = 0;
            int height = 0;

            if (scale != ScaleMode.None)
            {
                width  = request.GetInt32("width");
                height = request.GetInt32("height");
            }

            AttachmentInfo attachment;
            string         filePath = this.GetImageFileFromFileID(fileid, scale, width, height, format, out attachment);

            if (String.IsNullOrEmpty(filePath))
            {
                if (attachment == null)
                {
                    filePath = context.Server.MapPath("~/YZSoft/Attachment/img/EmptyImageAttachment.png");
                }
                else
                {
                    if (YZMimeMapping.isVedioFile(attachment.Ext))
                    {
                        filePath = context.Server.MapPath("~/YZSoft/Attachment/img/EmptyImageAttachment.png");
                    }
                    else
                    {
                        filePath = context.Server.MapPath("~/YZSoft/Attachment/img/EmptyImageAttachment.png");
                    }
                }
            }

            string fileName = Path.GetFileNameWithoutExtension(attachment == null ? "empty.png" : attachment.Name);

            if (String.IsNullOrEmpty(Path.GetExtension(filePath))) //原图
            {
                fileName += attachment.Ext;
            }
            else
            {
                fileName += Path.GetExtension(filePath);
            }

            this.ProcessResponseHeader(context, fileName, true);
            context.Response.TransmitFile(filePath);
        }
Exemplo n.º 2
0
        public JObject Base64ImageFromFileID(HttpContext context)
        {
            YZRequest   request = new YZRequest(context);
            string      fileid  = request.GetString("fileid", null);
            ScaleMode   scale   = request.GetEnum <ScaleMode>("scale", ScaleMode.None);
            ImageFormat format  = YZImageHelper.ParseImageFormat(request.GetString("format", "png"));

            int width  = 0;
            int height = 0;

            if (scale != ScaleMode.None)
            {
                width  = request.GetInt32("width");
                height = request.GetInt32("height");
            }

            AttachmentInfo attachment;
            string         filePath = this.GetImageFileFromFileID(fileid, scale, width, height, format, out attachment);

            if (String.IsNullOrEmpty(filePath))
            {
                if (YZMimeMapping.isVedioFile(attachment.Ext))
                {
                    filePath = context.Server.MapPath("~/YZSoft/Attachment/img/EmptyImageAttachment.png");
                }
                else
                {
                    filePath = context.Server.MapPath("~/YZSoft/Attachment/img/EmptyImageAttachment.png");
                }
            }

            string fileName = Path.GetFileNameWithoutExtension(attachment.Name) + Path.GetExtension(filePath);

            Bitmap       bmp = new Bitmap(filePath);
            MemoryStream ms  = new MemoryStream();

            bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
            byte[] arr = new byte[ms.Length];
            ms.Position = 0;
            ms.Read(arr, 0, (int)ms.Length);
            ms.Close();

            JObject rv = new JObject();

            rv["base64"] = Convert.ToBase64String(arr);
            return(rv);
        }
Exemplo n.º 3
0
        protected virtual string GetImageFile(AttachmentInfo attachment, ScaleMode scale, int width, int height, ImageFormat format)
        {
            if (attachment == null)
            {
                return(null);
            }

            string filePath;

            if (YZMimeMapping.isVedioFile(attachment.Ext))
            {
                filePath = this.GetVideoOutputFile(attachment, scale, width, height, format, null);
            }
            else
            {
                filePath = this.GetImageOutputFile(attachment, scale, width, height, format, null);
            }

            return(filePath);
        }
Exemplo n.º 4
0
        public object GetImageSize(HttpContext context)
        {
            YZRequest request = new YZRequest(context);
            string    fileid  = request.GetString("fileid");
            Size      size;

            AttachmentInfo attachment;

            using (IYZDbProvider provider = YZDbProviderManager.DefaultProvider)
            {
                using (IDbConnection cn = provider.OpenConnection())
                {
                    attachment = AttachmentManager.TryGetAttachmentInfo(provider, cn, fileid);
                }
            }

            if (attachment == null)
            {
                size = new Size(55, 47);
            }
            else
            {
                if (attachment.LParam1 != -1)
                {
                    size = new Size(attachment.LParam1 / 10000, attachment.LParam1 % 10000);
                }
                else
                {
                    string filePath = this.GetImageFile(attachment, ScaleMode.None, 0, 0, null);
                    if (!String.IsNullOrEmpty(filePath))
                    {
                        size = this.GetImageSize(filePath);
                        attachment.LParam1 = size.Width * 10000 + size.Height;

                        using (IYZDbProvider provider = YZDbProviderManager.DefaultProvider)
                        {
                            using (IDbConnection cn = provider.OpenConnection())
                            {
                                AttachmentManager.Update(provider, cn, attachment);
                            }
                        }
                    }
                    else
                    {
                        if (YZMimeMapping.isVedioFile(attachment.Ext))
                        {
                            size = new Size(55, 47);
                        }
                        else
                        {
                            size = new Size(55, 47);
                        }
                    }
                }
            }

            return(new {
                width = size.Width,
                height = size.Height
            });
        }