public ActionResult ShowPictures(int TypeId, string objectType)
        {
            ObjectFactory factory   = new ObjectFactory(repository);
            IAddImage     editImage = factory.CreateObject(objectType);

            List <HolidayApp.Entities.Image> images = editImage.GetImages(TypeId);

            List <EditImageModel> list = new List <EditImageModel>();

            AddPictureType addpicture = (AddPictureType)Enum.Parse(typeof(AddPictureType), objectType);


            if (images != null)
            {
                foreach (var item in images)
                {
                    list.Add(new EditImageModel()
                    {
                        Id = item.ImageId, TypeId = TypeId, type = addpicture, imagePath = item.ImagePath
                    });
                }
            }


            return(View(list));
        }
예제 #2
0
        /// <summary>
        /// 添加图片
        /// </summary>
        /// <param name="dc"></param>
        /// <param name="path"></param>
        public static void AddPicture(this XWPFDocument doc, string path, AddPictureType pType)
        {
            if (path.IndexOf("http") != -1)
            {
                //byte[] bytes = ExcelUtil.getFile(path);
                WebRequest   request  = WebRequest.Create(path);
                WebResponse  response = request.GetResponse();
                Stream       s        = response.GetResponseStream();
                byte[]       data     = new byte[response.ContentLength];
                int          length   = 0;
                MemoryStream ms       = new MemoryStream();
                while ((length = s.Read(data, 0, data.Length)) > 0)
                {
                    ms.Write(data, 0, length);
                }
                ms.Seek(0, SeekOrigin.Begin);

                //using (Stream stt = new MemoryStream(bytes))
                //{
                CT_P p = doc.GetNewP();
                p.SetAlign(ST_Jc.center);
                XWPFParagraph gp  = new XWPFParagraph(p, doc);
                XWPFRun       run = gp.CreateRun();
                run.AddPicture(ms, (int)PictureType.PNG, "2.png", 1000000, 1000000);
                ms.Close();
                //stt.Close();
                //}
            }
            //else if(path.IndexOf(";base64") != -1)
            //{
            //    int index = path.IndexOf(",");
            //    path = path.Substring(index + 1);
            //    byte[] bytes = Convert.FromBase64String(path);
            //    using (Stream s64 = new MemoryStream(bytes))
            //    {
            //        CT_P p = doc.GetNewP();
            //        p.SetAlign(ST_Jc.center);
            //        XWPFParagraph gp = new XWPFParagraph(p, doc);
            //        XWPFRun run = gp.CreateRun();
            //        run.AddPicture(s64, (int)PictureType.PNG, "1.png", 1000000, 1000000);
            //        s64.Close();
            //    }
            //}
            //else
            //{
            //    using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read))
            //    {
            //        CT_P p = doc.GetNewP();
            //        p.SetAlign(ST_Jc.center);
            //        XWPFParagraph gp = new XWPFParagraph(p, doc);
            //        XWPFRun run = gp.CreateRun();
            //        run.AddPicture(fs, (int)PictureType.PNG, "1.png", 1000000, 1000000);
            //        fs.Close();
            //    }
            //}
        }