예제 #1
0
 public ExtraImageModel(int id, ExtraImage extraImage, ImageSource imageSource)
 {
     Id          = id;
     ExtraImage  = extraImage;
     ImageSource = imageSource;
     Location    = new Point(ExtraImage.X, ExtraImage.Y);
     Size        = new Size(ExtraImage.Width, ExtraImage.Height);
 }
예제 #2
0
        public BitmapSource LoadImageFromExtraImage(ExtraImage item, BitmapSource extraImage)
        {
            var image = new WriteableBitmap(item.Width, item.Height, 96, 96, PixelFormats.Pbgra32, null);
            var rect  = new Int32Rect(item.X, item.Y, item.Width, item.Height);

            image.Lock();
            extraImage.CopyPixels(rect, image.BackBuffer, image.BackBufferStride * image.PixelHeight, image.BackBufferStride);
            image.Unlock();
            image.Freeze();
            return(image);
        }
예제 #3
0
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (ExtraImage != null)
                {
                    ExtraImage.Dispose();
                }
            }

            base.Dispose(disposing);
        }
예제 #4
0
        private void UpdateImage()
        {
            if (counter <= 0)
            {
                ShowExtraImage = false;

                if (ExtraImage != null)
                {
                    ExtraImage.Dispose();
                }

                ExtraImage = null;
            }
            else
            {
                int    size = Height - (ExtraImagePadding * 2);
                Bitmap bmp  = new Bitmap(size, size);

                using (Graphics g = Graphics.FromImage(bmp))
                    using (Brush shadowBrush = new SolidBrush(Color.FromArgb(150, 0, 0, 0)))
                        using (Brush brush = new SolidBrush(Color.FromArgb(230, 0, 0)))
                            using (Font font = new Font("Arial", 9, FontStyle.Bold))
                                using (StringFormat stringFormat = new StringFormat())
                                {
                                    g.SmoothingMode   = SmoothingMode.HighQuality;
                                    g.PixelOffsetMode = PixelOffsetMode.Half;
                                    g.DrawRoundedRectangle(shadowBrush, null, new Rectangle(0, 1, bmp.Width, bmp.Height), 3);
                                    g.DrawRoundedRectangle(brush, null, new Rectangle(0, 0, bmp.Width, bmp.Height), 3);
                                    stringFormat.Alignment     = StringAlignment.Center;
                                    stringFormat.LineAlignment = StringAlignment.Center;
                                    string text;
                                    if (Counter > 9)
                                    {
                                        text = "+";
                                    }
                                    else
                                    {
                                        text = Counter.ToString();
                                    }
                                    g.DrawString(text, font, Brushes.White, new Rectangle(0, 0, bmp.Width, bmp.Height), stringFormat);
                                }

                if (ExtraImage != null)
                {
                    ExtraImage.Dispose();
                }

                ExtraImage     = bmp;
                ShowExtraImage = true;
            }
        }
예제 #5
0
        public ActionResult AddExtraImage(HttpPostedFileBase[] images, ExtraImageViewModel model)
        {
            ExtraImage extraImage = new ExtraImage();

            byte[] bytes;

            //UserId And UserName
            int    PostId   = Convert.ToInt32(TempData["PostId"]);
            string PostName = Convert.ToString(TempData["PostName"]);
            int    user_id  = Convert.ToInt32(TempData["user_id"]);

            //var ID = Request.Cookies["USERID"].Value;
            //int user_id = Convert.ToInt32(ID);



            foreach (HttpPostedFileBase image in images)
            {
                using (BinaryReader br = new BinaryReader(image.InputStream))
                {
                    bytes = br.ReadBytes(image.ContentLength);
                }
                extraImage.ExtraPostName    = PostName;
                extraImage.ExtraPostId      = PostId;
                extraImage.ExtraImgName     = Path.GetFileName(image.FileName);
                extraImage.ExtraContentType = image.ContentType;
                extraImage.ExtraImgData     = bytes;
                extraImage.ExtraUserId      = user_id;
                extraImage.ExtraIsActive    = true;
                extraImage.ExtraIsDeleted   = false;
                extraImage.ExtraImgDate     = DateTime.Now;

                _ctx.extraPost.Add(extraImage);
                _ctx.SaveChanges();
            }
            return(RedirectToRoute("FirstPage"));
        }