KimHJ
Members-
Content Count
39 -
Joined
-
Last visited
Community Reputation
3 NeutralTechnical Information
-
Delphi-Version
Delphi 12 Athens
Recent Profile Visitors
The recent visitors block is disabled and is not being shown to other users.
-
I was just thinking I can just delete the image after I have send it.
-
I just replaced it in the same place in the Client where the MemoryStream.LoadFromFile(FImageFilePath); was. I can save it first and then use LoadFromFile and it works, but I don't want to save them on the device. Image1.Bitmap.SaveToFile(FImageFilePath); MemoryStream.LoadFromFile(FImageFilePath);
-
Remy, I'm sorry I didn't see the sample codes you wrote, before. Maybe we where posting at the same time. On the server side in the first example I get an error: First chance exception at $00007FFCF5F3FA4C. Exception class EIdReadLnMaxLineLengthExceeded with message 'Max line length exceeded.'. Process CSIPictureServer.exe (3744) Here: JsonStr := AContext.Connection.IOHandler.ReadLn; The second example worked, thanks. I have the TImage with a image, why when I save to MemoryStream like this I just get a 19kb black image on the server side? Image1.Bitmap.SaveToStream(MemoryStream); //MemoryStream.LoadFromFile(FImageFilePath); I just get a 19kb black image.
-
Remy, It works as it is, but I changed the code in the Client StringStream := TStringStream.Create(IdEncoderMIME1.Encode(MemoryStream),TEncoding.UTF8); .. IdTCPClient1.Socket.Write(JObj.ToJSON); I change the code in the Server code: StringStream := TStringStream.Create('', TEncoding.UTF8); I tried to use ReadString, but the I get a read error when it tries to parse the json PicStr: String; .. PicStr := AContext.Connection.IOHandler.ReadString(-1); JSON := TJSONObject.ParseJSONValue(PicStr) as TJSONObject; It works fine now and I found that it did save the images, but they was not in the folder that I had in the filename string, but in the project folder where the application was running from. I take a picture with the camera and place it in a TImage. procedure TMainForm.TakePhotoFromCameraAction1DidFinishTaking(Image: TBitmap); begin Image1.Bitmap.Assign(Image); end; Then with the same code that works sending a image from a file works. MemoryStream := TMemoryStream.Create; MemoryStream.Position := 0; MemoryStream.LoadFromFile(FImageFilePath); When I try this I get a blank image. MemoryStream := TMemoryStream.Create; MemoryStream.Position := 0; Image1.Bitmap.SaveToStream(MemoryStream); Thanks for your help.
-
Remy, I do see the image in the TImage on the server application after it is send from the client app. I by accident remove the rest to 0, but still no file are saved. Here is the Client side running on Android. procedure TMainForm.SendPicture; var MemoryStream: TMemoryStream; StringStream: TStringStream; JObj: TJSONObject; begin {$IFDEF MSWINDOWS} FImageFilePath := TPath.Combine(TPath.GetDocumentsPath, EditImage.Text); {$ENDIF} {$IFDEF ANDROID} FImageFilePath := TPath.Combine(TPath.GetSharedDocumentsPath, SetupForm.EditImage.Text); {$ENDIF} if not FileExists(FImageFilePath) then begin ShowMessage('No such file at ' + FImageFilePath + '!'); Exit; end; IdTCPClient1.Host := SetupForm.EditHost.Text; try IdTCPClient1.Port := Integer.Parse(SetupForm.EditPort.Text); except on EConvertError do begin ShowMessage('Wrong port value!'); Exit; end; end; if not IdTCPClient1.Connected then begin try IdTCPClient1.Connect; except on EIdSocketError do begin ShowMessage('Connection error!'); Exit; end; end; end else begin IdTCPClient1.Disconnect; Exit; end; TTask.Run( procedure begin MemoryStream := nil; StringStream := nil; JObj := nil; try MemoryStream := TMemoryStream.Create; MemoryStream.LoadFromFile(FImageFilePath); StringStream := TStringStream.Create(IdEncoderMIME1.Encode(MemoryStream),TEncoding.ASCII); JOBJ := TJSONObject.Create; JOBJ.AddPair('image_encoded', StringStream.DataString); JOBJ.AddPair('message', Edit1.Text); IdTCPClient1.Socket.WriteLn(JObj.ToJSON); TThread.Synchronize(nil, procedure begin ShowMessage('BASE64 Image and message successfully sent to server!'); end); finally IdTCPClient1.Disconnect; JObj.Free; StringStream.Free; MemoryStream.Free; end; end); end; Right no I'm testing the send and save on the server side, but eventually I would like to send and save an image displayed in a TImage on the client side and not a file. The TImage is from the camera.
-
Yes, it compiles and it prints. First It didn't print, but then I added the command Nextline(1) first and PrintText after then it printed. Now I just need to create the rest of the app. I'm working on two different apps at the same time as you can see on my posts, not getting enough sleep lately. Again, thanks for all your help.
-
I have this code where I send an jpg image with TidTCPClient to a TidTCPServer. On the Server side the image aperea in a TImage, but no file is created when I save it. I tried using .jpg as well I try to use the MemoryStream.SaveToFile. I look in many forums and it looks like the do the same thing, what is wrong with this code? Here is the server code. procedure TMainForm.IdTCPServer1Execute(AContext: TIdContext); var JSON: TJSONObject; StringStream: TStringStream; MemoryStream: TMemoryStream; begin MemoryStream := nil; StringStream := nil; JSON := nil; try StringStream := TStringStream.Create('', TEncoding.ASCII); AContext.Connection.IOHandler.LargeStream := True; AContext.Connection.IOHandler.ReadStream(StringStream, SizeOf(StringStream), True); JSON := TJSONObject.ParseJSONValue(StringStream.DataString) as TJSONObject; MemoryStream := TMemoryStream.Create; IdDecoderMIME1.DecodeStream(JSON.GetValue('image_encoded').Value, MemoryStream); TThread.Synchronize(nil, procedure begin Edit2.Text := ''; Edit2.Text := JSON.GetValue('message').Value; Image1.Bitmap.LoadFromStream(MemoryStream); end); finally MemoryStream.Free; StringStream.Free; JSON.Free; end; SaveImageToDisk; end; procedure TMainForm.SaveImageToDisk; var CsFilename: String; begin CsFilename := Edit2.Text + '.png'; Image1.Bitmap.SaveToFile(CsFilename); end;
-
Great, that did it.
-
Ok it works, just had to open the port in the firewall.
-
Sorry, I still have problems when compiling the new JavaInterfaces.pas I get those errors all the way down from JSrPrinter_10 [JavaSignature('com/sr/SrPrinter$10')] JSrPrinter_10 = interface(JRunnable) ['{A13C6C9C-B945-4438-A33F-1B4453FD0555}'] function _Getval$line: Integer; cdecl; //function needs result type. With a red line under the $ sign procedure run; cdecl; property val$line: Integer read _Getval$line; // property 'val' does not exsist in base class. With a red line under val($line), read and $ sign in Getval$text end; TJSrPrinter_10 = class(TJavaGenericImport<JSrPrinter_10Class, JSrPrinter_10>) end; Does it looks like Java2Op created some wrong classes? Is it something i can correct manually? Again, thanks for any help. JavaInterfaces.pas
-
Thanks a lot for your help, I would never had been able to find out this by my self. I was almost going back to Android Studio and make the app there.
-
No, that is the jar file they emailed me in the SDK, with the example. I just posted a bit of the sample, here is the SDK I was emailed. The SDK is 18mb here is my dropbox link. https://www.dropbox.com/scl/fi/0nw4mhyha0qx72m4dbgfn/Java-Printer-SDK.zip?rlkey=tcn49jv2vt4ofmg90xojnzun5&dl=0
-
I have used RestDebugger a lot, but I never tried to call a php script from it. I did find this https://www.linkedin.com/pulse/sending-data-between-embarcadero-delphi-fmx-apps-using-serge-pilko-lo06f/ I will try to if I can get it to work, my first try it timed out.
-
Thanks, It worked I don't get any errors. Now I just have to find out why it's not printing. When I look at the Android example code it looks like they jus send the command printText MainActivity.this.findViewById(R.id.test2).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { try { SrPrinter.getInstance(getApplicationContext()).printText(((EditText) findViewById(R.id.test1)).getText().toString()); } catch (Exception e) { e.printStackTrace(); } } }); Here are the the first part of the SrPrinter.class package com.sr; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.ServiceConnection; import android.graphics.Bitmap; import android.os.IBinder; import android.os.RemoteException; import java.util.Deque; import java.util.concurrent.LinkedBlockingDeque; import recieptservice.com.recieptservice.PSAMCallback; import recieptservice.com.recieptservice.PrinterInterface; import recieptservice.com.recieptservice.PrinterInterface.Stub; public class SrPrinter { static SrPrinter srPrinter; static Deque<Runnable> deque; static volatile PrinterInterface printerInterface = null; static boolean reconnect = false; static ServiceConnection serviceConnection = new ServiceConnection() { public void onServiceConnected(ComponentName componentName, IBinder iBinder) { SrPrinter.printerInterface = Stub.asInterface(iBinder); synchronized(SrPrinter.deque) { while(SrPrinter.printerInterface != null && !SrPrinter.deque.isEmpty()) { ((Runnable)SrPrinter.deque.poll()).run(); } } } public void onServiceDisconnected(ComponentName componentName) { SrPrinter.printerInterface = null; SrPrinter.reconnect = true; } }; public SrPrinter() { } public static synchronized SrPrinter getInstance(Context context) { Intent intent; if (srPrinter != null) { if (reconnect) { intent = new Intent(); intent.setClassName("recieptservice.com.recieptservice", "recieptservice.com.recieptservice.service.PrinterService"); context.startService(intent); context.bindService(intent, serviceConnection, 1); reconnect = false; } return srPrinter; } else { srPrinter = new SrPrinter(); deque = new LinkedBlockingDeque(); intent = new Intent(); intent.setClassName("recieptservice.com.recieptservice", "recieptservice.com.recieptservice.service.PrinterService"); context.startService(intent); context.bindService(intent, serviceConnection, 1); return srPrinter; } }
-
I have attached it here. printer.jar