【问题标题】:flip image in before send it to API as Base64 Xamarin forms在将图像作为 Base64 Xamarin 形式发送到 API 之前翻转图像
【发布时间】:2019-11-06 04:54:45
【问题描述】:

我从设备中选择了一个图像,它是正常的,但我想在将其发送到 API 之前水平翻转它,以便在正常未镜像后预览它,并在 base64 字符串图像上执行此操作。

【问题讨论】:

  • 嗨,你解决了吗?
  • 是的,但是当它在 android 和 iOS 上位图不是 base64 时设法翻转它,解决方案在下面的答案中
  • 太好了,看到了:)

标签: c# image xamarin.forms


【解决方案1】:

但是,您尚未发布所有信息。 在 Xamarin Forms Platform 中,您可以使用支持您正在寻找的转换的 FFImageLoading 插件。它支持:

  • 翻转变换
  • 旋转变换

点击链接在此处找到它们的实现: https://github.com/luberda-molinet/FFImageLoading/blob/master/samples/ImageLoading.Forms.Sample/Shared/Pages/Transformations/FlipTransformationPage.xaml

【讨论】:

    【解决方案2】:

    你的问题没有清楚地解释你想做什么。你可以更新它,更详细地说明你想把什么类型转换成什么类型​​。无论如何,我给出了一个可能的答案。

    base64字符串的图片路径

    // provide read access to the file
    FileStream fs = new FileStream(media.Path, FileMode.Open,FileAccess.Read);
    // Create a byte array of file stream length
    byte[] ImageData = new byte[fs.Length];
    //Read block of bytes from stream into the byte array
    fs.Read(ImageData,0,System.Convert.ToInt32(fs.Length));
    //Close the File Stream
    fs.Close();
    string _base64String = Convert.ToBase64String (ImageData);
    

    base64字符串转字节[]

    byte[] data = Convert.FromBase64String (FileRespone);
    

    【讨论】:

      【解决方案3】:

      我曾经将图像翻转为位图而不是 Base64 在安卓中 https://acomputerengineer.wordpress.com/2016/06/07/flip-imagebitmap-horizontally-and-vertically-in-android/

      在IOS中:
      How to flip UIImage horizontally?

      UIImage sourceImage = uiImage;//[UIImage imageNamed: @"whatever.png"];
      
                 UIImage flippedImage = sourceImage.GetImageFlippedForRightToLeftLayoutDirection();
                     //[UIImage imageWithCGImage: sourceImage.CGImage    scale: sourceImage.scale  orientation: UIImageOrientationUpMirrored];
      

      【讨论】:

        猜你喜欢
        • 2021-08-06
        • 1970-01-01
        • 1970-01-01
        • 2017-05-17
        • 2019-09-15
        • 1970-01-01
        • 1970-01-01
        • 2021-09-21
        • 1970-01-01
        相关资源
        最近更新 更多