Pages

Thursday, March 31, 2011

Edit htm Pages Using CKeditor

in Web.Config File
<appSettings>
<add key=”ImageRoot” value=”~/images/”/>
<add key=”FilesRoot” value=”~/files/”/>
</appSettings>
EditStaticPages.aspx Page
<%@ Page Language=”C#” AutoEventWireup=”true”  CodeFile=”EditStaticPages.aspx.cs” Inherits=”_Default” ValidateRequest=”false”  %>
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head id=”Head1″ runat=”server”>
<title>Edit Static Pages</title>
<script type=”text/javascript” src=”http://13.cdn.blog.com/wp-admin/ckeditor/ckeditor.js”></script>
<script type=”text/javascript” language=”JavaScript1.2″ src=”http://13.cdn.blog.com/wp-admin/../Scripts/positions.js”></script>
<script    type=”text/javascript” language=”JavaScript1.2″ src=”http://13.cdn.blog.com/wp-admin/../Scripts/Events.js”></script>
<style type=”text/css”>
*{
font-family:Calibri;
font-size:10pt;
text-align: left;
font-weight: 700;
}
#ContentArea
{
font-family: Calibri;
font-size:12px;
}
.style1
{
width: 146px;
}
</style>
</head>
<body>
<form id=”form1″ runat=”server”>
<table style=”width: 900px; height: 427px”>
<tr>
<td >
Select a Static Page to edit</td>
<td >
<table>
<tr>
<td>  <asp:DropDownList ID=”ddlContlst” runat=”server” Width=”285px”
AutoPostBack=”True” onselectedindexchanged=”ddlContlst_SelectedIndexChanged”>
</asp:DropDownList>
</td>
<td>
<asp:RequiredFieldValidator ID=”RequiredFieldValidator1″ runat=”server”
ControlToValidate=”ddlContlst” ErrorMessage=”Please Select a Static Page”
InitialValue=”Select” ValidationGroup=”Validity”>*</asp:RequiredFieldValidator>
<asp:Image id=”Image4″ runat=”server” ImageUrl=”~/Images/Req.gif”></asp:Image></td>
<td style=”padding-left:20px”><asp:HyperLink ID=”lnk_preview” Target=”_blank”  runat=”server” Text=”Preview”></asp:HyperLink></td>
<td> <asp:HiddenField ID=”HiddenVal” runat=”server” /> </td>
</tr></table>
</td>
</tr>
<tr>
<td colspan=”2″>
<textarea id =”Editor1″ name=”editor1″ runat=”server”
style=”width:98%; height: 340px; position: static;” wrap=”off”>
</textarea>
</td>
</tr>
<tr>
<td style=”padding-right:10px;” colspan=”2″ align=”right”>
<asp:Button ID=”Btn_Save” runat=”server” OnClick=”Button1_Click” Text=”Save”
Width=”54px” ValidationGroup=”Validity” Height=”24px” />&nbsp
<asp:ValidationSummary ID=”ValidationSummary1″ runat=”server”
ShowMessageBox=”True” ShowSummary=”False” ValidationGroup=”Validity” />
</td>
</tr>
</table>
<script type=”text/javascript” >
CKEDITOR.replace(‘Editor1′);
CKEDITOR.on(‘dialogDefinition’, function(ev) {
if (ev.data.name == ‘image’) {
var btn = ev.data.definition.getContents(‘info’).get(‘browse’);
btn.hidden = false;
btn.onClick = function() { window.open(CKEDITOR.basePath + ‘ImageBrowser.aspx’, ‘popuppage’, ‘scrollbars=no,width=860,height=710,left=100,top=150,resizable=no,toolbar=no,titlebar=no’); };
}
if (ev.data.name == ‘link’) {
var btn = ev.data.definition.getContents(‘info’).get(‘browse’);
btn.hidden = false;
btn.onClick = function() { window.open(CKEDITOR.basePath + ‘LinkBrowser.aspx’, ‘popuppage’, ‘scrollbars=no,width=520,height=580,left=’ + ((screen.width – 520) / 2) + ‘,top=’ + ((screen.height – 580) / 2) + ‘,resizable=no,toolbar=no,titlebar=no’); };
}

});
</script>
</form>
</body>
</html>
—————
EditStaticPages.aspx.cs file
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Net.Mail;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Text.RegularExpressions;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(Server.MapPath(“~/StaticPages”));
foreach (System.IO.FileInfo f in dir.GetFiles(“*.*”))
{
ListItem itm = new ListItem();
itm.Text = f.Name.Substring(0, f.Name.IndexOf(“.”));
itm.Value = f.Name;
ddlContlst.Items.Add(itm);
}
ddlContlst.Items.Insert(0, “Select”);
lnk_preview.Visible = false;
}
}
protected void Button1_Click(object sender, EventArgs e)
{
string FilePathSave = HiddenVal.Value;//TextBox1.Text;
File.WriteAllText(FilePathSave, Editor1.InnerText);
ClientScript.RegisterStartupScript(this.GetType(), “msg”, “<script>alert(‘Update Successful’)</script>”);
}
protected void ddlContlst_SelectedIndexChanged(object sender, EventArgs e)
{
GetPreviewPath(ddlContlst.SelectedIndex);
if (ddlContlst.SelectedIndex > 0)
{
string urlstr;
string tmp = Request.Url.AbsoluteUri;
int LastIndex = tmp.LastIndexOf(“/”);
tmp = tmp.Substring(0, LastIndex);
if (Page.AppRelativeTemplateSourceDirectory.Length > 2)
{
LastIndex = tmp.LastIndexOf(“/”);
tmp = tmp.Substring(0, LastIndex);
}
urlstr = tmp + “/StaticPages/” + ddlContlst.SelectedValue;
HiddenVal.Value = Request.PhysicalApplicationPath + “StaticPages\\” + ddlContlst.SelectedValue;
string strAddYahooComPage;
System.Net.HttpWebRequest reqFirstPage = (System.Net.HttpWebRequest)WebRequest.Create(urlstr);
System.Net.HttpWebResponse resAddYahooCom = (System.Net.HttpWebResponse)reqFirstPage.GetResponse();
System.IO.StreamReader srAddYahooComUrl = new StreamReader(resAddYahooCom.GetResponseStream());
strAddYahooComPage = srAddYahooComUrl.ReadToEnd();
Editor1.InnerHtml = strAddYahooComPage;
}
}
private void GetPreviewPath(int index)
{
switch(index)
{
case 0: lnk_preview.Visible = false;
break;
case 1:
lnk_preview.Visible = true;
lnk_preview.NavigateUrl = “~/About.aspx”;
break;
case 2:
lnk_preview.Visible = true;
lnk_preview.NavigateUrl = “~/Academics.aspx”;
break;
case 3:
lnk_preview.Visible = true;
lnk_preview.NavigateUrl = “~/Administration.aspx”;
break;
case 4:
lnk_preview.Visible = true;
lnk_preview.NavigateUrl = “~/Alumni.aspx”;
break;
case 5:
lnk_preview.Visible = true;
lnk_preview.NavigateUrl = “~/ContactUs.aspx”;
break;
case 6:
lnk_preview.Visible = true;
lnk_preview.NavigateUrl = “~/Departments.aspx”;
break;
case 7:
lnk_preview.Visible = true;
lnk_preview.NavigateUrl = “~/Facilities.aspx”;
break;
case 8:
lnk_preview.Visible = true;
lnk_preview.NavigateUrl = “/FAQs.aspx”;
break;
case 9:
lnk_preview.Visible = true;
lnk_preview.NavigateUrl = “~/Links.aspx”;
break;
case 10:
lnk_preview.Visible = true;
lnk_preview.NavigateUrl = “~/PhotoGallery.aspx”;
break;
case 11:
lnk_preview.Visible = true;
lnk_preview.NavigateUrl = “~/Placements.aspx”;
break;
case 12:
lnk_preview.Visible = true;
lnk_preview.NavigateUrl = “~/PrivacyPolicy.aspx”;
break;
case 13:
lnk_preview.Visible = true;
lnk_preview.NavigateUrl = “~/RandD.aspx”;
break;
case 14:
lnk_preview.Visible = true;
lnk_preview.NavigateUrl = “~/Rules.aspx”;
break;
case 15:
lnk_preview.Visible = true;
lnk_preview.NavigateUrl = “~/Staff.aspx”;
break;
case 16:
lnk_preview.Visible = true;
lnk_preview.NavigateUrl = “~/StudentLife.aspx”;
break;
case 17:
lnk_preview.Visible = true;
lnk_preview.NavigateUrl = “~/TermsofService.aspx”;
break;
default:
lnk_preview.Visible = false;
break;
}
}
}
————-
Down load the CKeditor from here
—————–
in CKeditor folder create a file as ImageBrowser.aspx
<%@ Page Language=”C#” AutoEventWireup=”true” MaintainScrollPositionOnPostback=”true” CodeFile=”ImageBrowser.aspx.cs” Inherits=”ImageBrowserPage” %>
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head id=”Head1″ runat=”server”>
<title>Image Browser</title>
<style type=”text/css”>
body { margin: 0px; }
form { width:750px; background-color: #E3E3C7; }
h1 { padding: 15px; margin: 0px; padding-bottom: 0px; font-family:Arial; font-size: 14pt; color: #737357; }
</style>
</head>
<body>
<form id=”form1″ runat=”server”>
<div>
<asp:ScriptManager ID=”ScriptManager1″ runat=”server” />
<h1>Image Browser</h1>
<asp:UpdatePanel ID=”UpdatePanel1″ runat=”server”>
<ContentTemplate>
<table cellpadding=”10″ cellspacing=”0″ border=”1″ style=”background-color:#F1F1E3; margin:15px;”>
<tr>
<td style=”width: 400px; height:470″ valign=”middle” align=”center”>
<div style=”width:385px; height:455px; overflow:scroll”>
<asp:Image ID=”Image1″ runat=”server” />
</div>
</td>
<td style=”width: 324px;” valign=”top”>
Folders:<br />
<asp:DropDownList ID=”DirectoryList” runat=”server” Style=”width: 160px;” OnSelectedIndexChanged=”ChangeDirectory” AutoPostBack=”true” />
<asp:Button ID=”DeleteDirectoryButton” runat=”server” Text=”Delete” OnClick=”DeleteFolder” OnClientClick=”return confirm(‘Are you sure you want to delete this folder and all its contents?’);” Visible=”false” />
<asp:HiddenField ID=”NewDirectoryName” runat=”server” />
<asp:Button ID=”NewDirectoryButton” runat=”server” Text=”New” OnClick=”CreateFolder” Visible=”false”/>
<br /><br />
<asp:Panel ID=”SearchBox” runat=”server” DefaultButton=”SearchButton”>
Search:<br />
<asp:TextBox ID=”SearchTerms” runat=”server”/>
<asp:Button ID=”SearchButton” runat=”server” Text=”Go” OnClick=”Search” UseSubmitBehavior=”false” />
<br />
</asp:Panel>
<asp:ListBox ID=”ImageList” runat=”server” Style=”width: 280px; height: 180px;” OnSelectedIndexChanged=”SelectImage” AutoPostBack=”true” />
<asp:HiddenField ID=”NewImageName” runat=”server” />
<asp:Button ID=”RenameImageButton” runat=”server” Text=”Rename” OnClick=”RenameImage” />
<asp:Button ID=”DeleteImageButton” runat=”server” Text=”Delete” OnClick=”DeleteImage” OnClientClick=”return confirm(‘Are you sure you want to delete this image?’);” />
<br />
<br />
Size:<br />
<asp:TextBox ID=”ResizeWidth” runat=”server” Width=”50″ OnTextChanged=”ResizeWidthChanged” />
x
<asp:TextBox ID=”ResizeHeight” runat=”server” Width=”50″ OnTextChanged=”ResizeHeightChanged” />
<asp:HiddenField ID=”ImageAspectRatio” runat=”server” />
<asp:Button ID=”ResizeImageButton” runat=”server” Text=”Resize Image” OnClick=”ResizeImage” Visible=”false” /><br />
<asp:Label ID=”ResizeMessage” runat=”server” ForeColor=”Red” />
<br /><br />
Upload Image:
<asp:FileUpload ID=”UploadedImageFile” runat=”server” />
<asp:Button ID=”UploadButton” runat=”server” Text=”Upload” OnClick=”Upload” /><br />
<br />
</td>
</tr>
</table>
<center>
<asp:Button ID=”OkButton” runat=”server” Text=”Ok” OnClick=”Clear” />
<asp:Button ID=”CancelButton” runat=”server” Text=”Cancel” OnClientClick=”window.top.close(); window.top.opener.focus();” OnClick=”Clear” />
<br /><br />
</center>
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID=”UploadButton” />
</Triggers>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>
——-
ImageBrowser.aspx.cs
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Web.UI;
using System.Web.UI.WebControls;
using Image = System.Drawing.Image;
using System.Linq;
using System.IO;
using System.Configuration;
using System.Web.Security;
using System.Collections.Generic;
using System.Web;
using System.Collections;
using System.Runtime.InteropServices;
public partial class ImageBrowserPage : Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindDirectoryList();
ChangeDirectory(null, null);
NewDirectoryButton.OnClientClick = “var name = prompt(‘Enter name of folder:’); if (name == null || name == ”) return false; document.getElementById(‘” + NewDirectoryName.ClientID + “‘).value = name;”;
}
ResizeMessage.Text = “”;
ScriptManager.RegisterStartupScript(this, this.GetType(), “FocusImageList”, “window.setTimeout(\”document.getElementById(‘” + ImageList.ClientID + “‘).focus();\”, 1);”, true);
}
protected void BindDirectoryList()
{
ImageFolder = “”;
string[] directories = Directory.GetDirectories(FileImageFolder);
directories = Array.ConvertAll<string, string>(directories, delegate(string directory) { return directory.Substring(directory.LastIndexOf(‘\\’) + 1); });
DirectoryList.DataSource = directories;
DirectoryList.DataBind();
DirectoryList.Items.Insert(0, “EditorImages”);
}
protected void ChangeDirectory(object sender, EventArgs e)
{
DeleteDirectoryButton.Enabled = (DirectoryList.SelectedIndex != 0);
ImageFolder = (DirectoryList.SelectedIndex == 0) ? “” : DirectoryList.SelectedValue + “/”;
SearchTerms.Text = “”;
BindImageList();
SelectImage(null, null);
}
protected void DeleteFolder(object sender, EventArgs e)
{
Directory.Delete(FileImageFolder, true);
BindDirectoryList();
ChangeDirectory(null, null);
}
protected void CreateFolder(object sender, EventArgs e)
{
string name = UniqueDirectory(NewDirectoryName.Value);
Directory.CreateDirectory(FileImageFolderRoot + name);
BindDirectoryList();
DirectoryList.SelectedValue = name;
ChangeDirectory(null, null);
}
protected void BindImageList()
{
ImageList.Items.Clear();
string[] files = Directory.GetFiles(FileImageFolder, “*” + SearchTerms.Text.Replace(” “, “*”) + “*”);
foreach (string file in files)
{
if (IsImage(file))
ImageList.Items.Add(file.Substring(file.LastIndexOf(‘\\’) + 1));
}
if (files.Length > 0)
ImageList.SelectedIndex = 0;
}
protected void Search(object sender, EventArgs e)
{
BindImageList();
}
protected void SelectImage(object sender, EventArgs e)
{
RenameImageButton.Enabled = (ImageList.Items.Count != 0);
DeleteImageButton.Enabled = (ImageList.Items.Count != 0);
ResizeImageButton.Enabled = (ImageList.Items.Count != 0);
ResizeWidth.Enabled = (ImageList.Items.Count != 0);
ResizeHeight.Enabled = (ImageList.Items.Count != 0);
if (ImageList.Items.Count == 0)
{
Image1.ImageUrl = “”;
ResizeWidth.Text = “”;
ResizeHeight.Text = “”;
return;
}
Image1.ImageUrl = ImageFolder + ImageList.SelectedValue + “?” + new Random().Next(1000);
Image img = Image.FromFile(FileImageFolder + ImageList.SelectedValue);
ResizeWidth.Text = img.Width.ToString();
ResizeHeight.Text = img.Height.ToString();
ImageAspectRatio.Value = “” + img.Width / (float)img.Height;
img.Dispose();
int pos = ImageList.SelectedItem.Text.LastIndexOf(‘.’);
if (pos == -1)
return;
RenameImageButton.OnClientClick = “var name = prompt(‘Enter new filename:’,'” + ImageList.SelectedItem.Text.Substring(0, pos) + “‘); if (name == null || name == ”) return false; document.getElementById(‘” + NewImageName.ClientID + “‘).value = name + ‘” + ImageList.SelectedItem.Text.Substring(pos) + “‘;”;
OkButton.OnClientClick = “window.top.opener.CKEDITOR.dialog.getCurrent().setValueOf(‘info’, ‘txtUrl’, encodeURI(‘” + ImageFolder + ImageList.SelectedValue.Replace(“‘”, “\\’”) + “‘)); window.top.close(); window.top.opener.focus();”;
}
protected void RenameImage(object sender, EventArgs e)
{
string filename = UniqueFilename(NewImageName.Value);
File.Move(FileImageFolder + ImageList.SelectedValue, FileImageFolder + filename);
BindImageList();
ImageList.SelectedValue = filename;
SelectImage(null, null);
}
protected void DeleteImage(object sender, EventArgs e)
{
File.Delete(FileImageFolder + ImageList.SelectedValue);
BindImageList();
SelectImage(null, null);
}
protected void ResizeWidthChanged(object sender, EventArgs e)
{
float ratio = Util.Parse<float>(ImageAspectRatio.Value);
int width = Util.Parse<int>(ResizeWidth.Text);
ResizeHeight.Text = “” + (int)(width / ratio);
}
protected void ResizeHeightChanged(object sender, EventArgs e)
{
float ratio = Util.Parse<float>(ImageAspectRatio.Value);
int height = Util.Parse<int>(ResizeHeight.Text);
ResizeWidth.Text = “” + (int)(height * ratio);
}
protected void ResizeImage(object sender, EventArgs e)
{
int width = Util.Parse<int>(ResizeWidth.Text);
int height = Util.Parse<int>(ResizeHeight.Text);
Image img = Image.FromFile(FileImageFolder + ImageList.SelectedValue);
Image resizedImage = img.Resize(width, height,null);
img.Dispose();
File.Delete(FileImageFolder + ImageList.SelectedValue);
EncoderParameters encoderParams = new EncoderParameters(2);
encoderParams.Param[0] = new EncoderParameter(Encoder.Quality, 80L);
encoderParams.Param[1] = new EncoderParameter(Encoder.ColorDepth, 24L);
resizedImage.Save(FileImageFolder + ImageList.SelectedValue, GetImageCodec(ImageList.SelectedValue), encoderParams);
resizedImage.Dispose();
ResizeMessage.Text = “Image successfully resized!”;
SelectImage(null, null);
}
protected void Upload(object sender, EventArgs e)
{
if (IsImage(UploadedImageFile.FileName))
{
string filename = UniqueFilename(UploadedImageFile.FileName);
UploadedImageFile.SaveAs(FileImageFolder + filename);
var data = UploadedImageFile.FileBytes.ToImage().Resize(null, null, null).ToByteArray();
FileStream file = File.Create(FileImageFolder + filename);
file.Write(data, 0, data.Length);
file.Close();
BindImageList();
ImageList.SelectedValue = filename;
SelectImage(null, null);
}
else
{
ClientScript.RegisterStartupScript(this.GetType(), “msg”, “<Script>alert(‘The file must have an extension of jpg or gif or bmp or jpeg or png’)</Script>”);
}
}
protected void Clear(object sender, EventArgs e)
{
Session.Remove(“viewstate”);
}
//util methods
private bool IsImage(string file)
{
//return (GetImageCodec(file) != null);
return file.EndsWith(“.jpg”, StringComparison.CurrentCultureIgnoreCase) ||
file.EndsWith(“.gif”, StringComparison.CurrentCultureIgnoreCase) ||
file.EndsWith(“.bmp”, StringComparison.CurrentCultureIgnoreCase) ||
file.EndsWith(“.jpeg”, StringComparison.CurrentCultureIgnoreCase) ||
file.EndsWith(“.png”, StringComparison.CurrentCultureIgnoreCase);
}
protected ImageCodecInfo GetImageCodec(string file)
{
foreach (ImageCodecInfo codec in ImageCodecInfo.GetImageEncoders())
{
foreach (string ext in codec.FilenameExtension.Split(‘;’))
{
if (file.EndsWith(ext.Substring(1), StringComparison.CurrentCultureIgnoreCase))
return codec;
}
}
return null;
}
protected string UniqueFilename(string filename)
{
string newfilename = filename;
for (int i = 1; File.Exists(FileImageFolder + newfilename); i++)
{
newfilename = filename.Insert(filename.LastIndexOf(‘.’), “(” + i + “)”);
}
return newfilename;
}
protected string UniqueDirectory(string directoryname)
{
string newdirectoryname = directoryname;
for (int i = 1; Directory.Exists(FileImageFolderRoot + newdirectoryname); i++)
{
newdirectoryname = directoryname + “(” + i + “)”;
}
return newdirectoryname;
}
//properties
protected string ImageFolderRoot
{
get
{ return ResolveUrl(ConfigurationManager.AppSettings["ImageRoot"]); }
}
protected string FileImageFolderRoot
{
get { return Server.MapPath(ImageFolderRoot); }
}
protected string ImageFolder
{
get { return ImageFolderRoot + ViewState["folder"]; }
set { ViewState["folder"] = value; }
}
protected string FileImageFolder
{
get { return Server.MapPath(ImageFolder); }
}
}
———–
in App_Code    create a Class file called util.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.IO;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
public static class Util
{
public static T Parse<T>(object value)
{
try { return (T)System.ComponentModel.TypeDescriptor.GetConverter(typeof(T)).ConvertFrom(value.ToString()); }
catch (Exception) { return default(T); }
}
public static Image ToImage(this byte[] data)
{
MemoryStream stream = new MemoryStream(data.Length);
stream.Write(data, 0, data.Length);
stream.Seek(0L, SeekOrigin.Begin);
return Image.FromStream(stream);
}
public static byte[] ToByteArray(this Image img)
{
MemoryStream resized = new MemoryStream();
img.Save(resized, ImageFormat.Jpeg);
return resized.ToArray();
}
public static Image Resize(this Image image, int? width, int? height, Color? background)
{
if (width == null && height == null || width == 0 && height == 0)
return image;
int w = (width == null || width == 0) ? image.Width : width.Value;
int h = (height == null || height == 0) ? image.Height : height.Value;
float desiredRatio = (float)w / h;
float scale, posx, posy;
float ratio = (float)image.Width / image.Height;
if (image.Width < w && image.Height < h)
{
scale = 1f;
posy = (h – image.Height) / 2f;
posx = (w – image.Width) / 2f;
}
else if (ratio > desiredRatio)
{
scale = (float)w / image.Width;
posy = (h – (image.Height * scale)) / 2f;
posx = 0f;
}
else
{
scale = (float)h / image.Height;
posx = (w – (image.Width * scale)) / 2f;
posy = 0f;
}
if (!background.HasValue)
{
w = (int)(image.Width * scale);
h = (int)(image.Height * scale);
posx = 0f;
posy = 0f;
}
Image resizedImage = new Bitmap(w, h);
Graphics g = Graphics.FromImage(resizedImage);
g.SmoothingMode = SmoothingMode.HighQuality;
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
g.PixelOffsetMode = PixelOffsetMode.HighQuality;
if (background.HasValue)
g.FillRectangle(new SolidBrush(background.Value), 0, 0, w, h);
g.DrawImage(image, posx, posy, image.Width * scale, image.Height * scale);
foreach (PropertyItem item in image.PropertyItems)
resizedImage.SetPropertyItem(item);
return resizedImage;
}
}

No comments:

Post a Comment