『壹』 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;
}