ทำไมต้องบันทึกเป็นไฟล์ ทำไมไม่บันทึกลงฐานข้อมูล อ่าเป็นคำถามที่ดีมาครับ(ถามเองตอบเอง)
ก็เพราะว่าง่ายต่อการจัดการ และฐานข้อมูลไม่ใหญ่เกินไป
มาลงมือกันเลยครับ!!
- สร้างฟอร์มดังรูปด้านล่าง
- เรียกใช้ Namespace เพิ่มดังนี้
using System.Drawing.Imaging;
using System.IO;
- เขียนโค้ดตามด้านล่างนี้
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Imaging;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
pictureBox1.ImageLocation = @"C:\Users\Miki\Downloads\Insert Retrieve Images From MySQL\Insert Retrieve Images From MySQL\CSharpMySQLBLOBImages\CSharpMySQLBLOBImages\bin\Debug\Images\Image_4.jpg";
}
private void button2_Click(object sender, EventArgs e)
{
if (!Directory.Exists("Images"))
{
Directory.CreateDirectory("Images");
}
pictureBox1.Image.Save(@"Images\Image_4_111.jpg", ImageFormat.Jpeg);
}
private void button3_Click(object sender, EventArgs e)
{
Bitmap bmp = new Bitmap(pictureBox1.Image);
Graphics gr = Graphics.FromImage(bmp);
Pen p = new Pen(Color.Red);
p.Width = 5.0f;
gr.DrawRectangle(p, 1, 2, 30, 40);
pictureBox1.Image = bmp;
}
}
}


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