(原創) 如何使用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.pswp.cn/news/388660.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/388660.shtml
英文地址,請注明出處:http://en.pswp.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…

128.Two Sum

題目: Given an array of integers, return indices of the two numbers such that they add up to a specific target. 給定一個整數數組,返回兩個數字的索引,使它們相加到特定目標。 You may assume that each input would have exactly on…

php獲取錯誤信息函數,關于php:如何獲取mail()函數的錯誤消息?

我一直在使用PHP mail()函數。如果郵件由于任何原因未發送,我想回顯錯誤消息。 我該怎么做?就像是$this_mail mail(exampleexample.com, My Subject, $message);if($this_mail) echo sent!;else echo error_message;謝謝!當mail()返回false時…

關于夏季及雷雨天氣的MODEM、路由器使用注意事項

每年夏季是雷雨多發季節,容易出現家用電腦因而雷擊造成電腦硬件的損壞和通訊故障,為了避免這種情況的的發生,保護您的財產不受損失(一般雷擊照成損壞的設備是沒得保修的),建議您繼續閱讀下面內容&#xff1…

創建Console應用程序,粘貼一下代碼,創建E://MyWebServerRoot//目錄,作為虛擬目錄,親自測試通過,

創建Console應用程序,粘貼一下代碼,創建E://MyWebServerRoot//目錄,作為虛擬目錄,親自測試通過, 有一個想法,調用ASP.DLL解析ASP,可是始終沒有找到資料,有待于研究,還有…

c#對文件的讀寫

最近需要對一個文件進行數量的分割,因為數據量龐大,所以就想到了通過寫程序來處理。將代碼貼出來以備以后使用。 //讀取文件的內容 放置于StringBuilder 中 StreamReader sr new StreamReader(path, Encoding.Default); String line; StringBuilder sb …

php表格tr,jQuery+ajax實現動態添加表格tr td功能示例

本文實例講述了jQueryajax實現動態添加表格tr td功能。分享給大家供大家參考,具體如下:功能:ajax獲取后臺返回數據給table動態添加tr/tdhtml部分:ajax部分:var year $(#year).val();//下拉框數據var province $(#prov…

maya的簡單使用

1、導出obj類型文件window - settings preferences - plug- in Manager objExport.mllfile - export selection就有OBJ選項了窗口-設置/首選項- 插件管理 objExport.mll文件-導出當前選擇2、合并元素在文件下面的下拉框,選擇多邊形。按住shift鍵&…

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年,阿蘭圖靈開發的圖靈測試作為一臺機器的顯示類似人類…

查看修改swap空間大小

查看swap 空間大小(總計): # free -m 默認單位為k, -m 單位為M   total used free shared buffers cached  Mem: 377 180 197 0 19 110  -/ buffers/ca…

關于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;為每個進…

多米諾骨牌v.1MEL語言

// // //Script Name:多米諾骨牌v.1 //Author:瘋狂小豬 //Last Updated: 2011.10.5 //Email:wzybwj163.com // //---------------------------------------------------------------------------- //-----------------------------------------------------------------…

THINKPHP3.2視頻教程

http://edu.51cto.com/lesson/id-24504.html lunix視頻教程 http://bbs.lampbrother.net/read-htm-tid-161465.html TP資料http://pan.baidu.com/s/1dDCLFRr#path%252Fthink 微信開發,任務吧,留著記號了

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 …

897. 遞增順序查找樹-未解決

897. 遞增順序查找樹 https://leetcode-cn.com/contest/weekly-contest-100/problems/increasing-order-search-tree/ package com.test;import java.util.ArrayList; import java.util.Collections; import java.util.List;/*** author stono* date 2018/9/2* 897. 遞增順序查…

Azure PowerShell (16) 并行開關機Azure ARM VM

《Windows Azure Platform 系列文章目錄》 并行開機腳本: https://github.com/leizhang1984/AzureChinaPowerShell/blob/master/ARM/2StartAzureARMVM/StartAzureRMVM.txt 并行關機腳本: https://github.com/leizhang1984/AzureChinaPowerShell/blob/mas…

使用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庫之一。 今天,我…

Maya開發

Maya開發(一)-- 緒論 (翻譯自Maya官方文檔)2008-05-09 15:33 緒論 Autodesk Maya 是一個開放的產品,就是說任何Autodesk以外的人都可以改變Maya現有的特征,或者 增加新的特性.你可以用兩個方法來修改MAYA: ME…

織夢在線報名平臺php,DedeCMSv5

DedeCMS v5國內專業的PHP網站內容管理系統-織夢內容管理系統v5.8 Roadmap狀態 ? 已完成 🔨 進行中 ? 未完成項目開發可以到織夢開發問題管理中進行交流反饋。🔨 調整DedeCMS目錄結構,將原有include中外部訪問的內容遷移出去;&am…