首页 > 代码库 > Datasnap Image

Datasnap Image

delphi用,不能与java、c#互相识别。

procedure TServerMethods.UpdateDoc(ItemID : integer; doc : TStream);

 

delphi用,不能与java、c#互相识别。

procedure TServerMethods.UpLoadFile(ADoc: TJSONArray);

jsonArray := TDBXJSONTools.StreamToJSON(aStream, 0, aStream.Size);

bstream := TDBXJSONTools.JSONToStream(jsonArray);

技术分享
procedure TForm2.Button4Click(Sender: TObject);
var
  jpg, jpg2: TJPEGImage;
  aStream: TMemoryStream;
  bstream: TStream;
  jsonArray: TJSONArray;
begin
  jpg := TJPEGImage.Create;
  jpg.LoadFromFile(‘e:\test.jpg‘);
  Image1.Picture.Assign(jpg);

  aStream := TMemoryStream.Create;
  jpg.SaveToStream(aStream);

  aStream.Position := 0;
  jsonArray := TDBXJSONTools.StreamToJSON(aStream, 0, aStream.Size);
  RichEdit1.Text := jsonArray.Value;
  RichEdit1.Text := jsonArray.ToString;
  RichEdit1.Text := jsonArray.ToJSON; // 纯数字 不能跨语言 java c#互相识别

  // jsonArray:= TJSONObject.ParseJSONValue(RichEdit1.Text);
  bstream := TDBXJSONTools.JSONToStream(jsonArray);
  jpg2 := TJPEGImage.Create;
  bstream.Position := 0;
  jpg2.LoadFromStream(bstream);
  Image2.Picture.Assign(jpg2);
  jpg.Free;
end;
View Code

 

http://www.cnblogs.com/codingnote/archive/2012/04/09/2438673.html

http://stackoverflow.com/questions/16550915/how-to-convert-a-json-string-to-an-image

 http://blog.csdn.net/shandiantianying/article/details/9022121

string,base64

 

 class function CreateTDataSetFromJSON(value: TJSONObject): TDataset;
 class function TDataSetToJSONObject(value: TDataset): TJSONObject;

跨语言C#、java

Delphi读取b64字符串

procedure TForm2.Button3Click(Sender: TObject);
var
  strStream: TStringStream;
  b64: TBase64Encoding;
  aStream: TMemoryStream;
  jpg2: TJPEGImage;
begin
  strStream := TStringStream.Create;
  strStream.LoadFromFile(e:\b64CSharp.txt);
  strStream.Position := 0;

  b64 := TBase64Encoding.Create;
  aStream := TMemoryStream.Create;
  b64.Decode(strStream, aStream);
  aStream.Position := 0;
  jpg2 := TJPEGImage.Create;
  jpg2.LoadFromStream(aStream);

  Image2.Picture.Assign(jpg2);

  strStream.Free;
  b64.Free;
  aStream.Free;
  jpg2.Free;

end;

c#图片base64编码

        private void button1_Click(object sender, EventArgs e)
        {
            System.IO.MemoryStream ms = new System.IO.MemoryStream();
            System.Drawing.Bitmap bp = new Bitmap(@"e:\test.jpg");
            bp.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
            byte[] b = ms.GetBuffer();

            this.richTextBox1.Text = Convert.ToBase64String(b);
             
        }

 C#图片baes64解码

byte[] bt = Convert.FromBase64String(base64string);
System.IO.MemoryStream stream = new System.IO.MemoryStream(bt);
Bitmap bitmap = new Bitmap(stream);
pictureBox1.Image = bitmap;

 

Datasnap Image