Solved

i 'll be mad with jpg

Posted on 2001-09-11
13
214 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
Comment Utility
? don't use a dbimage or a graphic-blob type
0
 
LVL 22

Expert Comment

by:mnasman
Comment Utility
Hello

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

Author Comment

by:ws1999
Comment Utility
ofcourse otherwise it cannot pass the compiler
0
 
LVL 3

Accepted Solution

by:
cubud earned 30 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 14

Expert Comment

by:AvonWyss
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Finalized.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

744 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now