banner despecable me2

วันศุกร์ที่ 9 สิงหาคม พ.ศ. 2556

lab20 การเขียนโปรแกรมกราฟฟิกส์ด้วย GDI+4

การโหลดภาพเพื่อแสดงบน Form

 private void Form1_Paint(object sender, PaintEventArgs e)
        {
            Bitmap bmp = new Bitmap("C:\\Users\\chaninthorn\\Desktop\\ws_ALTools-_Valentine's_Quotes_1366x768.jpg");
            this.SetClientSizeCore(bmp.Width + 20, bmp.Height + 20);
            e.Graphics.DrawImage(bmp, 10, 10);
        }


----------------------------------------------
การ Zoom out คือการกำหนดให้ Rectangle ปลายทาง เล็กกว่าขนาดจริงของภาพ

private void Form1_Paint(object sender, PaintEventArgs e)
         {
            Bitmap bmp = new Bitmap("C:\\Users\\chaninthorn\\Desktop\\ws_ALTools-_Valentine's_Quotes_1366x768.jpg");
            Rectangle destrect = new Rectangle(10, 10, bmp.Width / 2, bmp.Height / 2);
            Rectangle srcrect = new Rectangle(0, 0, bmp.Width, bmp.Height);
            this.SetClientSizeCore(destrect.Width + 20, destrect.Height + 20);
            e.Graphics.DrawImage(bmp,destrect, srcrect,GraphicsUnit.Pixel);
        }

-------------------------------------------------

การ Zoom in คือการกำหนดให้ Rectangle ปลายทาง โตกว่า Rectangle ของภาพ ในที่จะเลือกภาพมา
private void Form1_Paint(object sender, PaintEventArgs e)
        {
            Bitmap bmp = new Bitmap("C:\\Users\\chaninthorn\\Desktop\\ws_ALTools-_Valentine's_Quotes_1366x768.jpg");
            Rectangle destrect = new Rectangle(10, 10, bmp.Width, bmp.Height);
            Rectangle srcrect = new Rectangle(0, 0, bmp.Width / 2, bmp.Height / 2);
            this.SetClientSizeCore(destrect.Width + 20, destrect.Height + 20);
            e.Graphics.DrawImage(bmp, destrect, srcrect, GraphicsUnit.Pixel);
        }


------------------------------------------------
การพลิกและหมุนภาพ
private void Form1_Paint(object sender, PaintEventArgs e)
        {
            Bitmap bmp = new Bitmap("C:\\Users\\chaninthorn\\Desktop\\ws_ALTools-_Valentine's_Quotes_1366x768.jpg");
            this.SetClientSizeCore(bmp.Width, bmp.Height);
            Rectangle topleft = new Rectangle(0, 0, bmp.Width / 2, bmp.Height / 2);
            Rectangle topright = new Rectangle(bmp.Width / 2, 0, bmp.Width / 2, bmp.Height / 2);
            Rectangle bottomleft = new Rectangle(0, bmp.Height / 2, bmp.Width / 2, bmp.Height / 2);
            Rectangle bottomRight = new Rectangle(bmp.Width / 2, bmp.Height / 2, bmp.Width / 2, bmp.Height / 2);

            bmp.RotateFlip(RotateFlipType.RotateNoneFlipNone);
            e.Graphics.DrawImage(bmp, topleft);

            bmp.RotateFlip(RotateFlipType.RotateNoneFlipX);
            e.Graphics.DrawImage(bmp, topright);

            bmp.RotateFlip(RotateFlipType.Rotate180FlipNone);
            e.Graphics.DrawImage(bmp, bottomleft);

            bmp.RotateFlip(RotateFlipType.Rotate180FlipY);
            e.Graphics.DrawImage(bmp, bottomRight);
        }

-------------------------------------------------
การเขียนข้อความลงในภาพ


private void Form1_Paint(object sender, PaintEventArgs e)
        {
            Bitmap bmp = new Bitmap("C:\\Users\\chaninthorn\\Desktop\\ws_ALTools-_Valentine's_Quotes_1366x768.jpg");
            this.SetClientSizeCore(bmp.Width, bmp.Height);
            Rectangle destrect = new Rectangle(0, 0, bmp.Width, bmp.Height);
            Brush myBrush = new SolidBrush(Color.Coral);
            e.Graphics.DrawImage(bmp, destrect);
            e.Graphics.DrawString("I LOVE YOU จุฟๆ  ^_______^",
                new Font("Verdana", 25, FontStyle.Bold), myBrush, 0, 0);
        }

ไม่มีความคิดเห็น:

แสดงความคิดเห็น