gpt4 book ai didi

c# - 在 C# 中使用 AForge.Video.FFMEG 向图像添加文本

转载 作者:行者123 更新时间:2023-12-04 22:55:44 27 4
gpt4 key购买 nike

使用 AForge.Video.FFMPEG我能够从图像创建视频。

        string[] files;
string folderPath = @"FolderPath";
files = Directory.GetFiles(folderPath).OrderBy(c => c).ToArray();

VideoFileWriter writer = new VideoFileWriter();
writer.Open(@"C:folder\new.mp4", imageWidth, imageHeight, 10, VideoCodec.MPEG4);
for (int j = 0; j < files.Length; j++)
{
string fileName = files[j];
BitmapSource imageBitMap = new BitmapImage(new Uri(fileName, UriKind.RelativeOrAbsolute));
imageBitMap.Freeze();
int stride = imageBitMap.PixelWidth * ((imageBitMap.Format.BitsPerPixel + 7) / 8);
byte[] ImageInBits = new byte[imageBitMap.PixelWidth * imageBitMap.PixelHeight];
imageBitMap.CopyPixels(ImageInBits, stride, 0);

Bitmap image = new Bitmap(imageWidth, imageHeight, stride, PixelFormat.Format8bppIndexed, Marshal.UnsafeAddrOfPinnedArrayElement(ImageInBits, 0));

writer.WriteVideoFrame(image);
image.Dispose();
}

我正在尝试使用将文本/字符串添加到输入图像
    private Bitmap WriteString(Bitmap bmp)
{
RectangleF rectf = new RectangleF(70, 90, 90, 50);

Bitmap tempBitmap = new Bitmap(bmp.Width, bmp.Height);
Graphics g = Graphics.FromImage(tempBitmap);

g.DrawImage(bmp, 0, 0);
g.SmoothingMode = SmoothingMode.AntiAlias;
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
g.PixelOffsetMode = PixelOffsetMode.HighQuality;
g.DrawString("yourText", new Font("Tahoma", 8), Brushes.Red, rectf);
g.Flush();

return bmp;
}

喜欢
            Bitmap image = new Bitmap(imageWidth, imageHeight, stride, PixelFormat.Format8bppIndexed, Marshal.UnsafeAddrOfPinnedArrayElement(ImageInBits, 0));
Bitmap outputBitmap=WriteString(image);
writer.WriteVideoFrame(outputBitmap);

如何将字符串写入图像?

有没有办法给 AForge.Video.FFMEG加字幕在创建视频之前进行图像处理?

最佳答案

私有(private)位图写入字符串(位图 bmp){

    Bitmap tempBitmap = new Bitmap(bmp.Width, bmp.Height); << create new    
..draw on copy..
return bmp; <<< return original
}

似乎是错误的。

关于c# - 在 C# 中使用 AForge.Video.FFMEG 向图像添加文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44983204/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com