‘壹’ C# dataset中 datatable如何设置背景图片
【WinForm】:1)直接把图片路径(相对路径或者绝对路径)存在对应的数据表中,然后使用SqlDataAdapter填充到DataTable里,绑定到DataGridView,重写CellFormatting方法显示图片,具体步骤:1、列的类型为DataGridViewImageColumn
2、把你的图片路径字段绑定到改列(你手动添加也可以)
3、通过CellFormatting事件自定义加载图片,比如:
if (dg.Columns[e.ColumnIndex].Name.Equals("图片列的名称"))
{
string path = e.Value.ToString();
e.Value = ShowImage(path);//此出就可以显示图片
}
public System.Drawing.Image ShowImage(string path)
{
System.IO.FileStream fs = new System.IO.FileStream(path, System.IO.FileMode.Open);
System.Drawing.Image result = System.Drawing.Image.FromStream(fs);
fs.Close();
return result;
}2)直接使用System.IO.File.ReadAlBytes方法写入数据库的Image字段,然后使用SqlDataAdapter填充到DataTable里,绑定到DataGridView即可。 【WebForm】1)直接绑定到<image src=<%#Eval("图片路径字段")%>(参考, http://www.microsofttranslator.com/bv.aspx?ref=Internal&from=en&to=zh-chs&a= http://msdn.microsoft.com/zh-cn/library/aa479350.aspx,方法)。2)如果你把图片转化成二进制直接写入数据表,必须使用HttpHandler进行转换后输出(点击, http://blog.csdn.net/lsd123/article/details/3655370,参考)
‘贰’ 如何设置自定义cell 选中 时的 背景 颜色
下面两句代码即可
//cell颜色设置为白色
self.backgroundView=[[UIImageView alloc] initWithImage:[UIImage imageWithColor:[UIColor whiteColor]]];
//cell选中的颜色是淡蓝色
self.selectedBackgroundView=[[UIImageView alloc] initWithImage:[UIImage imageWithColor:UIColorFromRGB(0x81b9ea)]];
说明:
// 其中的【UIColorFromRGB】是宏
#define UIColorFromRGB(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]
// imageWithColor是【UIImage】的类别的扩充 (根据颜色生成一个图片)
+ (UIImage *)imageWithColor:(UIColor *)color
{
CGRect rect = CGRectMake(0, 0, 1, 1);
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
(context, [color CGColor]);
CGContextFillRect(context, rect);
UIImage *image = ();
UIGraphicsEndImageContext();
return image;
}