C#怎样读取数据库中Image类型在线等!!

C#怎样读取数据库中Image类型在线等!!,第1张

存进去了就可以用流文件读出来 然后绘制到屏幕上

class MyBitmap

{

private int width;//位图的宽

public int Width

{

get { return width; }

set { width = value; }

}

private int height;//位图的高

public int Height

{

get { return height; }

set { height = value; }

}

private int postColor;//颜色深度

public int PostColor

{

get { return postColor; }

set { postColor = value; }

}

private Bitmap mBitmap;//位图内置对象,引用系统内置Bitmap

public Bitmap MBitmap

{

get { return mBitmap; }

set { mBitmap = value; }

}

/// <summary>

/// 构造方法,构造一个Bitmap类

/// </summary>

/// <param name="fileurl">文件路径,包含文件名</param>

public MyBitmap(string fileurl)

{

FileStream fs = new FileStream(fileurl, FileModeOpen);//引用文件 *** 作流

fsSeek(18, 0);//将流的初始值设为19,即跳过18位

int wbmp1 = fsReadByte();//读取宽的第一位

int wbmp2 = fsReadByte();//读取宽的第二位

int wbmp3 = fsReadByte();//读取宽的第三位

fsReadByte();//第四位在这里用不到

int hbmp1 = fsReadByte();//读取高的第一位

int hbmp2 = fsReadByte();//读取高的第二位

int hbmp3 = fsReadByte();//读取高的第三位,第四位依然用不到

Width = wbmp1 | wbmp2 << 8 | wbmp3 << 16;//位移运算得到三个位组成的一个int类型的变量,即位图的宽

Height = hbmp1 | hbmp2 << 8 | hbmp3 << 16;//位移运算得到三个位组成的一个int类型的变量,即位图的高

//取得颜色深度,即为多少位的图在文件头的29位

fsSeek(28, 0);//跳过28位

postColor = fsReadByte();//读取第29位,即颜色深度

MBitmap = new Bitmap(Width, Height, PixelFormatFormat24bppRgb);//实例化Bitmap类

fsSeek(54, 0);//跳过文件头,即从第55位开始

for (int Ycount = 0; Ycount < MBitmapHeight; Ycount++)//双层循环,遍历bmp数组,分别调用SetPixel方法

{

for (int Xcount = 0; Xcount < MBitmapWidth; Xcount++)

{

int a = fsReadByte();

int b = fsReadByte();

int c = fsReadByte();

int color = a | b << 8 | c << 16;

//因为行序是颠倒的,所以要让它倒回来,需要用行高减去它当前的行数再减一,防止越界

MBitmapSetPixel(Xcount, MBitmapHeight - Ycount - 1, ColorFromArgb(color));

}

}

fsClose();//关闭文件流

}

/// <summary>

/// 绘制位图

/// </summary>

/// <param name="g">Graphics对象g</param>

public void Draw(Graphics g,Bitmap bmp)

{

gDrawImage(bmp, 0, 0);//绘制bmp图

}

public Bitmap SmallBitmap(Bitmap b)

{

int w = bWidth / 2;

int h = bHeight / 2;

Bitmap bmp = new Bitmap(b, w, h);

for (int Ycount = 0; Ycount < h; Ycount++)

{

for (int Xcount = 0; Xcount < w; Xcount++)

{

Color c1 = bGetPixel(Xcount 2, Ycount 2);

Color c2 = bGetPixel(Xcount 2, Ycount 2 + 1);

Color c3 = bGetPixel(Xcount 2 + 1, Ycount 2);

Color c4 = bGetPixel(Xcount 2 + 1, Ycount 2 + 1);

int c1r = (16711680 & c1ToArgb()) >> 16;

int c1g = (65280 & c1ToArgb()) >> 8;

int c1b = (255 & c1ToArgb());

int c2r = (16711680 & c2ToArgb()) >> 16;

int c2g = (65280 & c2ToArgb()) >> 8;

int c2b = (255 & c2ToArgb());

int c3r = (16711680 & c3ToArgb()) >> 16;

int c3g = (65280 & c3ToArgb()) >> 8;

int c3b = (255 & c3ToArgb());

int c4r = (16711680 & c4ToArgb()) >> 16;

int c4g = (65280 & c4ToArgb()) >> 8;

int c4b = (255 & c4ToArgb());

int cr = (c1r + c2r + c3r + c4r) / 4;

int cg = (c1g + c2g + c3g + c4g) / 4;

int cb = (c1b + c2b + c3b + c4b) / 4;

bmpSetPixel(Xcount, Ycount, ColorFromArgb((cr == 255 && cg == 0 && cb == 255) 0 : 255, cr, cg, cb));

}

}

return bmp;

}

}

这里有一段我写的对bmp类型的绘制,你可以看下

如果你用sqlite_get_table的话得到的前N列是你的表头。应该从第N个开始往后读。N是你create table 时的元素个数。

例如:

sqlite3_get_table(m_pSqlDb,pStrSql,&szResult,&iRow,&iColumn,&chErrMsg);

int nIndex = iColumn;

for (int row=0;row<iRow;row++)

{

for (int column=0;column<iColumn;column++)

{

在这里赋值。

szResult[nindex++] 是取到的值。你直接付给你的结构体就行。你最好做一下判断。

}

}

先读取数据库的路径,用select form base;得到路径之后,

// StreamReader objReader = new StreamReader(@"C:\Users\loa\Desktop\testtxt");

// string sLine = "";

// ArrayList arrText = new ArrayList();

// while (sLine != null)

// {

// sLine = objReaderReadLine();

// if (sLine != null)

// arrTextAdd(sLine);

// }

// objReaderClose();

// foreach (string sOutput in arrText)

// ConsoleWriteLine(sOutput);

insert into table1 (field1,field2) SELECT field1,field2 FROM table2 where 。。。

不知道是不是你要的效果

以上就是关于C#怎样读取数据库中Image类型在线等!!全部的内容,包括:C#怎样读取数据库中Image类型在线等!!、从SQLIT数据库中取出表的数据存于结构体中的C语言代码、你好,请问vs2010要怎样读取数据库表里的txt文件的路径,然后把txt显示在页面上呢等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/sjk/9542644.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-04-29
下一篇2023-04-29

发表评论

登录后才能评论

评论列表(0条)

    保存