1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | #include <stdio.h>//printf とかで必要 #include<windows.h>//MessageBox とかで必要 #include <wmsdk.h> #pragma comment(lib, "wmvcore.lib") #include "wmp.h" void main( void ) { IWMMetadataEditor * pEditor = NULL; IWMHeaderInfo3 * pHeaderInfo = NULL; IWMPMedia3 * spCurrMedia3 = NULL; //IWMPMedia3* Media; //IWMHeaderInfo3 HRESULT hr = S_FALSE; hr = WMCreateEditor(&pEditor); hr = pEditor->Open(L "G:\\sampleMovie\\sample.mp3" ); pEditor->QueryInterface(IID_IWMHeaderInfo, ( void **) &pHeaderInfo); WM_PICTURE* pPicture = NULL;; WORD wStreamNum = 0; WORD wLength = 0; WMT_ATTR_DATATYPE wmtDataType = WMT_TYPE_BINARY; hr = pHeaderInfo->GetAttributeByName(&wStreamNum, g_wszWMPicture, &wmtDataType, NULL, &wLength); if (SUCCEEDED(hr)) { printf ( "成功\n" ); } pPicture = (WM_PICTURE*) new BYTE [wLength]; hr = pHeaderInfo->GetAttributeByName(&wStreamNum, g_wszWMPicture, &wmtDataType, ( BYTE *)pPicture, &wLength); if (SUCCEEDED(hr)) { printf ( "成功\n" ); } MessageBox(0,0,TEXT( "OK" ),0); } |
WM_PICTURE structure で調べたら
pwszMIMETypeは image/jpeg
bPictureType が3なので 、前面の写真のようです。
バイナリエディッタでファイルを開いてみた。
jpeg 形式で保存してみる。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | // WMPConsoleApplication1.cpp : メイン プロジェクト ファイルです。 #include "stdafx.h" #include <stdio.h> #include <wmsdk.h> #include "wmp.h" //#pragma comment(lib, "user32.lib") #pragma comment(lib, "wmvcore.lib") using namespace System; using namespace System::IO; //using namespace System::IO::MemoryStream; int main(array<System::String ^> ^args) { Console::WriteLine(L "プログラムスタート" ); IWMMetadataEditor * pEditor = NULL; IWMHeaderInfo3 * pHeaderInfo = NULL; IWMPMedia3 * spCurrMedia3 = NULL; HRESULT hr = S_FALSE; hr = WMCreateEditor(&pEditor); hr = pEditor->Open(L "G:\\sampleMovie\\Amanda.wma" ); hr = pEditor->QueryInterface(IID_IWMHeaderInfo, ( void **) &pHeaderInfo); WM_PICTURE* pPicture = NULL;; WORD wStreamNum = 0; WORD wLength = 0; WMT_ATTR_DATATYPE wmtDataType = WMT_TYPE_BINARY; hr = pHeaderInfo->GetAttributeByName(&wStreamNum, g_wszWMPicture, &wmtDataType, NULL, &wLength); if (SUCCEEDED(hr)) { printf ( "成功\n" ); } pPicture = (WM_PICTURE*) new BYTE [wLength]; hr = pHeaderInfo->GetAttributeByName(&wStreamNum, g_wszWMPicture, &wmtDataType, ( BYTE *)pPicture, &wLength); if (SUCCEEDED(hr)) { printf ( "成功\n" ); } //画像の大きさ printf ( "画像の大きさ:%d \n" ,pPicture->dwDataLen); FILE *fp; /* ファイル操作で使用する変数 */ fp = fopen ( "D:\\sample.jpg" , "wb" ); fwrite ( pPicture->pbData , pPicture->dwDataLen , 1 , fp ); fclose ( fp ); Console::WriteLine(L "プログラム終了" ); Console::ReadLine(); return 0; } |
mp3 wma の形式で確認しました。
画像データがないmp3,wmaでは当然画像は取得できません。
ファイルエクスプローラの詳細で画像データが在るか確認できます。
0 件のコメント:
コメントを投稿