resizeing image . . . . - c#

hi thanks a lot i have one code below in this code ill upload one image . convert it into
byte code and store it in database .. and retrive it in gridview .. the thing is before
converting it into byte code i want to resize it could u plz tell me what code i should insert here ... thanks a lot .. ...
protected void btnUpload_Click(object sender, EventArgs e)
{
string strID= txtid.Text.ToString();
string strImageName = txtName.Text.ToString();
if (FileUpload1.PostedFile != null &&
FileUpload1.PostedFile.FileName != "")
{
byte[] imageSize = new byte
[FileUpload1.PostedFile.ContentLength];
HttpPostedFile uploadedImage = FileUpload1.PostedFile;
uploadedImage.InputStream.Read
(imageSize, 0, (int)FileUpload1.PostedFile.ContentLength);
// Create SQL Connection
SqlConnection con = new SqlConnection("user id=sa;password=Zoomin#123;database=salary_db;server=192.168.1.100");
// Create SQL Command
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "INSERT INTO image1(ID,ImageName,Image)" +
" VALUES (#ID,#ImageName,#Image)";
cmd.CommandType = CommandType.Text;
cmd.Connection = con;
SqlParameter ID = new SqlParameter
("#ID", SqlDbType.VarChar, 50);
ID.Value = strID.ToString();
cmd.Parameters.Add(ID);
SqlParameter ImageName = new SqlParameter
("#ImageName", SqlDbType.VarChar, 50);
ImageName.Value = strImageName.ToString();
cmd.Parameters.Add(ImageName);
SqlParameter UploadedImage = new SqlParameter
("#Image", SqlDbType.Image, imageSize.Length);
UploadedImage.Value = imageSize;
cmd.Parameters.Add(UploadedImage);
con.Open();
int result = cmd.ExecuteNonQuery();
con.Close();
if (result > 0)
lblMessage.Text = "File Uploaded";
GridView1.DataBind();
}}

You could use the following function:
public void ResizeImage(double scaleFactor, Stream fromStream, Stream toStream)
{
using (var image = Image.FromStream(fromStream))
{
var newWidth = (int)(image.Width * scaleFactor);
var newHeight = (int)(image.Height * scaleFactor);
using (var thumbnailBitmap = new Bitmap(newWidth, newHeight))
using (var thumbnailGraph = Graphics.FromImage(thumbnailBitmap))
{
thumbnailGraph.CompositingQuality = CompositingQuality.HighQuality;
thumbnailGraph.SmoothingMode = SmoothingMode.HighQuality;
thumbnailGraph.InterpolationMode = InterpolationMode.HighQualityBicubic;
var imageRectangle = new Rectangle(0, 0, newWidth, newHeight);
thumbnailGraph.DrawImage(image, imageRectangle);
thumbnailBitmap.Save(toStream, image.RawFormat);
}
}
}
The name of the parameters should be pretty self-explanatory.

Have a look at
Resize an Image C#

Related

How do I insert bitmap into MySQL in c#?

I'm trying to insert my bitmap Image into MySQL but the problem is that bitmap is not supported. My error:"System.NotSupportedException: 'Parameter type Bitmap is not supported; see https://fl.vu/mysql-param-type. Value: System.Drawing.Bitmap'". My picture datatype in MySQL is a blob. I wonder if I should change the datatype?
My button Register
private void buttonRegister_Click(object sender, EventArgs e)
{
String email = textBoxEmail.Text;
String username = textBoxUsername.Text;
String password = textBoxPassword.Text;
String reTypepassword = textBoxReTypePassword.Text;
UsersClass user = new UsersClass();
System.Security.Cryptography.AesCryptoServiceProvider keyMaker = new System.Security.Cryptography.AesCryptoServiceProvider();
keyMaker.KeySize = 128;
keyMaker.BlockSize = 128;
keyMaker.GenerateKey();
byte[] build = keyMaker.Key;
String Key = Convert.ToBase64String(build);
//MessageBox.Show(Key);
string encryptPassword = user.EncryptString(Key, textBoxPassword.Text);
char[] v = encryptPassword.ToCharArray();
int c = 0;
Bitmap bm = new Bitmap(Image);
for (int w = 0; w < bm.Width; w++)
{
for (int h = 0; h < bm.Height; h++)
{
if (v.Length > c)
{
Color pixel = bm.GetPixel(w, h);
bm.SetPixel(w, h, Color.FromArgb(pixel.R, pixel.G, Convert.ToInt32(v[c])));
c++;
}
}
}
Color p = bm.GetPixel(Image.Width - 1, Image.Height - 1);
bm.SetPixel(Image.Width - 1, Image.Height - 1, Color.FromArgb(p.R, p.G, Convert.ToInt32(c)));
Image = (Image)bm;
imageBox.Image = Image;
myconn.openConnection();
if (password == reTypepassword)
{
MySqlCommand cmd = new MySqlCommand("insert into customer values(#id, #username, #email, #password, #Customer_Request,#location,#address,#key, #picture)", myconn.getConnection());
cmd.Parameters.Add(new MySqlParameter("#id", 0));
cmd.Parameters.Add(new MySqlParameter("#username", textBoxUsername.Text));
cmd.Parameters.Add(new MySqlParameter("#email", textBoxEmail.Text));
cmd.Parameters.Add(new MySqlParameter("#password", encryptPassword));
cmd.Parameters.Add(new MySqlParameter("#Customer_Request", ""));
cmd.Parameters.Add(new MySqlParameter("#location", ""));
cmd.Parameters.Add(new MySqlParameter("#address", textBoxAddress.Text));
cmd.Parameters.Add(new MySqlParameter("#key", Key));
cmd.Parameters.Add(new MySqlParameter("#picture", Image));
cmd.ExecuteNonQuery();
MessageBox.Show("Success to insert");
}
else
{
MessageBox.Show("Please enter the correct password");
}
}
This code writes a PNG file (but that could be another type too) to the database, and retrieves it, and stores it to 'test.png'.
using System.IO;
using MySql.Data.MySqlClient;
class Program
{
static void Main(string[] args)
{
string filename = #"D:/MySQL Server 8.0/Uploads/d95251abfa0f532b0b332906de4d3181b033b35e76319b807c4948df4fa5aa95.png";
string Server = "localhost";
string DatabaseName = "test";
string UserName = "test";
string Password = "test";
string connstring = string.Format("Server={0}; database={1}; UID={2}; password={3}", Server, DatabaseName, UserName, Password);
MySqlConnection conn = new MySqlConnection(connstring);
conn.Open();
string sql = "INSERT INTO pic VALUES(#idpic,#caption,#image)";
var cmd = new MySqlCommand(sql, conn);
cmd.Parameters.AddWithValue("#idpic",null);
cmd.Parameters.AddWithValue("#caption","test");
cmd.Parameters.AddWithValue("#image", File.ReadAllBytes(filename));
var result = cmd.ExecuteNonQuery();
var lastId = cmd.LastInsertedId;
Console.WriteLine($"Executing insert resulted in {result}, with idpic={lastId}");
sql = "SELECT img FROM pic WHERE idpic=#id";
cmd = new MySqlCommand(sql, conn);
cmd.Parameters.AddWithValue("#id", lastId);
MySqlDataReader reader = cmd.ExecuteReader();
reader.Read();
byte[] picture = (byte[])reader["img"];
File.WriteAllBytes(#"d:\temp\test.png", picture);
conn.Close();
}
}
The MySQL table was created as follows:
CREATE TABLE `pic` (
`idpic` int unsigned NOT NULL AUTO_INCREMENT,
`caption` varchar(45) NOT NULL,
`img` longblob NOT NULL,
PRIMARY KEY(`idpic`)
) ENGINE=InnoDB AUTO_INCREMENT = 2 DEFAULT CHARSET = utf8mb4 COLLATE=utf8mb4_0900_ai_ci
There are, at least two settings which needs to be checked.
max_allowed_packet Should be set larger than the maximum file size for the picture.
secure_file_priv If this is set, only files from the directory specified can be inserted to your database.
The user that is connecting to the database should be granted FILE access

Datareader not reading image value

i am using datareader at page load to read and store database values in variables, my table includes both nvarchar and image type columns. At page load my 5 images value in database is not read by reader but others are perfectly read.
Byte[] img1 = null;
Byte[] img2 = null;
Byte[] img3 = null;
Byte[] img4 = null;
Byte[] img5 = null;
SqlConnection con = new SqlConnection("Data Source=RAJ-PC\\SQLEXPRESS;Initial Catalog=Finder;Integrated Security=True");
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
loadad();
}
}
protected void loadad()
{
SqlCommand cmd = new SqlCommand("sps_addetails", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("#ad_id", ad_id);
cmd.Parameters.AddWithValue("#useremail", ses);
con.Open();
SqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
rd_iam.SelectedValue = reader["iam"].ToString();
dd_category.SelectedValue = reader["category"].ToString();
c = Convert.ToInt16(reader["category"].ToString());
dd_subcategory.SelectedValue = reader["subcategory"].ToString();
txt_title.Text = reader["title"].ToString();
txt_description.Text = reader["description"].ToString();
txt_pername.Text = reader["contactname"].ToString();
txt_mobile1.Text = reader["mobile1"].ToString();
txt_mobile2.Text = reader["mobile2"].ToString();
txt_landline1.Text = reader["landline1"].ToString();
txt_landline2.Text = reader["landline2"].ToString();
txt_email1.Text = reader["email1"].ToString();
txt_email2.Text = reader["email2"].ToString();
txt_website.Text = reader["website"].ToString();
dd_country.Text = reader["country"].ToString();
d = Convert.ToInt16(reader["country"].ToString());
dd_state.Text = reader["state"].ToString();
txt_pincode.Text = reader["pincode"].ToString();
txt_address.Text = reader["address"].ToString();
txt_lat.Text = reader["latitude"].ToString();
txt_lon.Text = reader["longitude"].ToString();
img1 = (byte[])reader["image1"];
img2 = (byte[])reader["image2"];
img3 = (byte[])reader["image3"];
img4 = (byte[])reader["image4"];
img5 = (byte[])reader["image5"];
}
con.Close();
}
And stored procedure sps_addetails is
ALTER PROCEDURE [dbo].[sps_addetails]
#ad_id int,
#useremail nvarchar(100)
AS
BEGIN
select * from dbo.tbl_adregister where useremail=#useremail and ad_id=#ad_id
END
aspx
<asp:FileUpload ID="FileUpload1" runat="server" />
update button functionality is (aspx.cs)
Byte[] imgbytes1 = null;
if (FileUpload1.HasFile)
{
HttpPostedFile file1 = FileUpload1.PostedFile;
imgbytes1 = new Byte[file1.ContentLength];
file1.InputStream.Read(imgbytes1, 0, file1.ContentLength);
}
else
{
imgbytes1 = img1;
}
con.Open();
SqlCommand cmd = new SqlCommand("sps_uploadphoto", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("#imagedata1", imgbytes1);
cmd.ExecuteNonQuery();
con.Close();
Try first determining the image size, then instantiating the variables, and then use the GetBytes() method:
int index = reader.GetOrdinal("image1");
Int64 size = 0;
try { size = reader.GetBytes(index , 0, null, 0, int.MaxValue); }
catch { size = reader.GetBytes(index, 0, img1, 0, 1); }
img1 = new Byte[size];
reader.GetBytes(index, 0, img1, 0, img1.Length);
... rinse and repeat for images 2 through 5 ...
Let us know if that gets it for you.
Reading image value is different from others...
<img runat="server" id="image1" alt="" src="" height="100" width="100" />
protected void LoadImage1()
{
SqlCommand cmd = new SqlCommand("sps_getimage", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("#flag", 1);
cmd.Parameters.AddWithValue("#ad_id", ad_id);
con.Open();
SqlDataReader reader = cmd.ExecuteReader(System.Data.CommandBehavior.SequentialAccess);
if (reader.HasRows)
{
reader.Read();
MemoryStream memory = new MemoryStream();
long startIndex = 0;
const int ChunkSize = 256;
while (true)
{
byte[] buffer = new byte[ChunkSize];
long retrievedBytes = reader.GetBytes(0, startIndex, buffer, 0, ChunkSize);
memory.Write(buffer, 0, (int)retrievedBytes);
startIndex += retrievedBytes;
if (retrievedBytes != ChunkSize)
break;
}
byte[] data = memory.ToArray();
img1 = data;
memory.Dispose();
image1.Src = "data:image/png;base64," + Convert.ToBase64String(data);
}
con.Close();
}

How to convert string to image?

private void btnread_Click(object sender, EventArgs e)
{
MySqlConnection connection = new MySqlConnection(MyConnectionString);
connection.Open();
MySqlCommand cmd = connection.CreateCommand();
cmd.CommandText = "SELECT imagecol FROM imgtable WHERE id = 17";
MySqlDataAdapter adap = new MySqlDataAdapter(cmd);`enter code here`
DataTable dt = new DataTable();
adap.Fill(dt);
string b = dt.Rows[0]["imagecol"].ToString();
byte[] storedImage = System.Text.Encoding.ASCII.GetBytes(b);
byte[] ss = (byte[])dt.Rows[0]["imagecol"];
Image newImage;
using (MemoryStream stream = new MemoryStream(storedImage))
{
newImage = Image.FromStream(stream);
}
//// Display to make sure code works
picbox.Image = newImage;
connection.Close();
}
You don't need to convert to byte[] to string then back to byte[] using ASCII.GetBytes.
This should solve your problem.
using (MemoryStream stream = new MemoryStream(ss))
{
newImage = Image.FromStream(stream);
}
Side note: Give proper names for members even when you write a sample application. ss is not meaningful.

Resize image before storing it into a folder in asp.net c#

I want to resize Profile picture before storing it into a folder in asp.net .What will be technique to resize it ?? Here is my code for image upload.
Any help will be appreciated..Thanks!
protected void btnUpload_Click(object sender, EventArgs e)
{
StartUpLoad();
}
private void StartUpLoad()
{
//get the file name of the posted image
string imgName = fileuploadImage.FileName.ToString();
//sets the image path
string imgPath = "ImageStorage/" + imgName;
fileuploadImage.SaveAs(Server.MapPath(imgPath));
//get the size in bytes that
int imgSize = fileuploadImage.PostedFile.ContentLength;
//validates the posted file before saving
if (fileuploadImage.PostedFile != null && fileuploadImage.PostedFile.FileName != "")
{
if (fileuploadImage.PostedFile.ContentLength > 102400)
{
Page.ClientScript.RegisterClientScriptBlock(typeof(Page), "Alert", "alert('File is too big')", true);
}
else
{
//save the file
//Call the method to execute Insertion of data to the Database
ExecuteInsert(imgName, imgSize, imgPath);
Response.Write("Save Successfully!");
}
}
}
private string GetConnectionString()
{
//sets the connection string from your web config file. "DBConnection" is the name of your Connection String
return System.Configuration.ConfigurationManager.ConnectionStrings["ParkingProjectConnectionString"].ConnectionString;
}
private void ExecuteInsert(string name, int size, string path)
{
SqlConnection conn = new SqlConnection(GetConnectionString());
string sql = "INSERT INTO ImageInfo (ImageName, ImageSize, ImagePath) VALUES "
+ " (#imgName,#imgSize,#imgPath)";
try
{
conn.Open();
SqlCommand cmd = new SqlCommand(sql, conn);
SqlParameter[] param = new SqlParameter[3];
param[0] = new SqlParameter("#imgName", SqlDbType.NVarChar, 50);
param[1] = new SqlParameter("#imgSize", SqlDbType.BigInt, 9999);
param[2] = new SqlParameter("#imgPath", SqlDbType.VarChar, 50);
param[0].Value = name;
param[1].Value = size;
param[2].Value = path;
for (int i = 0; i < param.Length; i++)
{
cmd.Parameters.Add(param[i]);
}
cmd.CommandType = CommandType.Text;
cmd.ExecuteNonQuery();
}
catch (System.Data.SqlClient.SqlException ex)
{
string msg = "Insert Error:";
msg += ex.Message;
throw new Exception(msg);
}
finally
{
conn.Close();
}
}
This Code works for me.
protected void Button1_Click(object sender, EventArgs e)
{
if (FileUpload1.HasFile)
{
FileUpload1.PostedFile.SaveAs(Server.MapPath("~/Test/") + "test.jpg");
string pth = Server.MapPath("~/Test/test.jpg");
resizeImageAndSave(pth);
}
}
private string resizeImageAndSave(string imagePath)
{
System.Drawing.Image fullSizeImg
= System.Drawing.Image.FromFile(imagePath);
var thumbnailImg = new Bitmap(150, 130);
var thumbGraph = Graphics.FromImage(thumbnailImg);
thumbGraph.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
thumbGraph.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
thumbGraph.InterpolationMode =System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
var imageRectangle = new Rectangle(0, 0, 150, 130);
thumbGraph.DrawImage(fullSizeImg, imageRectangle);
string targetPath = imagePath.Replace(Path.GetFileNameWithoutExtension(imagePath), Path.GetFileNameWithoutExtension(imagePath) + "-resize");
thumbnailImg.Save(targetPath, System.Drawing.Imaging.ImageFormat.Jpeg); //(A generic error occurred in GDI+) Error occur here !
thumbnailImg.Dispose();
return targetPath;
}
Try this code:
private Image resizeImageAndSave(string imagePath)
{
Size wantedSize = new Size(250, 180);
Image fullImg = Image.FromFile(imagePath);
Bitmap resizedImg = new Bitmap(fullImg, wantedSize);
return (Image)resizedImg;
}

How to display images with fixed dimensions in ASP.NET after retrieving them from a MySQL database

Following are the links which describe connection to MySQL:
http://www.codeproject.com/KB/aspnet/asp_net_and_mysql.aspx
http://www.codeproject.com/KB/aspnet/image_asp.aspx
Here is the code to display image from mysql database:
protected void Page_Load(object sender, EventArgs e)
{
MySqlConnection conn = new MySqlConnection(db);
conn.Open();
string s;
s = Session["t"].ToString();
string commantext = "select img_id,img_file,img_type,img_name from image where img_name='"+s+"'";
// string commantext = "select img_id,img_file,img_type,img_name from image";
// DataSet ds = MySqlHelper.ExecuteDataset(conn, commantext);
MySqlCommand cmd = new MySqlCommand(commantext,conn);
cmd.Parameters.Add("?img_id", MySqlDbType.Int32).Value = s;
// DataTable dt = ds.Tables[0];
DataTable dt = GetData(cmd);
while(dt !=null)
{
Byte[] bytes = (Byte[])dt.Rows[0]["img_file"];
// Byte[] bytes = (Byte[])dt.Rows[1][] ;
Response.Buffer = true;
Response.Charset = "";
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentType = dt.Rows[0]["img_type"].ToString();
Response.AddHeader("content-disposition", "attachment;filename="
+ dt.Rows[0]["img_name"].ToString());
Response.BinaryWrite(bytes);
Response.Flush();
Response.End();
}
conn.Close();
}
private DataTable GetData(MySqlCommand cmd)
{
DataTable dt = new DataTable();
//String strConnString = System.Configuration.ConfigurationManager.ConnectionStrings["conString"].ConnectionString;
MySqlConnection con = new MySqlConnection(db);
MySqlDataAdapter sda = new MySqlDataAdapter();
cmd.CommandType = CommandType.Text;
cmd.Connection = con;
try
{
con.Open();
sda.SelectCommand = cmd;
sda.Fill(dt);
return dt;
}
catch
{ return null;
}
finally
{ con.Close();
sda.Dispose();
con.Dispose();
}
}
My code to upload image file to mysql database is as below.
protected void Button1_Click(object sender, EventArgs e)
{
Stream img_strm = File1.PostedFile.InputStream;
int img_len = File1.PostedFile.ContentLength;
string strtype = File1.PostedFile.ContentType;
//code snippet to determine image height and width.
System.Drawing.Image i = System.Drawing.Image.FromStream(img_strm);
int fileheight = int.Parse(i.Width.ToString());
int filewidth = int.Parse(i.Height.ToString());
strname = Text1.Value;
//Session["t"] = strname;
byte[] imgData = new byte[img_len];
int n = img_strm.Read(imgData, 0, img_len);
int result = saveToDb(strname, imgData, strtype);
}
private int saveToDb(string imgName, byte[] imgbin, string imgContenttype)
{
string db = "server=localhost;database=test;uid=root;password=techsoft";
MySqlConnection conn = new MySqlConnection(db);
MySqlCommand cmd = new MySqlCommand("insert into image(img_name,img_file,img_type) values(?img_name,?img_file,?img_type)", conn);
//MySqlParameter param0 = new MySqlParameter("?img_id", MySqlDbType.Int16, 20);
//param0.Value = ;
//cmd.Parameters.Add(param0);
MySqlParameter param0 = new MySqlParameter("?img_name", MySqlDbType.VarChar, 45);
param0.Value = imgName;
cmd.Parameters.Add(param0);
// MySqlParameter param1 = new MySqlParameter("?img_file", MySqlDbType.VarChar, 45);
MySqlParameter param1 = new MySqlParameter("?img_file", MySqlDbType.LongBlob, 10);
param1.Value = imgbin;
cmd.Parameters.Add(param1);
MySqlParameter param2 = new MySqlParameter("?img_type", MySqlDbType.VarChar, 45);
param2.Value = imgContenttype;
cmd.Parameters.Add(param2);
conn.Open();
int num = cmd.ExecuteNonQuery();
conn.Close();
return num;
}
I have used binary writer to display. Can anybody suggest how to display images in fixed dimensions?
I would resize the images on the page being used to display them. Where are they being displayed?
or
I would resize the images at the time they are saved
Assuming your only challenge is to only scale the images(either before uploading or when retrieving them)...here is some code i use to get scaled dimensions for an image (to fit specific fixed dimensions)...you can stick this somewhere in an imaging class
Note that there are many approaches...
public static Size getScaledDimensions( Image img, Int32 maxW, Int32 maxH)
{
//check if image is already within desired dimensions
if (img.Height <= maxH & img.Width <= maxW)
{
Size orgsize = new Size(img.Width, img.Height);
return orgsize; // no need to rescale
}
else //proceed with rescaling
{
int finalH;
int finalW;
//use height/width ratio to determine our new dimensions
double hwRatio = (double)img.Height / (double)img.Width;
int newW = (int) (maxH/ hwRatio);
int newH = (int) (hwRatio * maxW);
//make sure we scale the right dimension
if (newW <= maxW) // scale width
{
finalH = maxH;
finalW = newW;
}
else
{ // scale height
finalH = newH;
finalW = maxW;
}//end if
Size newsize = new Size(finalW, finalH);
return newsize;
}
Thanks for all the support from rip and The_AlienCoder for their answers. I have found out answer to my own query.
We need to use streams to convert binary data from mysql database. Later graphic library should be used to load the streams. In the meantime we need to resize the image according to our need.
protected void Page_Load(object sender, EventArgs e){
//Create connection to mysql database.
MySqlConnection conn = new MySqlConnection(db);
conn.Open();
string s;
s = Session["t"].ToString();
string commantext = "select img_id,img_file,img_type,img_name from image where img_name='"+s+"'";
MySqlCommand cmd = new MySqlCommand(commantext,conn);
cmd.Parameters.Add("?img_id", MySqlDbType.Int32).Value = s;
//create datatable. GetData is a method to fetch the data.
DataTable dt = GetData(cmd);
//Get data from database to bytes.
Byte[] bytes = (Byte[])dt.Rows[0]["img_file"];
//Defining the size to display data.
int outputSize = 100;
if (bytes.Length > 0)
{
// Open a stream for the image and write the bytes into it
System.IO.MemoryStream stream = new System.IO.MemoryStream(bytes, true);
stream.Write(bytes, 0, bytes.Length);
Bitmap bmp = new Bitmap(stream);
Size new_size = new Size();
//resize based on the longer dimension
if (bmp.Width > bmp.Height)
{
new_size.Width = outputSize;
new_size.Height = (int)(((double)outputSize / (double)bmp.Width) * (double)bmp.Height);
}
else
{
new_size.Width = (int)(((double)outputSize / (double)bmp.Height) * (double)bmp.Width);
new_size.Height = outputSize;
}
Bitmap bitmap = new Bitmap(new_size.Width, new_size.Height, bmp.PixelFormat);
Graphics new_g = Graphics.FromImage(bitmap);
new_g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
new_g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
new_g.DrawImage(bmp, -1, -1, bitmap.Width + 1, bitmap.Height + 1);
bmp.Dispose();
bitmap.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
bitmap.Dispose();
new_g.Dispose();
stream.Close();
}
}
private DataTable GetData(MySqlCommand cmd)
{
DataTable dt = new DataTable();
//String strConnString = System.Configuration.ConfigurationManager .ConnectionStrings["conString"].ConnectionString;
MySqlConnection con = new MySqlConnection(db);
MySqlDataAdapter sda = new MySqlDataAdapter();
cmd.CommandType = CommandType.Text;
cmd.Connection = con;
try
{
con.Open();
sda.SelectCommand = cmd;
sda.Fill(dt);
return dt;
}
catch
{ return null;
}
finally
{ con.Close();
sda.Dispose();
con.Dispose();
}
}
}

Categories