private void LoadBGImage() { { PreImage_AlphaCover = Properties.Resources.IMG_AlphaCover; } { if (File.Exists("Data/bg.jpg")) { Image image = Image.FromFile("Data/bg.jpg"); Image cloneImage = new Bitmap(image); image.Dispose(); PreImage_BG = (Bitmap)cloneImage; } else { PreImage_BG = Properties.Resources.IMG_BG; } //PreImage_BG = ImageZoom.GetThumbnail(PreImage_BG, PreImage_BG.Height * 1920 / PreImage_BG.Width, 1920); PreImage_BG = ImageEx.SmallPic(PreImage_BG, 1920); { //Bitmap b = new Bitmap(Width, Height); //Graphics g = Graphics.FromImage(); } //PreImage_BG.Save("0.jpg"); Color_PrimaryColor = ColorHelper.GetPrimaryColor(PreImage_BG); Color_SecondColor = ImageEx.ChangeColor(Color_PrimaryColor, -0.75f); PreImage_AlphaCover = (Bitmap)ImageEx.SetImageColorAllWithoutAlpha(PreImage_AlphaCover, Color.Black, Color_SecondColor, 255); //PreImage_AlphaCover.Save("2.png"); PreImage_BG = ImageEx.JoinMImage(PreImage_BG, PreImage_AlphaCover, new Rectangle(0, 0, PreImage_AlphaCover.Width, PreImage_AlphaCover.Height)); //BackgroundImage = PreImage_BG; } { Graphics g; PreImage_Header = new Bitmap(PreImage_BG.Width, Header_Height); g = Graphics.FromImage(PreImage_Header); Rectangle srcRect = new Rectangle(0, 0, PreImage_Header.Width, PreImage_Header.Height); GraphicsUnit units = GraphicsUnit.Pixel; g.DrawImage(PreImage_BG, 0, 0, srcRect, units); g.Save(); g.Dispose(); PreImage_Header = ImageEx.BrightnessP(PreImage_Header, -10); PreImage_Header = GB.ProcessImage(PreImage_Header); //PreImage_Header.Save("1.jpg"); //Bitmap b = new Bitmap(PictureBox_Header.Width, PictureBox_Header.Height); //g = Graphics.FromImage(b); //Pen p = new Pen(Color_PrimaryColor); //g.DrawImage(PreImage_Header, new Rectangle(0, 0, PictureBox_Header.Width, PictureBox_Header.Height), // new Rectangle((PreImage_Header.Width - Width) / 2, 0, Width, Height), GraphicsUnit.Pixel); ////Pen p = new Pen(Color.Red); //g.DrawLine(p, new Point(0, 0), new Point(b.Width, 0)); //g.DrawLine(p, new Point(b.Width - 1, 0), new Point(b.Width - 1, b.Height - 1)); //g.DrawLine(p, new Point(b.Width - 1, b.Height - 1), new Point(0, b.Height - 1)); //g.DrawLine(p, new Point(0, b.Height), new Point(0, 0)); //g.Save(); //g.Dispose(); } ControlNeedRefresh = true; }
private Bitmap GetStudentPhoto(string photoPath) { try { Bitmap res; if (File.Exists(photoPath)) { res = (Bitmap)Image.FromFile(photoPath); } else if ((File.Exists(photoPath + ".jpg"))) { res = (Bitmap)Image.FromFile(photoPath + ".jpg"); } else if ((File.Exists(photoPath + ".png"))) { res = (Bitmap)Image.FromFile(photoPath + ".png"); } else if ((File.Exists(photoPath + ".jpg.jpg"))) { res = (Bitmap)Image.FromFile(photoPath + ".jpg.jpg"); } else { return(null); } //if (res.Height / res.Width > 271.0 / 196.0) res = ImageEx.SmallPicH(res, 271); if (res.Width < 196) { res = ImageEx.SmallPic(res, 196); } //else // res = ImageEx.SmallPic(res, 196); res = ImageEx.CutImage(res, new Rectangle((res.Width - 196) / 2, 0, 196, 271)); return(res); } catch { return(null); } }