Мне нужно generate an image from a string
в моем приложении WPF и показать его.Вот мой код:
// Create Image and generate string on it
ystem.Windows.Controls.Image img = new System.Windows.Controls.Image();
// This is the font that I need to render
Font DefaultFont = new Font("Oybab Tuz", 40f, System.Drawing.FontStyle.Regular, GraphicsUnit.Pixel);
// Generate image from string
GraphicsPath graphicsPath = new GraphicsPath();
// As you see, the string include Right to left character, also include some other character in the middle
graphicsPath.AddString("سىناق123456789سىناق", DefaultFont.FontFamily, (int)DefaultFont.Style, DefaultFont.Size * 96f / 72f, new PointF(0f, 0f), StringFormat.GenericDefault);
// Turn the string to the image
RectangleF bounds = graphicsPath.GetBounds();
Bitmap bitmap = new Bitmap((int)(bounds.Width + bounds.X), (int)(bounds.Height + bounds.Y));
Graphics graphic = Graphics.FromImage(bitmap);
graphic.FillPath(new SolidBrush(System.Drawing.Color.FromArgb(0x33, 0x00, 0xFF)), graphicsPath);
graphicsPath.Dispose();
graphic.Dispose();
// turn the Image to ImageSource
MemoryStream memoryStream = new MemoryStream();
bitmap.Save(memoryStream, ImageFormat.Png);
img.Source = (ImageSource)(new ImageSourceConverter()).ConvertFrom(memoryStream);
// Add the image to the window content
this.Content = img;
Теперь это будет отлично отображаться в windows 10
, например, так:
![In the windows 10 operating system](https://i.stack.imgur.com/b53mD.png)
Но если операционная система ниже Windows 10, например: Windows XP
, Windows 7
, Windows 8.X
, она будет отображаться так:
![enter image description here](https://i.stack.imgur.com/3En4a.png)
Также не только число, если я добавлю другой символ, такой как: "&&"
"سىناق && سىناق"
Нижняя операционная система по-прежнему показывает его как:
"سىناق سىناق"
похоже, что операционная система автоматически удаляет символов в середине.
Iзнал шрифт, который я использую в нем is not include the number or the character which I put
, но Windows 10 могла бы отображать его правильно.
Вот шрифт: Загрузить файл шрифта
Посколькуперсонаж будет отображаться не только в определенном месте, поэтому I can't split the string, and render it one by one
.
Так что я действительно хочу знать why
, а также I hope some guys could give me advice to fix this problem when operating system lower than Windows 10
.Спасибо.