[ d_dzole @ 27.10.2009. 09:37 ] @

... pokusavam razne primere sa neta ali nista mi ne uspeva!

1- bitmap image is not valid
2- jpeg error 42, 53
3- stream error - ne mogu sada da se setim sta sve pise
...

Instaliran mi je Win7-64bit i Borland C++ Embarcadero RAD Studio 2010

Na formi su postavljeni:

-DataSource1
-ADOTable1
-DBGrid1
-DBImage1
-OpenPictureDialog1
-Edit1
-Button1
-mdb baza (fields[1] za edit-Text i fields[2] za sliku-OLE Object)

Kako da sacuvam JPG sliku iz dialoga i da se ona pikaze u dbimage ? (necu putanju - slike se cuvaju u bazi)

I samo jos da kazem da sa BMP slikama sve radi OK!


Hvala unapred

Pozdrav.
[ X Files @ 27.10.2009. 11:14 ] @
Da li si dodao:
#include <jpeg.hpp>
[ X Files @ 27.10.2009. 11:24 ] @
Sada sam pogledao. DBImage i dalje ne podrzava JPG, tj TBlobField je usko grlo.

Koliko vidim, zaobilazno resenje je koriscenje TImage umesto TDBImage, jer je uglavnom svejedno sta se od ovoga koristi (jer je read only).

Da ne prepricavam, evo jednog resenja:

Citat:

> well i have achieved in selecting a bmp file from a opendialog
> and then put it in a database using blob and ado.my code is:

I would suggest his code instead:

#include <memory>

void __fastcall TForm1::Button1Click(TObject *Sender)
{
if( OpenDialog1->Execute() )
{
std::auto_ptr<TFileStream> file(new
TFileStream(OpenDialog1->FileName, fmOpenRead | fmShareDenyWrite));
ADOTable1->Append();
try
{
ADOTable1->FieldValues["name"] = OpenDialog1->FileName;
ADOTable1->FieldValues["size"] = size;
std::auto_ptr<TStream>
blob(ADOTable1->CreateBlobStream(ADOTable1->FieldByName("file"), bmWrite));
blob->CopyFrom(file.get(), 0);
ADOTable1->Post();
}
catch(const Exception &)
{
ADOTable1->Cancel();
}
}
}

> now the problem is that dbimage doesnt show jpeg images.

TDBImage can only display images that TBlobField supports, and TBlobField do
not support JPG at all. Sure, you can store JPG data into a blob field just
fine, but TBlobField does not natively support assigning JPG data to/from a
TPicture. It only supports BMP. If you need JPG support, then you will
have to manage it manually.

> i thougt of taking the blob from the database
> and then put it in a stream ->savetofile
> and then image->picture->loadfromfile

That is one way to do it, if you use a normal TImage instead of a TDBImage.
You do not need a file, though. You can load the stream directly into the
TImage, as long as the Graphic property has been set to the appropriate
class type first. For example:

std::auto_ptr<TStream>
blob(ADOTable1->CreateBlobStream(ADOTable1->FieldByName("file"), bmRead));
std::auto_ptr<TJPEGImage> jpg(new TJPEGImage);
Image1->Picture->Graphic = jpg.get();
Image1->Picture->Graphic->LoadFromStream(blob.get());

> i cant take the blob from the adotable and put it in a file..

Yes, you can. TBlobField has SaveToStream() and SaveToFile() methods
available, ie:

TField *field = ADOTable1->FieldByName("file");
static_cast<TBlobField*>(field)->SaveToFile("some file");

Do note, however, that the saved data may contain additional data then you
expect, since TBlobField stored additional headers inside of itself for
certain data types.


Gambit


Ako ne odgovara, pokusaj kljucnim recima: jpg tdbimage ili jpg dbimage na adresi:
http://codenewsfast.com/
[ d_dzole @ 27.10.2009. 14:39 ] @

... izlistao sve i dalje se vrtim u krug !

A ovaj primer izbacuje gresku "ADOTable1:Dataset not in edit or insert mode." U bazi vidim da je upisano "file name" a u polju za slike nema nista.

Kada odradim ovako, JPG slika se prikazuje u DBImage

Code:

#include <jpeg.hpp>

if (OpenDialog1->Execute())
{
DBImage1->Picture->LoadFromFile(OpenDialog1->FileName);
}


Gde je problem - u upisivanju, citanju iz baze ili OLE Object ili sta vec ?!

I ovo sam probao, nema razlike, a i ne vidim potrebu za ovim ... DBImage1->Picture->RegisterFileFormat("jpg", "JPEG File", __classid(TJPEGImage)); ... ako vec mogu da prikazem jpg.

Ima li resenja ? :)