2012-11-22 4 views
1

CLI/C++로 이미지를로드 했으므로 Form에 표시하고 싶습니다. (프로그램을 실행할 때 Form1이 켜지면서 거기에 넣는 방법이 있습니다.) 어떤 이미지를 양식에 넣고 싶습니다.로드 된 이미지를 넣는 방법 CLI/C++

// a.cpp : 주 프로젝트 파일.

#include "stdafx.h" 
#include "Form1.h" 
#using <mscorlib.dll> //requires CLI 
using namespace System; 
using namespace System::IO; 
using namespace System::Windows::Media::Imaging; 
using namespace System::Windows::Media; 
using namespace System::Windows::Controls; 
using namespace a; 

[STAThreadAttribute] 
int main(array<System::String ^> ^args) 
{ 
    // Enabling Windows XP visual effects before any controls are created 
    Application::EnableVisualStyles(); 
    Application::SetCompatibleTextRenderingDefault(false); 

    // Create the main window and run it 
    Application::Run(gcnew Form1()); 


    // Open a Stream and decode a JPEG image 
     Stream^ imageStreamSource = gcnew FileStream("C:/heart.jpg", FileMode::Open, FileAccess::Read, FileShare::Read); 

     JpegBitmapDecoder^ decoder = gcnew JpegBitmapDecoder(imageStreamSource, BitmapCreateOptions::PreservePixelFormat, BitmapCacheOption::Default); 
     BitmapSource^ bitmapSource = decoder->Frames[0];//< --mamy bitmape 
     // Draw the Image 
     System::Windows::Controls::Image^ myImage = gcnew System::Windows::Controls::Image(); //<--- this image in the Form1 ------- 
     myImage->Source = bitmapSource; 
     myImage->Stretch = Stretch::None; 
     int width = 128; 
     int height = width; 
     int stride = width/8; 
     array<System::Byte>^ pixels = gcnew array<System::Byte>(height * stride); 

     // Define the image paletteo 
     BitmapPalette^ myPalette = BitmapPalettes::Halftone256; 

     // Creates a new empty image with the pre-defined palette. 
     BitmapSource^ image = BitmapSource::Create(
      width, height, 
      96, 96, 
      PixelFormats::Indexed1, 
      myPalette, 
      pixels, 
      stride); 

     System::IO::FileStream^ stream = gcnew System::IO::FileStream("new.jpg", FileMode::Create); 
     JpegBitmapEncoder^ encoder = gcnew JpegBitmapEncoder(); 
     TextBlock^ myTextBlock = gcnew System::Windows::Controls::TextBlock(); 
     myTextBlock->Text = "Codec Author is: " + encoder->CodecInfo->Author->ToString(); 
     encoder->FlipHorizontal = true; 
     encoder->FlipVertical = false; 
     encoder->QualityLevel = 30; 
     encoder->Rotation = Rotation::Rotate90; 
     encoder->Frames->Add(BitmapFrame::Create(image)); 
     encoder->Save(stream); 
    return 0; 
} 
+1

왜 C#을 태그 것을 할 수있는 더 쉬운 방법은 ++ 있다는 것을. 인터넷을로드하는 방법? 질문에 C#에 대한 참조가 보이지 않습니다. – caesay

답변

0

닷넷 Graphics 클래스 (GDI +)는 물론, 그리기 그래픽에 좋은 곳입니다. 캔버스에 이미지를 그리는 것이 아니라 다른 많은 것들을 그리는 데 사용할 수 있습니다. 'GDI + tutorials'또는 '.NET Graphics'와 같은 무언가를 찾을 수 있습니다. 또한

, 당신은 JPEG, 당신은 분명 C에서 작업 할 때 .NET에서

+0

나중에 C++을 사용할 필요가 있습니다. 퍼팅의 명령이 될 것입니다. –

+0

죄송합니다. O_o – Aaron

+0

이것은 양식 응용 프로그램의 일부입니다. Form1.h 나는 그것을 참조하는 방법을 모르고이 형식으로이로드 된 이미지를 넣습니다. –

관련 문제