Emad Younan

Emad Younan

  • NA
  • 67
  • 4.2k

Xamarin.android Convert from Binary To image

Mar 25 2020 11:10 AM
hello guys
i used this code to insert into my sql server the image i loaded
 
Stream st = ContentResolver.OpenInputStream(uri);
Android.Graphics.Bitmap bitmap = BitmapFactory.DecodeStream(st);
MemoryStream memoryStream = new MemoryStream();
bitmap.Compress(Android.Graphics.Bitmap.CompressFormat.Jpeg, 100, memoryStream);

byte[] data = memoryStream.ToArray();
image = Convert.ToBase64String(data);
 
my column type varbinary(MAX) of image

SqlCommand cm = new SqlCommand("update dbo.Members set Member_Name= '" + firs.Text + " " + second.Text + "',Image=CONVERT(Varbinary(MAX),'" + image + "'), Phone='" + phone.Text + "' where user_name ='" + mail.Text + "' ", cn);
cm.CommandTimeout = 0;
 
and when i load my app from start i select the info and sent them with intent to the next actiity like that
 
 
emailadress = dt.Rows[0]["user_name"].ToString();
user_name = dt.Rows[0]["Member_Name"].ToString();
image = dt.Rows[0]["Image"].ToString();
 
well my question how to reback that to bitmap to use into that code
 
i used this code but not working
image = Intent.GetStringExtra("Image") ?? "Data is not available";

byte[] bytes = Encoding.ASCII.GetBytes(image);

MemoryStream memoryStream = new MemoryStream();
memoryStream.Write(bytes, 0, bytes.Length);

bitmap = BitmapFactory.DecodeStream(memoryStream);
`circleImageView.SetImageBitmap(bitmap);`
 
thanks at advance

Answers (1)