如何在C ++ / CLI项目中包含JpegBitmapDecoder ^

时间:2012-11-21 09:25:50

标签: c++ visual-studio-2010 command-line-interface jpeg

如在主题中如何在C ++ / CLI项目中包含JpegBitmapDecoder ^。我尝试了inlude命名空间,但我得到了:

Error   1   error C3083: 'Windows': the symbol to the left of a '::' must be a type C:\Users\Duke\Documents\Visual Studio 2010\Projects\Jpg\Jpg\Jpg.cpp 8   1   Jpg
Error   2   error C3083: 'Media': the symbol to the left of a '::' must be a type   C:\Users\Duke\Documents\Visual Studio 2010\Projects\Jpg\Jpg\Jpg.cpp 8   1   Jpg
Error   3   error C2039: 'Imaging' : is not a member of 'System'    C:\Users\Duke\Documents\Visual Studio 2010\Projects\Jpg\Jpg\Jpg.cpp 8   1   Jpg
Error   4   error C2871: 'Imaging' : a namespace with this name does not exist  C:\Users\Duke\Documents\Visual Studio 2010\Projects\Jpg\Jpg\Jpg.cpp 8   1   Jpg

.jpg的


// Jpg.cpp : Defines the entry point for the console application.
//

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

int _tmain(int argc, _TCHAR* argv[])
{


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

        JpegBitmapDecoder^ decoder = gcnew JpegBitmapDecoder(imageStreamSource, BitmapCreateOptions::PreservePixelFormat, BitmapCacheOption::Default);//i want that decoder
        BitmapSource^ bitmapSource = decoder->Frames[0];//< --mamy bitmape

        // Draw the Image
        Image^ myImage = gcnew Image();
        myImage->Source = bitmapSource;
        myImage->Stretch = Stretch::None;
        myImage->Margin = System::Windows::Thickness(20);
        //

        int width = 128;
        int height = width;
        int stride = width / 8;
        array<System::Byte>^ pixels = gcnew array<System::Byte>(height * stride);

        // Define the image palette
        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 个答案:

答案 0 :(得分:1)

请改用:

using namespace System::Windows::Media::Imaging;

显然,上面的那一行应该暗示在C ++ / CLI中,你使用::而不是.