RTC Forums
November 24, 2024, 07:46:56 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
 
   Home   Help Login Register  
Pages: [1]
  Print  
Author Topic: Get Images from a MYSql blob field.  (Read 8064 times)
classic12
Guest
« on: November 10, 2011, 07:15:08 PM »

Brilliant product by the way...

I have produce the client and server from lesson2 & lesson5.

I send a number from the client and it returns data from one of the fields.

The server receives the number and runs a query and I return the value from a grid. ( I know I'm not supposed to use grids but using for visualisation whilst testing).
So I am a happy man..............

I now need to return an Image from Tickets2.Ticket_Image and show the image in an Image control on the client.

I tried to follow the samples app but could not get my head around it.
I see ImageControl1.Bitmap.LoadFromStream(Result.asDataSet.asByteStream['Graphic']);

So how do I set the server end to send the image data.

Cheers


SteveW

PS be gentle with me and every thing at idiot level
Logged
D.Tkalcec (RTC)
Administrator
*****
Posts: 1881


« Reply #1 on: November 10, 2011, 07:23:28 PM »

Instead of copying individual fields manually, why not use the "DelphiDataSetToRtc" function from the "rtcDB" unit?

For an example on working with databases, I recommend taking a look at demos inside the "DB_Access" folder first. They provide you with a ready-to-test example using the BDE on the Server and TRtcMemDataSet or TClientDataSet components on the Client.

If you need an example on copying fields manually, also check the "rtcDB.pas" unit, where you will see "DelphiDataSetToRtc", "RtcDataSetFieldsToDelphi" and "RtcDataSetRowsToDelphi" procedures.

Best Regards,
Danijel Tkalcec
Logged
classic12
Guest
« Reply #2 on: November 10, 2011, 07:42:27 PM »

Did I mention 'PS be gentle with me and every thing at idiot level'

There's a lot to take in and break down in the demos.

Any chance of a very basic client / server that simply returns an Image from a MYSQL blob field.

I have the text fields returning.
Once I get the Images I can then build the app from there.

Cheers


SteveW



Logged
D.Tkalcec (RTC)
Administrator
*****
Posts: 1881


« Reply #3 on: November 10, 2011, 09:17:09 PM »

If just you want a short answer, send the image using the "rtc_ByteStream" data type.

Here is a Quick Start topic about sending and receiving streams with RTC remote functions.

If you want to send more than just a Stream from the Server, you can pack multiple values of different types by using the "rtc_Record", "rtc_Array" or "rtc_DataSet" data type.

Here is a Quick Start topic about using complex structures with RTC remote functions.

Just beware that some Database Engines inject a graphic field header to Graphic Fields (I don't know about MySQL, but it is true for the BDE and especially Paradox tables), which you would need to skip before copying the Stream into a "rtc_ByteStream" data type - if you want to copy it manually. If you need an example on copying Graphic field content into a "rtc_ByteStream" data type, I strongly recommend taking a look at the "DelphiDataSetToRtc" function from the "rtcDB" unit and checking the local "rtcSkipGraphicHeader" procedure in the "rtcDB.pas" unit.

Or ... provided you are using a MySQL Engine which works with a TDataSet descendant, instead of manually copying fields and images, you could use the "DelphiDataSetToRtc" function on the Server to get a complete TDataSet content into a "rtc_DataSet" object, which you can send back as a response:

DelphiDataSetToRtc(MySqlDataSet, Result.NewDataSet);

If you need an explanation about that function, here is a related FAQ Topic.

If you need more info, please check the Quick Start lessons and the FAQ's about using RTC remote functions.

Best Regards,
Danijel Tkalcec
Logged
classic12
Guest
« Reply #4 on: November 15, 2011, 01:40:16 PM »

I have gone through the tutorials etc.

I have this on the server:

run MyQuery1

DelphiDataSetToRtc( MyQuery1, Result.NewDataSet );

1. Does this return result as a dataset to the client.

on the IOS client

I have added RtcMemDataSet1

1. What is the correct syntax to load this with the result.
I have tried Umain.FormMain.RtcMemDataSet1.FileName(Result.asDataSet)
2. Once I have the result how do I assign an edit box to field Ticket_No and a TImage to field Ticket_Image.

Umain.FormMain.Edit1.Text := RtcMemDataSet1.FieldbyName[Ticket_No].asString
Umain.FormMain.ImageControl1.Bitmap.LoadFromStream(Umain.FormMain.RtcMemDataSet1.FieldByName('Ticket_Image').asXXX


Cheers


SteveW
Logged
D.Tkalcec (RTC)
Administrator
*****
Posts: 1881


« Reply #5 on: November 15, 2011, 01:44:59 PM »

Yes, the code you have used on the Server would return a RtcDataSet to the Client. Please take a look at the iOSTestClient Project for an example on browsing through the rtcDataSet and displaying an image (using ImageControl) on the FireMonkey iOS Form. It is located in the "Demos\DB_Access" folder and is also one of the Projects inside the "Demos/iOS_Projects" Project Group.

Best Regards,
Danijel Tkalcec
Logged
classic12
Guest
« Reply #6 on: November 15, 2011, 04:01:36 PM »

Cheers

I have tables getting copied and showing images and text in fields.

When the table has a bmp it works but fails on a jpg.

 procedure TFormTicketEntry.UpdateBitmap;
  begin
  if assigned(MyDataSet) then
    begin
    if MyDataSet.isType['Ticket_Image']=rtc_ByteStream then
      begin
      UMain.FormMain.Label3.Text:='DataSet Received, showing Row '+IntToStr(MyDataSet.Row+1)+' of '+IntToStr(MyDataSet.RowCount);
      UMain.FormMain.ImageControl1.Bitmap := nil;
      UMain.FormMain.ImageControl1.Bitmap.LoadFromStream(MyDataSet.asByteStream['Ticket_Image']);
      end
    else
      begin
      UMain.FormMain.Label3.Text:='DataSet Received, showing Row '+IntToStr(MyDataSet.Row+1)+' of '+IntToStr(MyDataSet.RowCount);
      if assigned(UMain.FormMain.ImageControl1.Bitmap) then
        UMain.FormMain.ImageControl1.Bitmap.Clear(TAlphaColorRec.White);
      end;
    end
  else
    begin
    UMain.FormMain.Label3.Text:='No DataSet.';
    if assigned(UMain.FormMain.ImageControl1.Bitmap) then
      UMain.FormMain.ImageControl1.Bitmap.Clear(TAlphaColorRec.Black);
    end;
  end;

Cheers


SteveW
Logged
D.Tkalcec (RTC)
Administrator
*****
Posts: 1881


« Reply #7 on: November 15, 2011, 05:26:03 PM »

The RTC SDK only handles the communication. When you are using the ByteStream data type, the exact same byte stream you write on one side will be readable on the other side. This goes for BMP, JPG, EXE, ZIP, PDF, HTML and any other content you want to send. There is absolutely no difference for the RTC SDK.

I have now tested a FishFactServer and fmxFishFactClient (Windows) together with the iosTestClient (iPad) to see if JPG images will be displayed. Storing an image using the fmxFishFactClient, submitting changes to the FishFactServer, then using the iosTestClient to display the image worked without any problems.

Since you have said that BMP images display correctly and I see here that the ImageControl component for FireMonkey iOS can display JPG files, I'm guessing that you are sending more than just an image from the Server to the Client when using the JPG format, or that the JPG you are sending is corrupt, invalid, incomplete or in a format not supported by the ImageControl component.

If the image is coming from a database, try writing the contents of the field to a local file and see if you can open the file on Windows when you give it the "jpg" extension.

Best Regards,
Danijel Tkalcec
Logged
classic12
Guest
« Reply #8 on: November 15, 2011, 05:54:54 PM »

I found the problem. On the server I was using :

      Blobfield := MYQuery1.FieldbyName('Ticket_Image');
      BS := MYQuery1.CreateBlobStream(BlobField,bmReadWrite);
      Result.asByteStream := BS;
      Image1.Picture.Bitmap.LoadFromStream(BS);


This failed when there was a jpeg (not sure why) and the query failed.

Cheers


SteveW
Logged
D.Tkalcec (RTC)
Administrator
*****
Posts: 1881


« Reply #9 on: November 15, 2011, 07:00:39 PM »

What do you mean by "query failed"? Does the 4-line code you wrote above raise an exception? If yes, where and what is the exception message?

What happens if you comment out the "Result.asByteStream:=BS" line?

      Blobfield := MYQuery1.FieldbyName('Ticket_Image');
      BS := MYQuery1.CreateBlobStream(BlobField,bmReadWrite);
      // Result.asByteStream := BS; <-- comment out to test on Server
      Image1.Picture.Bitmap.LoadFromStream(BS);

Commenting out the RTC-related line and running the Server with "MultiThreaded=FALSE", does the JPEG show inside the Image1 control?

Also ... have you tried writing the BS stream which you get from the Database into a local file and analyzing the file? Or at leat try to open it with Image Viewer or Paint to see if it is a recognized JPG file by Windows?

Best Regards,
Danijel Tkalcec
Logged
classic12
Guest
« Reply #10 on: November 18, 2011, 02:00:32 PM »

Because my app had a problem with showing the image so the query did not run.

Cheers

SteveW
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!
Page created in 0.027 seconds with 15 queries.