如何将图像保存到sqlite数据库

问题描述:

在我的类我有一个方法,搜索图片库中的图片,也接收从手机相机拍摄的图像,我现在需要保存此图像在sqlite数据库。我正在使用像BLOB这样的数据库字段,但不喜欢在bity []中序列化图像或在decode64中转换以写入数据库。如何将图像保存到sqlite数据库

我想知道如果任何人有任何实施例来传递xaramin机器人我张贴接收图像的方法

protected override void OnActivityResult(int requestCode, Result resultCode, Intent data) 
     { 
      base.OnActivityResult(requestCode, resultCode, data); 

      // Make it available in the gallery 
      try 
      { 
       Intent mediaScanIntent = new Intent(Intent.ActionMediaScannerScanFile); 
       Uri contentUri = Uri.FromFile(App._file); 
       mediaScanIntent.SetData(contentUri); 
       SendBroadcast(mediaScanIntent); 

       // Display in ImageView. We will resize the bitmap to fit the display. 
       // Loading the full sized image will consume to much memory 
       // and cause the application to crash. 

       int height = Resources.DisplayMetrics.HeightPixels; 
       int width = imageView.Height; 
       App.bitmap = App._file.Path.LoadAndResizeBitmap(width, height); 
       if (App.bitmap != null) 
       { 
        imageView.SetImageBitmap(App.bitmap); 
        App.bitmap = null; 

       } 

       // Dispose of the Java side bitmap. 
       GC.Collect(); 
      } 
      catch 
      { 


      } 
      try 
      { 
       if (resultCode == Result.Ok) 
       { 
        var imageView = 
         FindViewById<ImageView>(Resource.Id.imageView1); 
         imageView.SetImageURI(data.Data); 

       } 
      } 
      catch { 

      } 

     } 
+1

那你尝试保存在数据库中的项目? –

代替存储&检索图像(字节[])作为从源码斑点分贝转换图像base64string和存储的图像作为在源码串和从源码而检索转换接收base64string到图像(字节[])

Base64的为位图:

public Bitmap Base64ToBitmap(String base64String) 
{ 
    byte[] imageAsBytes = Base64.Decode(base64String, Base64Flags.Default); 
    return BitmapFactory.DecodeByteArray(imageAsBytes, 0, imageAsBytes.Length); 
} 

位图转换为Base64:

public String BitmapToBase64(Bitmap bitmap) 
{ 
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); 
    bitmap.Compress(Bitmap.CompressFormat.Png, 100, byteArrayOutputStream); 
    byte[] byteArray = byteArrayOutputStream.ToByteArray(); 
    return Base64.EncodeToString(byteArray, Base64Flags.Default); 
} 
+0

Jay 对不起,延迟,但我怎样才能通过此功能的图像领域,并插入? – mba

+0

是的,你可以通过图像 –

+0

但我该怎么做? – mba