unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons, ExtCtrls, DB, ADODB,jpeg, DBCtrls, Mask;type
TForm1 = class(TForm)
con1: TADOConnection;
qry1: TADOQuery;
img1: TImage;
btn1: TBitBtn;
btn2: TBitBtn;
OpenDialog1: TOpenDialog;
lbl1: TLabel;
edt1: TEdit;
lbl2: TLabel;
edt2: TEdit;
dbnvgr1: TDBNavigator;
ds1: TDataSource;
qry2: TADOQuery;
img2: TImage;
btn3: TBitBtn;
procedure FormShow(Sender: TObject);
procedure btn1Click(Sender: TObject);
procedure btn2Click(Sender: TObject);
procedure btn3Click(Sender: TObject);
procedure dbnvgr1Click(Sender: TObject; Button: TNavigateBtn);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R dfm}procedure TForm1btn1Click(Sender: TObject);
var
ms:TMemoryStream;
jpg:TJPEGImage;
begin
ms:=TMemoryStreamCreate;
jpg:=TJPEGImageCreate;
jpgAssign(img1PictureGraphic);
jpgSaveToStream(ms);
msPosition:=0;
qry1SQLClear;
qry1SQLAdd('Insert Into TIMG(PNAME,PINFO,PPHOTO) values(:pname,:pinfo,:pphoto)');
qry1ParametersParamByName('pname')Value:=edt1Text;
qry1ParametersParamByName('pinfo')Value:=edt2Text;
qry1ParametersParamByName('pphoto')LoadFromStream(ms,ftBlob);
qry1ExecSQL;
jpgFree;
msFree;
end;procedure TForm1btn2Click(Sender: TObject);
begin
if OpenDialog1Execute then
img1PictureLoadFromFile(OpenDialog1FileName);
end;procedure TForm1btn3Click(Sender: TObject);
var
ms:TMemoryStream;
jpg:TJPEGImage;
begin
if not qry2FieldByName('PPHOTO')IsNull then
begin
ms:=TMemoryStreamCreate;
jpg:=TJPEGImageCreate;
TBlobField(qry2FieldByName('PPHOTO'))SaveToStream(ms);
msPosition:=0;
jpgLoadFromStream(ms);
img2PictureAssign(jpg);
end;
end;procedure TForm1dbnvgr1Click(Sender: TObject; Button: TNavigateBtn);
begin
btn3Click;
end;procedure TForm1FormShow(Sender: TObject);
begin
con1Close;
con1ConnectionString:='Driver=Firebird/Interbase(r) driver;UID=SYSDBA;PWD'+
'=123456;Dbname='+ExtractFilePath(ApplicationExeName)+'IMGFDB';
con1LoginPrompt:=False;
con1Connected:=True; qry2Active:=True;
//img2DataField:='PPHOTO';
end;end 我用的是Firebird数据库,存放的字段名是PPHOTO,数据类型是BLOB,其他数据库应该也差不多。
private void ShowImage(string sql)
{
//调用方法如:ShowImage("select Photo from UserPhoto where UserNo='" + userno +"'");
SqlCommand cmd = new SqlCommand(sql, conn);
connOpen();
byte[] b= (byte[])cmdExecuteScalar();
if (bLength 〉 0)
{
MemoryStream stream = new MemoryStream(b, true);
streamWrite(b, 0, bLength);
pictureBox1Image = new Bitmap(stream);
streamClose();
}
connClose();
}
类似这样 根据你的实际情况修改。
安卓中如何获取保存的uri 并保存到sqlite数据库中
有如下两种方法,仅供参考
方法一:Java代码
public void saveIcon(Bitmap icon) {
if (icon == null) {
return;
}
// 最终图标要保存到浏览器的内部数据库中,系统程序均保存为SQLite格式,Browser也不例外,因为是二进制的所以使用字节数组存储数据库的
// BLOB类型
final ByteArrayOutputStream os = new ByteArrayOutputStream();
// 将Bitmap压缩成PNG编码,质量为100%存储
iconcompress(BitmapCompressFormatPNG, 100, os);
// 构造SQLite的Content对象,这里也可以使用
raw ContentValues values = new ContentValues();
// 写入数据库的
BrowserBookmarkColumnsTOUCH_ICON字段 valuesput(BrowserBookmarkColumnsTOUCH_ICON, ostoByteArray());
DBUtilupdate();
//调用更新或者插入到数据库的方法
}
}
方法二:如果数据表入口时一个content:URIJava代码
import androidproviderMediaStoreImagesMedia;
import androidcontentContentValues;
import javaioOutputStream;
// Save the name and description of an image in a ContentValues map
ContentValues values = new ContentValues(3);
valuesput(MediaDISPLAY_NAME, "road_trip_1");
valuesput(MediaDESCRIPTION, "Day 1, trip to Los Angeles");
valuesput(MediaMIME_TYPE, "image/jpeg");
// Add a new record without the bitmap, but with the values just set
// insert() returns the URI of the new record
Uri uri = getContentResolver()insert(MediaEXTERNAL_CONTENT_URI, values);
// Now get a handle to the file for that record, and save the data into it
// Here, sourceBitmap is a Bitmap object representing the file to save to the database
try {
OutputStream outStream = getContentResolver()openOutputStream(uri);
sourceBitmapcompress(BitmapCompressFormatJPEG, 50, outStream);
outStreamclose();
} catch (Exception e) {
Loge(TAG, "exception while writing image", e);
}
原文请看>
//在循环里边写
imgClick += new EventHandler(ImageButtonClick);
//外边
void ImageButtonClick()
{
//点击事件 做什么
}
以上就是关于在delphi中如何取出数据库中的图片显示在image上全部的内容,包括:在delphi中如何取出数据库中的图片显示在image上、C#如何读取数据库中所有的图片显示到对应的pictureBox中、android 如何获取保存的图片的地址 并存到数据库中等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)