?
Solved

Assigning a Tjpegimage to a  TgraphicField

Posted on 2003-03-14
6
Medium Priority
?
778 Views
Last Modified: 2010-04-16
How does one correctly assign a TjpegImage to a Graphicfield for eg
I get an error when i try the following
jpeg_image.assign( b) //where b is of type TGraphicField(i had given the complete code in my previous question.since i did not get any response i am simplifying the question)
Thanks
venks
0
Comment
Question by:venks
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 1

Author Comment

by:venks
ID: 8141221
My question should have been 'How to assign a graphicfield to TjpegImage type'
I am sorry for the mistake in my question.I am trying to get the hang of what is to be assigned to what?
Thanks
venks
0
 
LVL 2

Expert Comment

by:PeterLarsen
ID: 8142103
You say 'graphicfield'. Is that a picture loaded from a database or ...?
0
 
LVL 17

Expert Comment

by:geobul
ID: 8142429
Hi,

Try this:

type
  TForm1 = class(TForm)
    ADOTable1: TADOTable;
    Image1: TImage;
    Button1: TButton;
    Button2: TButton;
    procedure LoadJPeg;
    procedure SaveJPeg(filename: string);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

uses jpeg;

var
JPegImage : TJpegImage;

// loads a jpeg from the current record, field name is 'pic'
// JPegImage has already been created before
procedure TForm1.LoadJPeg;
var
  ms : TMemoryStream;
begin
  // Do Only if a BLOB field available
  if (ADOTable1.FieldByName('pic').IsBlob) and (not (ADOTable1.FieldByName('pic').IsNull)) then begin
    // Prepare the stream
    ms := TMemoryStream.Create;
    try
      TGraphicField(ADOTable1.FieldByName('pic')).SaveToStream(ms);
      ms.Position := 0;
      JPegImage.LoadFromStream(ms);
      Image1.Picture.Assign(JPegImage); // display it on the form
    finally
      ms.Free;  // Free Stream
    end;
  end;
end;

// loads an image from record one
procedure TForm1.Button1Click(Sender: TObject);
begin
  ADOTable1.Open;
  ADOTable1.First;
  JpegImage := TJPegImage.Create;
  try
    LoadJPeg;
  finally
    JpegImage.Free;
  end;
  ADOTable1.Close;
end;

// saves a file in the current record, field name is 'pic'
procedure TForm1.SaveJPeg(filename: string);
var
  ms : TMemoryStream;
begin
  ADOTable1.Edit;
  // Prepare the stream
  ms := TMemoryStream.Create;
  try
    JPegImage.LoadFromFile(filename);
    JPegImage.SaveToStream(ms);
    ms.Position := 0;
    TGraphicField(ADOTable1.FieldByName('pic')).LoadFromStream(ms);
  finally
    ms.Free;  // Free Stream
  end;
  ADOTable1.Post;
end;

// saves an image to record one
procedure TForm1.Button2Click(Sender: TObject);
begin
  ADOTable1.Open;
  ADOTable1.First;
  JpegImage := TJPegImage.Create;
  try
    SaveJPeg('d:\test\pic1.jpg');
  finally
    JpegImage.Free;
  end;
  ADOTable1.Close;
end;

Regards, Geo
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 9

Accepted Solution

by:
mocarts earned 500 total points
ID: 8143917
if you want to call like jpeg_image.assign(graphicField) then it wouldn't work until you create new class inhrited from TJpegImage and override Assign method to handle this situation.

if you want assign TGraphicField value to TJpegImage in any possible way then there is example:

procedure AssignGraphicFieldToJpegImage(gf: TGraphicField; ji: TJpegImage);
var
  s: TStream;
begin
  s := gf.DataSet.CreateBlobStream(gf, bmRead);
  try
    ji.LoadFromStream(s);
  finally
    s.Free;
  end;
end;

procedure TForm1.btnLoadImageClick(Sender: TObject);
var
  ji: TJpegImage;
begin
  ji := TJpegImage.Create;
  try
    AssignGraphicFieldToJpegImage(Table1.FieldByName('img'), ji);
    Image1.Picture.Graphic := ji;
  finally
    ji.Free;
  end;
end;

mo.
0
 

Expert Comment

by:CleanupPing
ID: 9316773
venks:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
 
LVL 1

Author Comment

by:venks
ID: 9320161
thanks
Venkatesh
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses
Course of the Month11 days, 2 hours left to enroll

770 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