On Linux install System.Drawing.Common throw exception

博客记录了执行sudo apt-get install命令时出现获取dpkg前端锁失败的错误,给出了解决办法。包括删除与apt有关的进程、强制解锁、强制重新配置软件包、更新软件包源文件,最后重新执行安装命令。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

执行:

sudo apt-get update

sudo apt-get install -y --no-install-recommends libgdiplus libc6-dev

出现如下错误:

E: Could not get lock /var/lib/dpkg/lock-frontend - open (11: Resource temporarily unavailable)

E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), is another process using it?

 

解决

第一步:删除(kill)与apt有关的进程
例: 

hlp@hlp-Lenovo-G405:~$ ps afx|grep apt

 3284 pts/0    S+     0:00          \_ grep --color=auto apt

 2869 ?        Ss     0:00 /bin/sh /usr/lib/apt/apt.systemd.daily install

 2873 ?        S      0:00  \_ /bin/sh /usr/lib/apt/apt.systemd.daily lock_is_held install

 

hlp@hlp-Lenovo-G405:~$ sudo kill -9 2873

hlp@hlp-Lenovo-G405:~$ sudo kill -9 2869

 

第二步:强制解锁

sudo rm /var/lib/dpkg/lock

 

第三步:强制重新配置软件包

sudo dpkg --configure -a

 

第四步:更新软件包源文件

sudo apt update

 

重新执行:

sudo apt-get install -y --no-install-recommends libgdiplus libc6-dev

class RtspToImageConverter { private string rtspUrl; private string outputDirectory; private int captureInterval; // 捕获间隔(毫秒) private CancellationTokenSource cancellationTokenSource; public RtspToImageConverter(string rtspUrl, string outputDirectory, int captureInterval = 1000) { this.rtspUrl = rtspUrl; this.outputDirectory = outputDirectory; this.captureInterval = captureInterval; this.cancellationTokenSource = new CancellationTokenSource(); // 确保输出目录存在 if (!Directory.Exists(outputDirectory)) { Directory.CreateDirectory(outputDirectory); } } public async Task StartConversionAsync() { await Task.Run(() => CaptureFrames(), cancellationTokenSource.Token); } public void StopConversion() { cancellationTokenSource.Cancel(); } private void CaptureFrames() { using (VideoCapture capture = new VideoCapture(rtspUrl)) { if (!capture.IsOpened()) { Console.WriteLine($"无法打开RTSP流: {rtspUrl}"); return; } Console.WriteLine($"开始从RTSP流捕获帧: {rtspUrl}"); Mat frame = new Mat(); int frameCount = 0; while (!cancellationTokenSource.Token.IsCancellationRequested) { try { // 读取一帧 if (!capture.Read(frame)) { Console.WriteLine("无法读取帧,可能是流已关闭"); break; } if (!frame.Empty()) { // 生成输出文件名 string fileName = $"frame_{DateTime.Now:yyyyMMdd_HHmmss_fff}.jpg"; string filePath = Path.Combine(outputDirectory, fileName); // 将帧保存为JPEG图像 frame.SaveImage(filePath); frameCount++; Console.WriteLine($"已保存帧 {frameCount}: {filePath}"); } // 等待指定的间隔时间 Thread.Sleep(captureInterval); } catch (Exception ex) { Console.WriteLine($"捕获帧时发生错误: {ex.Message}"); // 发生错误时等待一段时间再重试 Thread.Sleep(1000); } } // 释放资源 frame.Dispose(); Console.WriteLine("已停止从RTSP流捕获帧"); } } }
最新发布
07-31
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值