(原創) 如何使用C++/CLI读/写jpg檔? (.NET) (C++/CLI) (GDI+) (C/C++) (Image Processing)

Abstract
因为Computer Vision的作业,之前都是用C# + GDI+写,但这次的作业要做Grayscale Dilation,想用STL的Generic Algorithm写,但C++ Standard Library并无法读取jpg档,用其它Library又比较麻烦,所以又回头想到GDI+,能同时使用STL和GDI+的,也只有C++/CLI了,我想这也是C++/CLI的优势之一,可以让你同时发挥.NET Framework和STL的power,以下的范例demo如何使用C++/CLI配合GDI+将jpg档读进来,并写入jpg檔。

Introduction
此范例比须手动加上Reference System.Drawing.dll

 1ExpandedBlockStart.gifContractedBlock.gif/**//* 
 2InBlock.gif(C) OOMusou 2006 http://oomusou.cnblogs.com
 3InBlock.gif
 4InBlock.gifFilename    : ReadJpg.cpp
 5InBlock.gifCompiler    : Visual C++ 8.0
 6InBlock.gifDescription : Demo how to read/write jpg by GDI+
 7InBlock.gifRelease     : 11/19/2006
 8ExpandedBlockEnd.gif*/

 9None.gif
10None.gif#include "stdafx.h"
11None.gif
12None.gifusing namespace System::Drawing;
13None.gifusing namespace System::Drawing::Imaging;
14None.gif
15ExpandedBlockStart.gifContractedBlock.gifint main() dot.gif{
16InBlock.gif  Bitmap ^originalImage = gcnew Bitmap("lena.jpg");
17InBlock.gif  Bitmap ^newImage = gcnew Bitmap(originalImage->Width, originalImage->Height);
18InBlock.gif
19ExpandedSubBlockStart.gifContractedSubBlock.gif  for(int x = 0; x!= originalImage->Width;++x) dot.gif{
20ExpandedSubBlockStart.gifContractedSubBlock.gif    for(int y = 0; y != originalImage->Height; ++y) dot.gif{
21InBlock.gif      int r = originalImage->GetPixel(x,y).R;
22InBlock.gif      int g = originalImage->GetPixel(x,y).G;
23InBlock.gif      int b = originalImage->GetPixel(x,y).B;
24InBlock.gif
25InBlock.gif      newImage->SetPixel(x,y, Color::FromArgb(r, g, b));
26ExpandedSubBlockEnd.gif    }

27ExpandedSubBlockEnd.gif  }

28InBlock.gif
29InBlock.gif  newImage->Save("newlena.jpg");
30InBlock.gif
31InBlock.gif  return 0;
32ExpandedBlockEnd.gif}

See Also
(原創) 如何使用ANSI C/ISO C++讀寫24位元的bmp圖檔? (初級) (C/C++)
(原創) 如何使用ANSI C讀寫32位元的BMP圖檔? (C/C++) (C) (Image Processing)
(原創) 如何使用ANSI C讀寫24/32位元的BMP圖檔? (C/C++) (C) (Image Processing)
(原創) 如何用程序的方式载入jpg图形文件? (.NET) (GDI+) (ASP.NET) (Image Processing)

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/388660.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

猫眼电影评论_电影的人群意见和评论家的意见一样好吗?

猫眼电影评论Ryan Bellgardt’s 2018 movie, The Jurassic Games, tells the story of ten death row inmates who must compete for survival in a virtual reality game where they not only fight each other but must also fight dinosaurs which can kill them both in th…

c#对文件的读写

最近需要对一个文件进行数量的分割,因为数据量庞大,所以就想到了通过写程序来处理。将代码贴出来以备以后使用。 //读取文件的内容 放置于StringBuilder 中 StreamReader sr new StreamReader(path, Encoding.Default); String line; StringBuilder sb …

ai前沿公司_美术是AI的下一个前沿吗?

ai前沿公司In 1950, Alan Turing developed the Turing Test as a test of a machine’s ability to display human-like intelligent behavior. In his prolific paper, he posed the following questions:1950年,阿兰图灵开发的图灵测试作为一台机器的显示类似人类…

关于WKWebView高度的问题的解决

关于WKWebView高度的问题的解决 IOS端嵌入网页的方式有两种UIWebView和WKWebView。其中WKWebView的性能要高些;WKWebView的使用也相对简单 WKWebView在加载完成后,在相应的代理里面获取其内容高度,大多数网上的方法在获取高度是会出现一定的问题&#xf…

测试nignx php请求并发数,nginx 优化(突破十万并发)

一般来说nginx 配置文件中对优化比较有作用的为以下几项:worker_processes 8;nginx 进程数,建议按照cpu 数目来指定,一般为它的倍数。worker_cpu_affinity 00000001 00000010 00000100 00001000 00010000 00100000 01000000 10000000;为每个进…

mardown 标题带数字_标题中带有数字的故事更成功吗?

mardown 标题带数字统计 (Statistics) I have read a few stories on Medium about writing advice, and there were some of them which, along with other tips, suggested that putting numbers in your story’s title will increase the number of views, as people tend …

使用Pandas 1.1.0进行稳健的2个DataFrames验证

Pandas is one of the most used Python library for both data scientist and data engineers. Today, I want to share some Python tips to help us do qualification checks between 2 Dataframes.Pandas是数据科学家和数据工程师最常用的Python库之一。 今天,我…

置信区间的置信区间_什么是置信区间,为什么人们使用它们?

置信区间的置信区间I’m going to try something a little different today, in which I combine two (completely unrelated) topics I love talking about, and hopefully create something that is interesting and educational.今天,我将尝试一些与众不同的东西…

php中wlog是什么意思,d-log模式是什么意思

D-Log是一种高动态范围的视频素材记录格式,总而言之这个色彩模式为后期调色提供了更大的空间。在相机和摄影机拍摄时,一颗高性能的传感器通常支持11档以上的动态范围,而在8bit的照片或视频上,以符合人眼感知的Gamma进行机内处理和…

PowerShell入门(三):如何快速地掌握PowerShell?

如何快速地掌握PowerShell呢?总的来说,就是要尽可能多的使用它,就像那句谚语说的:Practice makes perfect。当然这里还有一些原则和方法让我们可以遵循。 有效利用交互式环境 一般来说,PowerShell有两个主要的运行环境…

pca 主成分分析_通过主成分分析(PCA)了解您的数据并发现潜在模式

pca 主成分分析Save time, resources and stay healthy with data exploration that goes beyond means, distributions and correlations: Leverage PCA to see through the surface of variables. It saves time and resources, because it uncovers data issues before an h…

UML-- plantUML安装

plantUML安装 因为基于intellid idea,所以第一步自行安装.setting->plugins 搜索plantUML安装完成后,重启idea 会有如下显示安装Graphviz 下载地址 https://graphviz.gitlab.io/_pages/Download/Download_windows.html配置Graphviz环境变量: dot -ver…

rstudio 关联r_使用关联规则提出建议(R编程)

rstudio 关联r背景 (Background) Retailers typically have a wealth of customer transaction data which consists of the type of items purchased by a customer, their value and the date they were purchased. Unless the retailer has a loyalty rewards system, they …

jquery数据折叠_通过位折叠缩小大数据

jquery数据折叠Sometimes your dataset is just too large, and you need a way to shrink it down to a reasonable size. I am suffering through this right now as I work on different machine learning techniques for checkers. I could work for over 18 years and buy…

新鬼影病毒

今天和明天是最后两天宿舍有空调的日子啦,暑假宿舍没空调啊,悲催T__T 好吧,今天是最精华的部分啦对于鬼影3的分析,剩下的都是浮云啦,alg.exe不准备分析了,能用OD调试的货.分析起来只是时间问题.但是MBR和之后的保护模式的代码就不一样啦同学们,纯静态分析,伤不起啊,各种硬编码,…

Silverlight:Downloader的使用(event篇)

(1)Downloader的使用首先我们看什么是Downloader,就是一个为描述Silverlight plug-in下载功能的集合.Downloader能异步的通过HTTP GET Request下载内容.他是一个能帮助Silverlight下载内容的一个对象,这些下载内容包括(XMAL content,JavaScript content,ZIP packages,Media,ima…

决策树信息熵计算_决策树熵|熵计算

决策树信息熵计算A decision tree is a very important supervised learning technique. It is basically a classification problem. It is a tree-shaped diagram that is used to represent the course of action. It contains the nodes and leaf nodes. it uses these nod…

Free SQLSever 2008的书

Introducing SQL Server 2008 http://csna01.libredigital.com/?urss1q2we6这是一本提供自由使用书!我把它翻译,或转送有什么关系!这样的书还是有几本吧,Introducing Linq,Introducting Silverlight,都是啊!嘿嘿。。。…

流式数据分析_流式大数据分析

流式数据分析The recent years have seen a considerable rise in connected devices such as IoT [1] devices, and streaming sensor data. At present there are billions of IoT devices connected to the internet. While you read this article, terabytes and petabytes…

Jenkins自动化CI CD流水线之8--流水线自动化发布Java项目

一、前提 插件:Maven Integration plugin 环境: maven、tomcat 用的博客系统代码: git clone https://github.com/b3log/solo.git 远端git服务器: [gitgit repos]$ mkdir -p solo [gitgit repos]$ cd solo/ [gitgit solo]$ git --…