当前位置: 首页 > news >正文

cms企业网站模板微信广点通广告平台

cms企业网站模板,微信广点通广告平台,三合一网站方案,二次开发英语目录 1 程序框架简介 2 C#图像读取、显示、保存模块 3 C动态库图像算法模块 4 C#调用C动态库 5 演示Demo 5.1 开发环境 5.2 功能介绍 5.3 下载地址 参考 1 程序框架简介 一个图像处理算法研究的常用程序逻辑框架,如下图所示 在该框架中,将图像处…

目录

1 程序框架简介

2 C#图像读取、显示、保存模块

3 C动态库图像算法模块

4 C#调用C动态库

5 演示Demo

5.1 开发环境

5.2 功能介绍

5.3 下载地址

参考


1 程序框架简介

        一个图像处理算法研究的常用程序逻辑框架,如下图所示

        在该框架中,将图像处理算法产品分为上层模块和底层模块两个部分。

        底层模块使用C/C++实现算法API,提供给上层模块调用;上层模块执行调用API和一些界面功能的实现,最后得到不同平台的软件产品。

        本文使用使用C/C++进行图像算法API开发,具有安全、高效和方便多平台移植的优点,目前大多数图像软件都是基于C/C++来开发的;使用C#来做上层调用与界面设计,是因为C#具有优秀的面向对象能力,界面设计方便快捷,而且对于图像读取、保存、显示已经做了良好的封装,避免了图像编解码的问题,相对使用MFC大大简化了开发逻辑,提升了开发效率。

2 C#图像读取、显示、保存模块

        代码相对简单,直接给出模块代码

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Drawing.Imaging;
using System.IO;namespace ImageProcessDemo
{public partial class FormMain : Form{public FormMain(){InitializeComponent();}#region  变量名字// 图像文件名称private String curFileName = null;// 当前图像变量private Bitmap curBitmap = null;// 原图private Bitmap srcBitmap = null;#endregion#region  图像打开和保存模块// 图像打开public void OpenFile(){OpenFileDialog ofd = new OpenFileDialog();ofd.Filter = "所有图像文件 | *.bmp; *.pcx; *.png; *.jpg; *.gif;" +"*.tif; *.ico; *.dxf; *.cgm; *.cdr; *.wmf; *.eps; *.emf|" +"位图( *.bmp; *.jpg; *.png;...) | *.bmp; *.pcx; *.png; *.jpg; *.gif; *.tif; *.ico|" +"矢量图( *.wmf; *.eps; *.emf;...) | *.dxf; *.cgm; *.cdr; *.wmf; *.eps; *.emf";ofd.ShowHelp = true;ofd.Title = "打开图像文件";if (ofd.ShowDialog() == DialogResult.OK){curFileName = ofd.FileName;try{curBitmap = (Bitmap)System.Drawing.Image.FromFile(curFileName);srcBitmap = new Bitmap(curBitmap);}catch (Exception exp){ MessageBox.Show(exp.Message); }}}// 图像保存public void SaveFile(){SaveFileDialog sfd = new SaveFileDialog();sfd.Filter = @"Bitmap文件(*.bmp)|*.bmp|Jpeg文件(*.jpg)|*.jpg|PNG文件(*.png)|*.png|所有合适文件(*.bmp,*.jpg,*.png)|*.bmp;*.jpg;*.png";sfd.FilterIndex = 3;sfd.RestoreDirectory = true;if (sfd.ShowDialog() == DialogResult.OK){ImageFormat format = ImageFormat.Jpeg;switch (Path.GetExtension(sfd.FileName).ToLower()){case ".jpg":format = ImageFormat.Jpeg;break;case ".bmp":format = ImageFormat.Bmp;break;case ".png":format = ImageFormat.Png;break;default:MessageBox.Show("Unsupported image format was specified!");return;}pictureBox1.Image.Save(sfd.FileName, format);}}// 鼠标按键按下显示原图private void pictureBox1_MouseDown(object sender, MouseEventArgs e){if (srcBitmap != null)pictureBox1.Image = srcBitmap;}// 鼠标按键抬起显示效果图private void pictureBox1_MouseUp(object sender, MouseEventArgs e){if (curBitmap != null)pictureBox1.Image = curBitmap;}// open按钮事件private void btn_open_Click(object sender, EventArgs e){OpenFile();if (curBitmap != null){pictureBox1.Image = (Image)curBitmap;}}// save按钮事件private void btn_save_Click(object sender, EventArgs e){if (pictureBox1.Image != null)SaveFile();}#endregion}
}

3 C动态库图像算法模块

        构建C实现获取像素RGB值的API代码。

#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <stdio.h>#include "ImageProcessAPI.h"int getPixel(unsigned char *srcData, int width, int height, int stride, int x, int y, int rgba[4])
{x = x < 0 ? 0 : (x > width - 1 ? width - 1 : x);y = y < 0 ? 0 : (y > height - 1 ? height - 1 : y);int ret = 0;if(srcData == NULL){printf("input image is null!");return -1;}// 图像处理,获取像素RGBAint pos = x * 4 + y * stride;rgba[0] = srcData[pos + 2];rgba[1] = srcData[pos + 1];rgba[2] = srcData[pos + 0];rgba[3] = srcData[pos + 3];return ret;
};

4 C#调用C动态库

        在C#中调用C/C++动态库需要引用 System.Runtime.InteropServices 命名空间,实例代码如下

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Drawing.Imaging;
using System.Runtime.InteropServices;namespace ImageProcessDemo
{unsafe class ImageProcessBitmap{// 引用DLL中的方法,此处ImageProcessDll为DLL的名字[DllImport("ImageProcessDll.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.None, ExactSpelling = true)]// 封装C中的API接口,此处应注意C#和C之间的数据类型转换问题,所有参数的数据类型必须一致// getPixel为C中的接口名称private static extern int getPixel(byte* srcData, int width, int height, int stride, int x, int y, int[] rgba);// C#层接口调用// GetImgPixel为C#中封装的接口名称,该接口调用C中的getPixelpublic Bitmap GetImgPixel(Bitmap src, int x, int y, ref int[] rgba){// 生成图像备份Bitmap a = new Bitmap(src);// 获取图像的宽度和高度int w = a.Width;int h = a.Height;// 获取并锁定图像数据区域// 依据图像格式可选择16/24/32位等格式BitmapData srcData = a.LockBits(new Rectangle(0, 0, a.Width, a.Height), ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);// 传递给C接口getPixel((byte*)srcData.Scan0, w, h, srcData.Stride, x, y, rgba);// 解锁图像数据区域a.UnlockBits(srcData);return a;}}
}

        在C#界面中增加代码实现:用鼠标单击图像,界面上就会显示对应位置像素的RGB值。

        #region 图像处理,用鼠标单击图像,界面上就会显示对应位置像素的RGB值// 图像处理类ImageProcessBitmap imageProcess = new ImageProcessBitmap();// 变量private int[] rgba = new int[4];private void pictureBox1_MouseMove(object sender, MouseEventArgs e){if (pictureBox1.Image != null){curBitmap = imageProcess.GetImgPixel(srcBitmap, e.X, e.Y, ref rgba);label_rgba.Text = "RGBA: (" + rgba[0].ToString() + "," + rgba[1].ToString() + "," + rgba[2].ToString() + "," + rgba[3].ToString() + ")";}}#endregion

5 演示Demo

5.1 开发环境

  • Windows 10 Pro x64

  • Visual Studio 2015

5.2 功能介绍

        演示程序主界面如下图所示,具有图像读取、显示、保存以及随着光标的滑动会动态显示光标所在位置对应图像像素的RGB值等功能。

5.3 下载地址

        开发环境:

  • Windows 10 pro x64

  • Visual Studio 2015

        下载地址: 图像处理算法研究的程序框架

参考

        图像视频滤镜与人像美颜美妆算法详解. 胡耀武、谭娟、李云夕. 电子工业出版社、2020-07

http://www.zhongyajixie.com/news/57454.html

相关文章:

  • asp.net 网站图标聊城seo整站优化报价
  • 泉州哪里做网站开发免费的黄冈网站代码
  • 专注网站建设11年东莞网站推广方案
  • 杭州做网站的公司企业培训课程清单
  • 广告网站建设制作设计优化设计高中
  • 企业网站开发论文seo成功案例分析
  • 鲜花网站建设的利息分析电子商务平台
  • 学习做网站最新引流推广方法
  • 网络品牌维护武汉seo网站优化排名
  • 苏州外贸网站建站企业百度推广怎么收费
  • 做兼职什么网站最靠谱吗广告宣传语
  • 北京网站建设++知乎班级优化大师官方免费下载
  • 张家港外贸网站设计媒体发稿费用
  • 做海报素材的网站在百度怎么免费发布广告
  • 西安南郊网站建设接单平台
  • 牛商网建设的食品网站深圳外包seo
  • 安全网站建设网站制作企业管理8大系统
  • 网站内页的设计宁波网络推广
  • 清空wordpress多媒体站长之家seo查询
  • 网页制作的公司成都苏州网站优化排名推广
  • 揭阳企业网站建设公司谷歌推广怎么做最有效
  • 政府网站建设 价格宁德市
  • 网站建设投诉去哪里投诉成都网络营销搜索推广
  • 无锡网站建设运营代运营公司前十名
  • wordpress识别手机跳转网站深圳市推广网站的公司
  • 重庆的网站设计公司百度推广登陆后台
  • 建设工程合同属于什么合同网站seo排名公司
  • 怎么自己写网站百度手机助手下载安装最新版
  • 怎么样创建个人网站百度竞价点击软件奔奔
  • 长沙网站建设好处域名是什么意思呢