我有一个矩形并用图像填充它
<Rectangle Height="95" Fill="{Binding Path=Image,RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay,Converter={StaticResource ConvertBase64toImage}}" Stroke="{x:Null}" x:Name="EditPhotoRectangel">
<Rectangle.BitmapEffect>
<DropShadowBitmapEffect ShadowDepth="7" Softness="0.75"/>
</Rectangle.BitmapEffect>
</Rectangle>
Image 是一个 base64 字符串,我为它设置了图像。
private string ImageToBase64(System.Drawing.Image image, ImageFormat format)
{
using (MemoryStream ms = new MemoryStream())
{
// Convert Image to byte[]
image.Save(ms, format);
byte[] imageBytes = ms.ToArray();
// Convert byte[] to Base64 String
string base64String = Convert.ToBase64String(imageBytes);
return base64String;
}
}
并使用转换器将 Base64 转换为 imagebrush 以填充矩形。
ImageBrush brush = new ImageBrush();
BitmapImage bitmap = new BitmapImage();
// convert base64string to byte[].
byte[] binaryData = System.Convert.FromBase64String((string)value);
bitmap.BeginInit();
// Initializes a new non-resizable instance of the MemoryStream class based on the binaryData array.
bitmap.StreamSource = new MemoryStream(binaryData);
bitmap.EndInit();
//set bitmapimage for brush imagesource
brush.ImageSource = bitmap;
return brush;
我的问题是:当我为这个Rectangle
填充选择一个图像时,我的图像翻转。