11
2015
07

C#图片分割

 

   Bitmap image = new Bitmap(textBox1.Text);//从TextBox里获得图像的路径
    int Height = image.Height;//图像高度
    int Width = image.Width;//图像宽度
    int x = Convert.ToInt32(comboBox1.Text);//横切x份
    int y = Convert.ToInt32(comboBox2.Text);//纵切y份

11
2015
07

c#分割图片代码

 

public static class ImageSplitTool
    {
        public static ImageSource[] SplitImage(BitmapSource source, int tileWidth, int tileHeight)
        {
            var colCount = source.PixelWidth / tileWidth;
            var rowCount = source.PixelHeight / tileHeight;
            var results = new ImageSource[rowCount * colCount];
            var stride = tileWidth * ((source.Format.BitsPerPixel + 7) / 8);
            var pixelsCount = tileWidth * tileHeight;
            var tileRect = new Int32Rect(0, 0, tileWidth, tileHeight);

11
2015
07

C#图片切割,图片压缩,缩略图的生成代码

 

**//// <summary>
    /// 图片切割函数
    /// </summary>
    /// <param name="sourceFile">原始图片文件</param>
    /// <param name="xNum">在X轴上的切割数量</param>
    /// <param name="yNum">在Y轴上的切割数量</param>
    /// <param name="quality">质量压缩比</param>
    /// <param name="outputFile">输出文件名,不带后缀</param>
    /// <returns>成功返回true,失败则返回false</returns>
    public static bool imageCut(String sourceFile, int xNum, int yNum, long quality, String outputFile)
    {
        try
        {
            long imageQuality                        =    quality;
            Bitmap sourceImage                       =    new Bitmap(sourceFile);
            ImageCodecInfo myImageCodecInfo          =    GetEncoderInfo("image/jpeg");
            Encoder myEncoder                        =    Encoder.Quality;
            EncoderParameters myEncoderParameters    =    new EncoderParameters(1);
            EncoderParameter myEncoderParameter      =    new EncoderParameter(myEncoder, imageQuality);
            myEncoderParameters.Param[0]             =    myEncoderParameter;
            float xWidth                             =    sourceImage.Width / xNum;
            float yWidth                             =    sourceImage.Height / yNum;
            String outputImage                       =    "";
           
            for (int countY = 0; countY < yNum; countY++)
                for (int countX = 0; countX < xNum; countX++)
                {

08
2015
06

telerik的RadGrid控件列合并的方法

 

方法1 : 采用  GridTemplateColumn 添加 HeaderTemplate

 

<telerik:RadGrid ID="RadGrid1" runat="server" AllowSorting="True" AutoGenerateColumns="false">
  <MasterTableView>
    <Columns>
      <telerik:GridBoundColumn HeaderText="ContactName" DataField="ContactName" UniqueName="ContactName">
      </telerik:GridBoundColumn>
      <telerik:GridTemplateColumn UniqueName="TemplateColumn">
        <HeaderTemplate>
          <table id="Table1" cellspacing="1" cellpadding="1" width="300" border="1">
            <tr>
              <td colspan="2" align="center">
                <b>Address</b>
              </td>
            </tr>
            <tr>
              <td width="50%">
                <b>City</b>
              </td>
              <td width="50%">
                <b>Postal code</b>
              </td>
            </tr>
          </table>
        </HeaderTemplate>
        <ItemTemplate>
          <table id="Table2" cellspacing="1" cellpadding="1" width="300" border="1">
            <tr>
              <td width="50%">
                <%# DataBinder.Eval(Container.DataItem"City") %>
              </td>
              <td width="50%">
                <%# DataBinder.Eval(Container.DataItem"PostalCode") %>
              </td>
            </tr>
          </table>
        </ItemTemplate>
      </telerik:GridTemplateColumn>
    </Columns>
  </MasterTableView>
</telerik:RadGrid> 

30
2015
05

telerik控件RadGrid分组后无法折叠问题

 一个页面里面放了 一个 telerik 的 RadComboBox ,并且是复选模式;

        <telerik:RadComboBox ID="cbxState" AutoPostBack="true" Enabled="true" CheckedItemsTexts="DisplayAllInInput" DropDownAutoWidth="Disabled" MaxHeight="300"
                                        Localization-CheckAllString="全选" runat="server" CheckBoxes="true" EnableCheckAllItemsCheckBox="true" Width="160px" OnSelectedIndexChanged="ddlMine_SelectedIndexChanged">
       </telerik:RadComboBox>

23
2015
04

若要再次显示该网页,Web浏览器需要重新发送您以前提交的消息

 


网页刷新的时候提示 :

若要再次显示该网页,Web浏览器需要重新发送您以前提交的消息


解决方法

1、提交完成后不要reload,而是location.href='这个页面的地址'
2、提交完成后后台直接Response.Redirect当前页面。
3、设置网页过期 可以试试在后台page_load里面用下面的代码

19
2015
04

asp.net页面中点击按钮传递给Silverlight,并且页面不刷新

转自http://blog.csdn.net/zdw_wym/article/details/7347548 

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Index.aspx.cs" Inherits="test.Index" %> 
 
<!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 runat="server"> 
    <title></title> 
    <script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script> 
    <script src="Silverlight.js" type="text/javascript"></script> 
    <script type="text/javascript"> 
        function onSilverlightError(sender, args) { 
            var appSource = ""; 
            if (sender != null && sender != 0) { 
                appSource = sender.getHost().Source; 
            } 
 
            var errorType = args.ErrorType; 
            var iErrorCode = args.ErrorCode; 
 
            if (errorType == "ImageError" || errorType == "MediaError") { 
                return; 
            } 
 
            var errMsg = "Silverlight 应用程序中未处理的错误 " + appSource + "\n"; 
 
            errMsg += "代码: " + iErrorCode + "    \n"; 
            errMsg += "类别: " + errorType + "       \n"; 
            errMsg += "消息: " + args.ErrorMessage + "     \n"; 
 
            if (errorType == "ParserError") { 
                errMsg += "文件: " + args.xamlFile + "     \n"; 
                errMsg += "行: " + args.lineNumber + "     \n"; 
                errMsg += "位置: " + args.charPosition + "     \n"; 
            } 
            else if (errorType == "RuntimeError") { 
                if (args.lineNumber != 0) { 
                    errMsg += "行: " + args.lineNumber + "     \n"; 
                    errMsg += "位置: " + args.charPosition + "     \n"; 
                } 
                errMsg += "方法名称: " + args.methodName + "     \n"; 
            } 
 
            引发新错误(errMsg); 
        } 
    </script> 
</head> 
<body> 
    <form id="form1" runat="server"> 
    <div> 
        <asp:ScriptManager ID="ScriptManager1" runat="server"> 
        </asp:ScriptManager> 
        <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional"> 
            <ContentTemplate> 
                <input type="button" class="btn-search" value="查询" id="btnSearch" /> 
                <div style="width: 100%; height: 700px"> 
                    <object id="SL" data="data:application/x-silverlight-2," type="application/x-silverlight-2" 
                        width="100%" height="700px"> 
                        <param name="source" value="ClientBin/SL.xap" /> 
                        <param name="onError" value="onSilverlightError" /> 
                        <param name="background" value="white" /> 
                        <param name="minRuntimeVersion" value="4.0.60310.0" /> 
                        <param name="autoUpgrade" value="true" /> 
                        <param name="windowless" value="true" /> 
                        <a href="
http://go.microsoft.com/fwlink/?LinkID=149156&v=4.0.60310.0" style="text-decoration: none"> 
                            <img src="
http://go.microsoft.com/fwlink/?LinkId=161376" alt="获取 Microsoft Silverlight" 
                                style="border-style: none" /> 
                        </a> 
                    </object> 
                </div> 
            </ContentTemplate> 
        </asp:UpdatePanel> 
    </div> 
    </form> 
</body> 
</html> 
<script type="text/javascript" language="javascript"> 
    $(document).ready(function () { 
        $("#btnSearch").click(function () { 
            getMess(); 
        }); 
    }); 
 
    function getMess() { 
        $.post("Index.aspx", { 
            "action": "search", 
            "param": "level" 
        }, function (data) { 
            setTimeout(function () { 
                var slHost = document.getElementById("SL"); 
                var page = slHost.Content.Page; 
                page.process(data); 
            }, 1000); 
        }); 
    } 
</script> 

19
2015
04

ASP.NET传递参数到Silverlight


一、使用InitParams 


在Silverlight宿主页面加载时,我们在ASPX页面中获取参数,并作为初始化参数传递给Silverlight应用程序,如下代码所示:


protected void Page_Load(object sender, EventArgs e)
{
    this.Xaml1.InitParameters = String.Format("username={0},email={1}",
        Request.QueryString["username"],
        Request.QueryString["email"]);
}

29
2015
03

IE11无法显示ReportViewer打印按钮的问题

 

解决方法1 :

a. update "Report Viewer 2012 Runtime" to 11.1.3366
b. update "Microsoft .Net Framework" to 4.5.1
c. reboot system
Our environment: Win server 2008 r2, IIS7, ReportViewer 11

27
2015
03

Silverlight减小XAP文件大小,提高文件加载速度

 

Silverlight项目发布的时候要勾选 “通过使用应用程序库缓存减小XAP大小”,如果引用的是库文件,还需要添加对应的extmap.xml 文件‘


假如项目引用的是库文件,如c:\project\ Microsoft.Windows.Controls.dll,那就在c:\project\ 目录下[不能在silverlight工程的bin\debug下]建立Microsoft.Windows.Controls.extmap.xml,具体内容参考如下:
  <?xml version="1.0"?>
  <manifest xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
   <assembly>
    <name>Microsoft.Windows.Controls</name>
    <version>2.0.21027.1502</version>
    <publickeytoken>31bf3856ad364e35</publickeytoken>
    <relpath>Microsoft.Windows.Controls.dll</relpath>
    <extension downloadUri="Microsoft.Windows.Controls.zip" />
   </assembly>
  </manifest>