아래에 코드가 있습니다. 나는 어딘가에있는 그림 인 image2와 흰색 평면에있는 텍스트 인 image3을 가지고 있습니다. 예를 들어, "hello"는 기본 흰색 인 paint.exe로 작성되었습니다. 배경).그림에 문자를 쓰면서 문자를 쓰면서 그림을 그릴 수 있습니다.
그림에 텍스트를 표시하고 싶지만 코드가 성공하지 못합니다. 문제가 무엇입니까?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.IO;
namespace test_AlignmentOFImages
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
WriteableBitmap bitmap;
private void Window_Loaded(object sender, RoutedEventArgs e)
{
byte []pixels=new byte[480*640*4];
for (int i = 0; i < pixels.Length; i++)
{
if (i % 16 == 0)
{
pixels[i] = 0xff;
}
else
{
pixels[i] = (byte)i;
}
//pixels[i] = (byte)0xff;//white
}
int stride2 = 480 * 4;
image2.Source = BitmapImage.Create((int)image2.Width, (int)image2.Height, 96, 96, PixelFormats.Bgra32, null, pixels, stride2);
byte [] imagePixels=new byte[480*640*4];
System.Drawing.Image img;
//System.Drawing.Bitmap bm;
try
{
//img = System.Drawing.Image.FromFile(@"E:\src\Tests\test_AlignmentOFImages\test_AlignmentOFImages\image3.jpg");
img = System.Drawing.Image.FromFile(@"E:\src\Tests\test_AlignmentOFImages\test_AlignmentOFImages\image3.png");
}
catch (Exception ex)
{
throw ex;
}
MemoryStream ms=new MemoryStream();
img.Save(ms, System.Drawing.Imaging.ImageFormat.Png); //img.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
Array.Copy(ms.ToArray(), imagePixels, ms.ToArray().Length);
byte[] imagePixels2 = new byte[480 * 640*4];
image3.Source = null;
for (int i = 0; i < imagePixels.Length; i+=4)
{
if (imagePixels[i]<0xff )//if it is not white
{
imagePixels2[i] = imagePixels[i];//blue
imagePixels2[i+1] = imagePixels[i+1];//green
imagePixels2[i+2] = imagePixels[i+2];//red
imagePixels2[i+3] = 0xff;//alpha
}
}
image3.Source = BitmapImage.Create((int)image3.Width, (int)image3.Height, 96, 96, PixelFormats.Bgra32, null, imagePixels2, stride2);
}
}
}
내가 내가 거짓 픽셀 형식을 사용하고 있습니다 및 PNG 또는 JPEG 형식 내가 (예를 bgr24 또는 ...에 대한) 특별한 픽셀 형식을 사용해야한다고 생각합니다. 사전에 감사합니다.