Solved

i 'll be mad with jpg

Posted on 2001-09-11
13
219 Views
Last Modified: 2010-04-06
i want to save jpg to the blob field of SQL Server(BDE connection)

but it always tell me bitmap image is invalid,why,why???

here is my code:

var
FileStream : TFileStream;
BlobStream : TBlobStream;

begin

if OpenPictureDialog1.Execute then
  with Table1 do
begin

  FileStream := TFileStream.Create(OpenPictureDialog1.FileName, fmOpenRead);
  Edit;
  BlobStream := TBlobStream(CreateBlobStream(FieldByName('ThumbImage'), bmWrite));
  BlobStream.Seek(0,soFromBeginning);
  BlobStream.Truncate;
  BlobStream.CopyFrom(FileStream,FileStream.Size);
  FileStream.Free;
  BlobStream.Free;
  Post;
 
end;
0
Comment
Question by:ws1999
  • 4
  • 2
  • 2
  • +4
13 Comments
 
LVL 27

Expert Comment

by:kretzschmar
ID: 6475748
? don't use a dbimage or a graphic-blob type
0
 
LVL 22

Expert Comment

by:Mohammed Nasman
ID: 6475766
Hello

  Did you include the Jpeg unit in the uses clause?
0
 

Author Comment

by:ws1999
ID: 6475830
ofcourse otherwise it cannot pass the compiler
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Accepted Solution

by:
cubud earned 30 total points
ID: 6476629
Why don't you just do

TBlobField(Table1.FieldByName('Something')).LoadFromFile(filename);

Pete
http://www.HowToDoThings.com (Delphi articles)
http://www.Stuckindoors.com/delphi (Open source)
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 6477207
hi, a bit correction in your code
(of course cubud is right, you can easy use this suggestion,
even if i think that a comment would be better than an answer)

FileStream := TFileStream.Create(OpenPictureDialog1.FileName, fmOpenRead);
Edit;
BlobStream := TBlobStream(CreateBlobStream(FieldByName('ThumbImage'), bmWrite));
filestream.position := 0;  //<-add this line -> spool back the stream
BlobStream.CopyFrom(FileStream,0); // change this
FileStream.Free;
BlobStream.Free;
Post;
                     
meikl ;-)
0
 
LVL 3

Expert Comment

by:cubud
ID: 6477703
But why mess around creating all that code when typecasting as a TBlobField and using LoadFromFile does it all for you ?


Pete
http://www.HowToDoThings.com (Articles)
http://www.StuckIndoors.com/delphi (Open-source)
0
 
LVL 14

Expert Comment

by:AvonWyss
ID: 6485625
cubud, because your typecasting could lead to problems if
* the field was not a blob field
* some other part of the program (maybe some DB explorer or anything) expects the data to be in a certain format

Typecasts should be used with extreme caution, and I believe that you example does not do this.

Also, please read http://www.experts-exchange.com/jsp/cmtyQuestAnswer.jsp
0
 
LVL 3

Expert Comment

by:cubud
ID: 6485946
Reading that URL you provided I see no point whatsoever in having an "Answer" option.  It holds up the process needlessly and provides no benefit at all.  Maybe it should be removed ?

0
 
LVL 14

Expert Comment

by:AvonWyss
ID: 6485957
cubud, over the last years there have been lots of discussions because of this "answer" option. Actually, many experts are not very happy with it. A better option may have been to allow multiple experts to answer (e.g. remove the locking aspect) or to rename it to "lock question for evaluation" or so. I use it sometimes when a question is solved (in means of feedback by the questioner) but not yet graded.

Most, if not all, newcomer experts are cought by this "trap". So when I encounter this situation, I try to make the expert aware of this pitfall. Once again, welcome to EE and have a good time!
0
 
LVL 3

Expert Comment

by:cubud
ID: 6485984
Exactly, my opinion of "the answer" will undoubtedly be different to someone else's.  The LOCK option should really be for administrators and the question poster.

0
 

Expert Comment

by:amp072397
ID: 6789175
ws1999:

You have many open questions to which you must return:

http://www.experts-exchange.com/jsp/qShow.jsp?ta=msaccess&qid=20264790
http://www.experts-exchange.com/jsp/qShow.jsp?ta=delphi&qid=20256743
http://www.experts-exchange.com/jsp/qShow.jsp?ta=delphi&qid=20250343
http://www.experts-exchange.com/jsp/qShow.jsp?ta=delphi&qid=20249986
http://www.experts-exchange.com/jsp/qShow.jsp?ta=delphi&qid=20187323
http://www.experts-exchange.com/jsp/qShow.jsp?ta=delphi&qid=20184015
http://www.experts-exchange.com/jsp/qShow.jsp?ta=delphi&qid=20181707
http://www.experts-exchange.com/jsp/qShow.jsp?ta=delphi&qid=20180448
http://www.experts-exchange.com/jsp/qShow.jsp?ta=delphi&qid=20169990
http://www.experts-exchange.com/jsp/qShow.jsp?ta=delphi&qid=11401958
http://www.experts-exchange.com/jsp/qShow.jsp?ta=java&qid=20230693
http://www.experts-exchange.com/jsp/qShow.jsp?ta=java&qid=20194172
http://www.experts-exchange.com/jsp/qShow.jsp?ta=java&qid=20187856
http://www.experts-exchange.com/jsp/qShow.jsp?ta=java&qid=20187852
http://www.experts-exchange.com/jsp/qShow.jsp?ta=java&qid=20187466
http://www.experts-exchange.com/jsp/qShow.jsp?ta=java&qid=20182301
http://www.experts-exchange.com/jsp/qShow.jsp?ta=java&qid=20182182
http://www.experts-exchange.com/jsp/qShow.jsp?ta=java&qid=20181487
http://www.experts-exchange.com/jsp/qShow.jsp?ta=java&qid=20181301
http://www.experts-exchange.com/jsp/qShow.jsp?ta=java&qid=20180787
http://www.experts-exchange.com/jsp/qShow.jsp?ta=java&qid=20180436
http://www.experts-exchange.com/jsp/qShow.jsp?ta=java&qid=20172201
http://www.experts-exchange.com/jsp/qShow.jsp?ta=java&qid=20153303

To assist you in your cleanup, I'm providing the following guidelines:

1.  Stay active in your questions and provide feedback whenever possible. Likewise, when feedback has not been provided by the experts, commenting again makes them receive an email notification, and they may provide you with further information. Experts have no other method of searching for questions in which they have commented, except manually.

2.  Award points by hitting the Accept Comment As Answer button located above and to the left of that expert's comment.

3.  When grading, be sure to read:
http://www.experts-exchange.com/jsp/cmtyQuestAnswer.jsp#3
to ensure that you understand the grading system here at EE. If you grade less than an A, you must explain why.

4.  Questions that were not helpful to you should be PAQ'd (stored in the database for their valuable content?even if not valuable to you) or deleted. To PAQ or delete a question, you must first post your intent in that question to make the experts aware. Then, if no experts object after three full days, you can post a zero-point question at community support to request deletion or PAQ. Please include the link(s) to the question(s).
CS:  http://www.experts-exchange.com/jsp/qList.jsp?ta=commspt
At that point, a moderator can refund your points and PAQ or delete the question for you. The delete button does not work.

5.  If you fail to respond to this cleanup request, I must report you to the Community Support Administrator for further action.

Our intent is to get the questions cleaned up, and not to embarrass or shame anyone. If you have any questions or need further assistance at all, feel free to ask me in this question or post a zero-point question at CS. We are very happy to help you in this task!


thanks!
amp
community support moderator

2/8
0
 
LVL 1

Expert Comment

by:Moondancer
ID: 6863445
ADMINISTRATION WILL BE CONTACTING YOU SHORTLY REGARDING YOUR ACCOUNT AND OPEN QUESTIONS.

Question(s) below appears to have been abandoned. Your options are:
 
1. Accept a Comment As Answer (use the button next to the Expert's name).
2. Close the question if the information was not useful to you. You must tell the participants why you wish to do this, and allow for Expert response.
3. Ask Community Support to help split points between participating experts, or just comment here with details and we'll respond with the process.
4. Delete the question. Again, please comment to advise the other participants why you wish to do this.

For special handling needs, please post a zero point question in the link below and include the question QID/link(s) that it regards.
http://www.experts-exchange.com/jsp/qList.jsp?ta=commspt
 
Please click the Help Desk link on the left for Member Guidelines, Member Agreement and the Question/Answer process.  http://www.experts-exchange.com/jsp/cmtyHelpDesk.jsp

Please click you Member Profile to view your question history and keep them all current with updates as the collaboration effort continues, to track all your open and locked questions at this site.  If you are an EE Pro user, use the Power Search option to find them.

To view your open questions, please click the following link(s) and keep them all current with updates.
http://www.experts-exchange.com/questions/Q.11401958.html
http://www.experts-exchange.com/questions/Q.20169990.html
http://www.experts-exchange.com/questions/Q.20180448.html
http://www.experts-exchange.com/questions/Q.20181301.html
http://www.experts-exchange.com/questions/Q.20182182.html
http://www.experts-exchange.com/questions/Q.20184015.html
http://www.experts-exchange.com/questions/Q.20249986.html
http://www.experts-exchange.com/questions/Q.20264790.html
http://www.experts-exchange.com/questions/Q.20180436.html
http://www.experts-exchange.com/questions/Q.20187323.html


To view your locked questions, please click the following link(s) and evaluate the proposed answer.
http://www.experts-exchange.com/questions/Q.20181707.html

PLEASE DO NOT AWARD THE POINTS TO ME.  
 
------------>  EXPERTS:  Please leave any comments regarding your closing recommendations if this item remains inactive another seven (7) days.  Also, if you are interested in the cleanup effort, please click this link http://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=commspt&qid=20274643
 
Thank you everyone.
 
Moondancer
Moderator @ Experts Exchange

P.S.  For any year 2000 questions, special attention is needed to ensure the first correct response is awarded, since they are not in the comment date order, but rather in Member ID order.
0
 
LVL 1

Expert Comment

by:Moondancer
ID: 6887575
Finalized.
0

Featured Post

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question