繁体   English   中英

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

[英]Add text to image using AForge.Video.FFMEG in C#

使用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);

如何将字符串写入Image?

创建视频之前,有什么方法可以将AForge.Video.FFMEG字幕添加到图像吗?

私有位图WriteString(Bitmap bmp){

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

似乎是错误的。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM