C++
浏览量:831 回帖数:0
1楼
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "image.h"
#include "Jpeg.hpp"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
//存入图片
void __fastcall TForm1::Button1Click(TObject *Sender)
{
ADOQuery1->Close();
ADOQuery1->SQL->Clear();
ADOQuery1->SQL->Text="insert into image values(:img_id,:img)";
//ADOQuery1->Prepared=true;
//ADOQuery1->Open();
ADOQuery1->Parameters->Items[0]->value=1;
ADOQuery1->Parameters->Items[1]->LoadFromFile("E:\\a.jpg",ftBlob);
ADOQuery1->ExecSQL();
}
//---------------------------------------------------------------------------
//取图片
void __fastcall TForm1::Button2Click(TObject *Sender)
{
TMemoryStream *MS;
TJPEGImage *jpg;
TImage *Image1;
MS=new TMemoryStream;
jpg=new TJPEGImage;
//Graphics::TBitmap* tBitmap=new Graphics::TBitmap();
ADOQuery1->Close();
ADOQuery1->SQL->Text="select img_id,img from image where img_id=1";
ADOQuery1->Open();
Edit1->Text=ADOQuery1->Fieldvalues["img_id"];
((TBlobField *)ADOQuery1->FieldByName("img"))->SaveToStream(MS);
MS->Position=0;
jpg->LoadFromStream(MS);
//Canvas->Draw(0,0,jpg);
//tBitmap->Assign(jpg);
//Image1->Picture->Bitmap->Assign(tBitmap);
Image1->Picture->Assign(jpg);
delete jpg;
delete MS;
}
//---------------------------------------------------------------------------
提示image对象名无效
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "image.h"
#include "Jpeg.hpp"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
//存入图片
void __fastcall TForm1::Button1Click(TObject *Sender)
{
ADOQuery1->Close();
ADOQuery1->SQL->Clear();
ADOQuery1->SQL->Text="insert into image values(:img_id,:img)";
//ADOQuery1->Prepared=true;
//ADOQuery1->Open();
ADOQuery1->Parameters->Items[0]->value=1;
ADOQuery1->Parameters->Items[1]->LoadFromFile("E:\\a.jpg",ftBlob);
ADOQuery1->ExecSQL();
}
//---------------------------------------------------------------------------
//取图片
void __fastcall TForm1::Button2Click(TObject *Sender)
{
TMemoryStream *MS;
TJPEGImage *jpg;
TImage *Image1;
MS=new TMemoryStream;
jpg=new TJPEGImage;
//Graphics::TBitmap* tBitmap=new Graphics::TBitmap();
ADOQuery1->Close();
ADOQuery1->SQL->Text="select img_id,img from image where img_id=1";
ADOQuery1->Open();
Edit1->Text=ADOQuery1->Fieldvalues["img_id"];
((TBlobField *)ADOQuery1->FieldByName("img"))->SaveToStream(MS);
MS->Position=0;
jpg->LoadFromStream(MS);
//Canvas->Draw(0,0,jpg);
//tBitmap->Assign(jpg);
//Image1->Picture->Bitmap->Assign(tBitmap);
Image1->Picture->Assign(jpg);
delete jpg;
delete MS;
}
//---------------------------------------------------------------------------
提示image对象名无效
2017/10/21 2:19:04