2011年6月29日

关于 Visual Studio 默认创建的不是公共类

我们在使用 Visual Studio 2005/2008/2010 的时候,创建的class默认不是public的,这点大家可能都注意到了,可能有些同学甚至和我一样都有点烦恼了。

 

带着这个疑问上网搜索了一下,在stackoverflow.com上搜到一个帖子(英文原贴),分析的还不错,说默认的类为内部类(internal)是有很多好处的,可以把大部分的功能实现都隐藏在assembly内部,而只把想要公开的类/接口提供给用户。如果你真觉得烦恼,帖子还给出了把默认类创建为public的方法,说是ReSharper就可以,也可以直接修改 Visual Studio 的类模板,模板文件位置在 %ProgramFiles%\Microsoft Visual Studio 8\Common7 IDE\ItemTemplates\CSharp\1033\Class.zip。

 

经本人测试,直接修改此zip文件无效,也可能是由于本人是在 Visual Studio 2008 环境测试的,而此方法只适用于 Visual Studio 2005,反正是修改了 %ProgramFiles%\Microsoft Visual Studio 9.0\Common7\IDE\ItemTemplates\CSharp\Code\1033\Class.zip 这个压缩文件中的Class.cs文件的内容,没有任何效果。最后发现 %ProgramFiles%\Microsoft Visual Studio 9.0\Common7\IDE\ 下面有个 ItemTemplatesCache 文件夹,抱着试试看的想法,修改了 %ProgramFiles%\Microsoft Visual Studio 9.0\Common7\IDE\ItemTemplatesCache\CSharp\Code\1033\Class.zip\Class.cs 文件的内容,在 class 前添加了 public ,保存,重新启动 Visual Studio 2008,创建一个类,OK了!

 

最后声明此法不是正统套路(本人亦不是正统程序员),不太建议使用,仅供参考。

 

posted @ 2011-06-29 21:43 润之 阅读(51) 评论(0) 编辑

2011年6月20日

CKFinder的水印控件的问题

由于项目需要,想在CKFinder上传图片时打上水印,于是放狗一顿狂搜,发现CKSource官方就提供这样一个插件:watermark,正宗的行货水印功能!迫不及待地下载下来安装到plugins目录中,配置config.ascx,随便选了一个logo.gif,打开项目,运行,上传图片,哦耶!搞定!漂亮的半透明水印效果就被加到了图片的右下角!

 

本来书说到这儿也该大圆满结局了,不过天有不测风云,项目有不测变化,BOSS来了一句“水印要放在中间” ,问题跟着来了!watermark这个插件只支持设置水印距离左、下边缘的偏移量,愣是没有设置为中间的选项!无语了,郁闷了,杯具了,浮云了........最后实在木有办法只好到CKSource的官方网站上找答案,发现官网提供的文档还算全面,于是决定自己写个插件,创新咱不会,照官网的葫芦画个瓢应该还是没问题的。折腾了半天,终于搞定了,由于时间紧迫,功能比较单一,就是在中间打个水印,只能在中间,没有选项,而且透明度是50%,都是写死的,暂且凑和用了。

 

代码如下,仅供参考:

 

  1 using System;
  2 using System.Collections.Generic;
  3 using System.Linq;
  4 using System.Text;
  5 using System.IO;
  6 using System.Drawing;
  7 using System.Drawing.Drawing2D;
  8 using System.Drawing.Imaging;
  9 using System.Web;
 10 using System.Web.UI;
 11 using CKFinder;
 12 
 13 namespace CKFinder.Plugins
 14 {
 15     public class RangeonMark : CKFinder.CKFinderPlugin
 16     {
 17         public string JavascriptPlugins
 18         {
 19             get { return ""; }
 20         }
 21 
 22         public void Init(CKFinder.Connector.CKFinderEvent CKFinderEvent)
 23         {
 24             CKFinderEvent.AfterFileUpload +=
 25                   new CKFinder.Connector.CKFinderEvent.Hook(this.RangeonMarkAfterFileUploadCommandEventHandler);
 26         }
 27 
 28         protected void RangeonMarkAfterFileUploadCommandEventHandler(object sender, CKFinder.Connector.CKFinderEventArgs e)
 29         {
 30             if (!File.Exists((string)e.data[1]))
 31             {
 32                 return;
 33             }
 34             try
 35             {
 36                 this.CreateWatermark((string)e.data[1]);
 37             }
 38             catch
 39             {
 40             }
 41         }
 42 
 43         public void CreateWatermark(string sourceFile)
 44         {
 45             MemoryStream ms = new MemoryStream();
 46             Image img = Image.FromFile(sourceFile);
 47             img.Save(ms, img.RawFormat);
 48             byte[] data = ms.GetBuffer();
 49 
 50             ms.Dispose();
 51             img.Dispose();
 52 
 53             CreateWatermark(sourceFile, data);
 54         }
 55 
 56         public void CreateWatermark(string sourceFile, byte[] imgData)
 57         {
 58             string logo = "logo.gif";
 59             string logo_file = logo;
 60             if (!File.Exists(logo_file))
 61             {
 62                 if (File.Exists(HttpContext.Current.Server.MapPath(logo_file)))
 63                 {
 64                     logo_file = HttpContext.Current.Server.MapPath(logo_file);
 65                 }
 66                 else
 67                 {
 68                     logo_file = HttpContext.Current.Server.MapPath(((Page)HttpContext.Current.Handler).ResolveUrl("~/ckfinder/plugins/rangeonmark/" + logo));
 69                     if (!File.Exists(logo_file))
 70                     {
 71                         logo_file = HttpContext.Current.Server.MapPath(((Page)HttpContext.Current.Handler).ResolveUrl("ckfinder/plugins/rangeonmark/" + logo));
 72                         if (!File.Exists(logo_file))
 73                         {
 74                             return;
 75                         }
 76                     }
 77                 }
 78             }
 79 
 80             MemoryStream ms = new MemoryStream(imgData);
 81             Image imgSource = Image.FromStream(ms);
 82             Bitmap bmpOutput = new Bitmap(imgSource.Width, imgSource.Height);
 83             Bitmap bmpLogo = new Bitmap(logo_file);
 84             Graphics g = Graphics.FromImage(bmpOutput);
 85             Bitmap bmpPixel = this.CreateNonIndexedImage(bmpLogo);
 86 
 87             if (bmpLogo.Width > imgSource.Width || bmpLogo.Height > imgSource.Height)
 88             {
 89                 bmpPixel = this.resizeImage(bmpLogo, new Size((bmpLogo.Width > imgSource.Width) ? imgSource.Width : bmpLogo.Width, (bmpLogo.Height > imgSource.Height) ? imgSource.Height : bmpLogo.Height));
 90             }
 91             Bitmap bmpResized = bmpPixel;
 92 
 93             for (int i = 0; i < bmpResized.Width; i++)
 94             {
 95                 for (int j = 0; j < bmpResized.Height; j++)
 96                 {
 97                     Color pixel = bmpResized.GetPixel(i, j);
 98                     if (pixel.A != 0)
 99                     {
100                         bmpPixel.SetPixel(i, j, Color.FromArgb(128, pixel)); // alpha=255 : solid
101                     }
102                 }
103             }
104 
105             int IntX = (imgSource.Width - bmpPixel.Width) / 2;
106             int IntY = (imgSource.Height - bmpPixel.Height) / 2;
107 
108             g.InterpolationMode = InterpolationMode.HighQualityBicubic;
109             ImageFormat rawFormat = imgSource.RawFormat;
110             g.DrawImage(imgSource, 00, imgSource.Width, imgSource.Height);
111             g.DrawImage(bmpPixel, IntX, IntY);
112             imgSource.Dispose();
113             bmpLogo.Dispose();
114             bmpPixel.Dispose();
115             g.Dispose();
116             bmpOutput.Save(sourceFile, rawFormat);
117             imgSource.Dispose();
118 
119         }
120 
121         private Bitmap resizeImage(Image imgToResize, Size size)
122         {
123             int width = imgToResize.Width;
124             int height = imgToResize.Height;
125             float num = (float)size.Width / (float)width;
126             float num2 = (float)size.Height / (float)height;
127             float num3 = (num2 < num) ? num2 : num;
128             int width2 = (int)((float)width * num3);
129             int height2 = (int)((float)height * num3);
130             Bitmap bitmap = new Bitmap(width2, height2);
131             Graphics graphics = Graphics.FromImage(bitmap);
132             graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
133             graphics.DrawImage(imgToResize, 00, width2, height2);
134             graphics.Dispose();
135             return bitmap;
136         }
137 
138         private Bitmap CreateNonIndexedImage(Bitmap src)
139         {
140             Bitmap bitmap = new Bitmap(src.Width, src.Height, PixelFormat.Format32bppArgb);
141             using (Graphics graphics = Graphics.FromImage(bitmap))
142             {
143                 graphics.DrawImage(src, 00);
144             }
145             return bitmap;
146         }
147     }
148 }

 

 水平有限,代码写的比较糙,让各位牛人见笑了。

 

posted @ 2011-06-20 23:09 润之 阅读(371) 评论(2) 编辑

2011年2月20日

简单谈谈存储器的容量缩水问题

可能很多非IT人在购买了大容量的存储设备后会发现,实际的可用容量比标称的要缩水一些,而且随着容量的增大,缩水的比例也在增大。

 

是什么原因导致这个现象呢?是存储器厂商造假了吗?其实这是由于计算方法不同造成的,计算机的算法是按2的10次方即1024来作为1K的,而存储器厂商却是按现实生活普通的千进位即1000来作为1K的,这样,每1K就会相差24(字节),24个字节看起来不算多,可是现在的存储器容量越来越大,这个差异就相当明显了!存储器厂商的这种做法引起很多人的不满,确实有偷工减料的嫌疑!

 

下面举几个例子说明一下:

 

计算机中的算法:

1 = 1B(Byte) = 8b(bit)
1 * 1024 = 1KB
1 * 1024 * 1024 = 1MB
1 * 1024 * 1024 * 1024 = 1GB = 1073741824
 

存储器厂商的算法:

1 = 1B(Byte)
1 * 1000 = 1KB
1 * 1000 * 1000 = 1MB
1 * 1000 * 1000 * 1000 = 1GB = 1000000000
 

每1G存储空间相差:

73741824 / 1024 = 72013.5KB
72013.5KB / 1024 = 70.3256836MB

 

也就是说如果买个标称120GB的硬盘,实际可用容量会缩水120*70=8400MB左右,即8.2GB左右,可用空间应为111.8GB左右。
前几天本人买了个16GB的U盘,可用容量为14.9GB,算一下16 * 70 = 1120 / 1024 = 1.09375GB,也就是说要缩水1.1GB左右,正好是14.9GB。

 


posted @ 2011-02-20 21:29 润之 阅读(16) 评论(0) 编辑

2010年12月22日

糊涂一时

居然浪费了一晚上用来解决Windows Server 2008 R2 和 Windows 7 网上邻居访问的问题!

Win7可以正常访问2008R2的机子,而2008R2的机子竟然死活访问不了Win7的机子,输入Administrator和密码,总是提示密码不正确,上网搜了无数种解决方案,启动Computer Browser、uPnPxxx、SSDPxxx等一堆服务也不行,关闭Windows防火墙也不行,调整家庭网络/公共网络也不行,修改高级文件共享属性也不行,启用GUEST也不行.......总之是方法用尽,最后发现还真是Administrator密码不正确,晕死~!

Win7安装的时候默认是把Administrator禁用了的,当时直接创建了用户和密码,也没在意。把Administrator启用,设置其密码,访问,OK~!

纪念这个白痴的晚上~!

posted @ 2010-12-22 10:57 润之 阅读(16) 评论(0) 编辑

2010年12月13日

FileZilla Server 中文乱码问题

遇到 FileZilla Server 的中文乱码问题,Google得知是由于从0.9.14版开始全面采用了UTF-8编码,而0.9.14之前的版本就不会有这个问题。

 

Google到大多数的解决方案都是下面几中:
1、使用 FileZilla Client 做 FTP 客户端,可以设置其编码。
2、使用 FileZilla Server 0.9.14之前的版本
3、使用 FileZillaPV 补丁:http://sourceforge.net/projects/filezillapv/files/

 

深度Google才发现原来还有更好的解决方法:
如果是使用FlashFXP的话,选择View菜单,选择Raw Command Line,调出 Raw Command 命令行,在其中输入命令:OPTS UTF8 OFF,然后再刷新服务器端显示,就可以正常显示汉字了,也可以在站点属性的高级选项中设置 OPTS UTF8 OFF 为登录后的默认执行命令,个人认为这个方法更好!

 

posted @ 2010-12-13 15:27 润之 阅读(1158) 评论(0) 编辑

2010年8月24日

Windows下的符号链接

摘要: 换了新本本之后,不安于Windows Server 2003 R2了,之前也尝试过Windows Vista / Windows 7 / Windows Server 2008,但最后都由于各种不爽的原因而放弃,主要还是电脑配置太差,这次终于有机会升级系统了,于是装了Windows Server 2008 R2,用了两个月感觉还不错,各方面表现还算凑和,基本上还算爽。发现2008R2的用户目录结构...阅读全文

posted @ 2010-08-24 11:48 润之 阅读(1169) 评论(0) 编辑

2010年7月23日

配置CKEditor和CKFinder

摘要: 这方面的文章相当多,一搜一大把,我就不多说了,说说我遇到的问题。我也是参考网文进行配置的,CKEditor很顺利,没遇到什么问题,网文上说一定要加“class="ckeditor"”,我没加也没出现什么问题。可之后配置CKFinder却总是不行,郁闷了半天。最后发现是网文中CKFinder.SetupCKEditor(null, 'ckfinder/');这句的问题,应该是...阅读全文

posted @ 2010-07-23 06:29 润之 阅读(95) 评论(1) 编辑

导航

<2012年2月>
2930311234
567891011
12131415161718
19202122232425
26272829123
45678910

公告

昵称:润之
园龄:4年
粉丝:0
关注:0

搜索

 
 

常用链接

随笔档案

最新评论

阅读排行榜

评论排行榜

推荐排行榜