/// <summary> /// show the top 6 images on the home page /// </summary> /// <returns></returns> public ActionResult Index() { var pageSize = 6; var picManager = new PicManager(); ViewBag.pics = picManager.GetPics(pageSize).ToList(); return View(); }
public PicSelectorViewModel(Page page, PhotoSelectorOptions options) { this.options = options; CancelCommand = new Command(async() => { CropViewModel.PicSelectionResult.UserCancelled = true; await Application.Current.MainPage.Navigation.PopModalAsync(); }); DoneCommand = new Command(async() => { CropViewModel.PicSelectionResult.UserCancelled = false; await Application.Current.MainPage.Navigation.PopModalAsync(); }); ChangePhotoCommand = new Command(async fake => { await CrossMedia.Current.Initialize(); var canTakePhoto = CrossMedia.Current.IsTakePhotoSupported; var canSelectPhoto = CrossMedia.Current.IsPickPhotoSupported; string selectedOption = null; if (canTakePhoto && canSelectPhoto) { var buttonText = new[] { options.TakePhotoText, options.SelectPhotoText }; selectedOption = await page.DisplayActionSheet(null, CancelText, null, buttonText); } else if (canTakePhoto) { selectedOption = options.TakePhotoText; } else if (canSelectPhoto) { selectedOption = options.SelectPhotoText; } else { //TODO: How to internationalize these strings await page.DisplayAlert("No Photo Support", "This device does not support taking or selecting photos", "Ok"); selectedOption = null; } MediaFile selected = null; if (selectedOption == options.TakePhotoText) { selected = await CrossMedia.Current.TakePhotoAsync(new StoreCameraMediaOptions()); } else if (selectedOption == options.SelectPhotoText) { selected = await CrossMedia.Current.PickPhotoAsync(); } if (selected != null) { var pic = await PicManager.LoadAsync(new Uri(selected.Path)); CropViewModel.LoadImage(pic); BugHound.Info($"Setting selected photo to: {selected.Path}"); } }); }
public async Task InitializeAsync() { if (options.InitialPhoto != null) { BugHound.Debug($"Loading initial photo: {options.InitialPhoto}"); var initialPic = await PicManager.LoadAsync(options.InitialPhoto); CropViewModel.LoadImage(initialPic); //CropViewModel.PicSelectionResult.Selected = initialPic; BugHound.Debug($"Done loading initial photo: {options.InitialPhoto}"); } }
public PicAppService( IRepository <Picture> pictureRepo, IRepository <User, long> userRepo, IRepository <PicViewRecord> picViewRecordRepo, IRepository <PicFavRelation> picFavRelationRepo, PicManager picManager) { this._pictureRepo = pictureRepo; this._userRepo = userRepo; this._picViewRecordRepo = picViewRecordRepo; this._picManager = picManager; this._picFavRelationRepo = picFavRelationRepo; }
//private DataTable dt=new DataTable("dt"); public frmMain() { InitializeComponent(); j_rData = new J_RehooData(); opFont = new FontManager(6, Application.StartupPath + @"\Output", "fontChars.h", "font.c"); opPic = new PicManager(Application.StartupPath + @"\Output\PIC", "App_Resource_Offset.h"); this.jsave += this.SaveToServer; //this.jServer += this.GetServerData; this.jCreate += this.CreateFiles; }
public ActionResult Index(HttpPostedFileBase file) { try { var picManager = new PicManager(); var uri = picManager.SavePic(Request.Files[0].InputStream); Response.Write(uri); Response.End(); return RedirectToAction("Index"); } catch { return View(); } }
//private void upImage() //{ // if (FileUpload1.HasFile) // { // //判断上传的文件是否是图片类型 // if (input.IsImgString(FileUpload1.PostedFile.FileName)) // { // HttpPostedFile myFile = FileUpload1.PostedFile;//获取上传的文件 // int filelen = myFile.ContentLength; // byte[] myData = new byte[filelen]; // myFile.InputStream.Read(myData, 0, filelen); // FileStream newFile = new FileStream(FileUpload1.PostedFile.FileName, FileMode.Create); // newFile.Write(myData, 0, myData.Length); // System.Drawing.Image img = System.Drawing.Image.FromStream(newFile); // string imgNewName = input.ReDateTime("yyyyMMddHHmmssff") + ".jpg"; // string startPath = "~/AllUpLoadPic/" + imgNewName; // string filePath = Server.MapPath(startPath); // FileUpload1.SaveAs(filePath);//保存图片 // img_teacherPhoto.ImageUrl = startPath; // //生成缩略图 // Bitmap ImgFile = new Bitmap(filePath); // Bitmap tectSmalImg = CreateSmallImg.CreateThumbnail(ImgFile, 100, 100, true); // tectSmalImg.Save(Server.MapPath("~/AllUpLoadPic" + imgNewName)); // Session["smallImgPath"] = "~/AllUpLoadPic/" + imgNewName;//缩略图的位置 // btn_upload.CommandArgument = startPath;//将图片路径存起来 // //显示新上传的图片的信息 // lb_fileName.Text = FileUpload1.FileName; // lb_filePath.Text = "~/AllUpLoadPic/"; // lb_fileSize.Text = img.Width.ToString() + "*" + img.Height.ToString(); // //PicID.Text= // newFile.Dispose();//释放FileStream // FileUpload1.Enabled = false; // btn_upload.Enabled = false; // } // else // { // ClientDeal.JsAlert("请选择图片类型的文件!"); // } // } //} private void startUploadimg() { if (this.FileUpload1.HasFile) //检查是否有文件 { string fullFileName = this.FileUpload1.PostedFile.FileName; //文件路径名 string fileName = fullFileName.Substring(fullFileName.LastIndexOf("\\") + 1); //图片名称 string type = fullFileName.Substring(fullFileName.LastIndexOf(".") + 1).ToLower(); //图片格式 //fileName = realImageName() + "." + type; fileName = realImageName() + "." + type; if (type == "jpg" || type == "gif" || type == "bmp" || type == "jpeg") //判断是否为图片类型 { if (this.FileUpload1.PostedFile.ContentLength > 3072 * 1024) { Response.Write("<script>alert('上传图片必须小于3M!');</script>"); } else { this.img_teacherPhoto.ImageUrl = "~/AllUpLoadPic/" + fileName; //显示图片 //Response.Write("<script>alert('" + img_teacherPhoto.ImageUrl + "');</script>"); string path = HttpContext.Current.Request.MapPath("~/AllUpLoadPic/"); //获取上传文件的网站目录路径," this.FileUpload1.SaveAs(path + fileName); //存储文件到磁盘 //Response.Write("<script>alert('图片上传成功!');</script>");//提示 //upLoadDetail.Visible = true; double flen = (double)this.FileUpload1.PostedFile.ContentLength / 1024 / 1024; //decimal flen1 = Convert.ToDecimal(flen); //upLoadDetail.Text = "上传图片的名称是:" + fullFileName + "<br/>" + "存库名称为:" + fileName + "<br/>" + "格式是:" + type.ToString() + "<br/>" + "大小:" + flen.ToString() + "MB"; } HttpPostedFile myFile = FileUpload1.PostedFile;//获取上传的文件 int filelen = myFile.ContentLength; byte[] myData = new byte[filelen]; myFile.InputStream.Read(myData, 0, filelen); FileStream newFile = new FileStream(FileUpload1.PostedFile.FileName, FileMode.Create); newFile.Write(myData, 0, myData.Length); System.Drawing.Image img = System.Drawing.Image.FromStream(newFile); // string imgNewName = input.ReDateTime("yyyyMMddHHmmssff") + ".jpg"; //System.Drawing.Image img = System.Drawing.Image.FromStream(newFile); string startPath = "~/AllUpLoadPic/" + fileName; string filePath = Server.MapPath(startPath); //生成缩略图 Bitmap ImgFile = new Bitmap(filePath); Bitmap tectSmalImg = new Bitmap(ImgFile, 100, 100); //Bitmap tectSmalImg = CreateSmallImg.CreateThumbnail(ImgFile, 100, 100, true); //tectSmalImg.Save(Server.MapPath("~/AllUpLoadPic" + fileName)); Session["smallImgPath"] = "~/AllUpLoadPic" + fileName; //缩略图的位置 btn_upload.CommandArgument = startPath; //将图片路径存起来 //显示新上传的图片的信息 lb_fileName.Text = FileUpload1.FileName; lb_filePath.Text = "~/AllUpLoadPic/"; lb_fileSize.Text = img.Width.ToString() + "*" + img.Height.ToString(); //PicID.Text= newFile.Dispose();//释放FileStream FileUpload1.Enabled = true; btn_upload.Enabled = true; //保存到数据库 int a = -1; //Response.Write("<script>alert('"+fileName+"');</script>"); a = new PicManager().InsertPicInfo(fileName, "好美,我要上!", img.Height, img.Width); if (a == 0) { ; } } else { Response.Write("<script>alert('非图片类型,不允许上传!');</script>"); } } else { Response.Write("<script>alert('必须指定文件!');</script>"); } //this.FileUpload1.PostedFile.SaveAs(Server.MapPath("~/Images/")+FileUpload1.FileName); //this.Image1.ImageUrl = "~/Images/" + FileUpload1.FileName; }
public async Task <IHttpActionResult> PostPicture() { try { var encoded = await Request.Content.ReadAsStringAsync(); var bytes = Convert.FromBase64String(encoded); var json = Encoding.ASCII.GetString(bytes); var final = JsonConvert.DeserializeObject <IDictionary <string, object> >(json); //Gather attributes string uid = (string)final["uid"]; string mime = (string)final["mime"]; //Sanitize first, will save as uri encoded = encoded.Replace("/", ""); encoded = encoded.Replace("+", ""); encoded = encoded.Replace("=", ""); //Generate PID //p(encodedFirstTen)(uid skip3 then Ten)(Random 2 digit numb)(encodedreversedFive); string picid = (string)"p" + encoded.Substring(0, 10) + uid.Substring(3, 10) + new Random().Next(10, 99) + encoded.Substring(50, 5); Debug.WriteLine("\nCreated Pic:\n" + picid); //Get b64 string pic64 = (string)final["data"]; //Sav Picture [returns path] string path = PicManager.SavePicture(pic64, uid, picid, mime); //Create pics object Pic pic = new Pic(); //Assign Attributes //Dates pic.CreationDate = DateTime.Now; pic.ModifiedDate = DateTime.Now; //Check dates Debug.WriteLine("DATECHECK => " + pic.CreationDay + " " + pic.CreationMonth + " "); //Mandatory! pic.Uid = uid; pic.Pid = picid; pic.Location = path; pic.Name = (string)final["name"]; //Everything else is optional, you can serialize it to the database now! //Check for Location if (final.ContainsKey("Lon")) { pic.Lon = (string)final["Lon"]; pic.Lat = (string)final["Lat"]; } await session.Add(pic); //Return ok return(new OkResult(Request)); } catch (Exception e) { //Return bad Debug.WriteLine(e.Message); return(new BadRequestErrorMessageResult(e.Message, this)); } }