[erledigt] Image & Bilddaten holen - Marhsal::Copy



  • Moin,

    void Picture::Init(Bitmap ^image)
    {
    	logger->war("!! ACHTUNG !! Bilddaten aus Image holen ist noch nicht getestet !!");
    
    	if (!image)
    	{
    		logger->war("Image ist nullptr -> erzeuge Bild mit Default-Werten");
    		Init(352, 288);
    		return;
    	}
    
    	Init(image->Width, image->Height);
    
    	Imaging::BitmapData ^bmpData = image->LockBits(Rectangle(0, 0, width, height), Imaging::ImageLockMode::ReadOnly, image->PixelFormat);
    	IntPtr ^ptr = bmpData->Scan0;
    	int stride = bmpData->Stride;
    	int bytes = stride * height;
    	array<unsigned char> ^bildDaten = gcnew array<unsigned char>(bytes);
    	Runtime::InteropServices::Marshal::Copy(ptr, bildDaten, 0, bytes);
    	image->UnlockBits(bmpData);
    }
    

    das Problem ist eben jenes Marshal::Copy ... das wird permanent vom Compiler bemosert

    .\Picture.cpp(44) : error C2665: "System::Runtime::InteropServices::Marshal::Copy": Durch keine der 16 Überladungen konnten alle Argumenttypen konvertiert werden.
            c:\windows\microsoft.net\framework\v2.0.50727\mscorlib.dll: kann 'void System::Runtime::InteropServices::Marshal::Copy(cli::array<Type,dimension> ^,int,System::IntPtr,int)' sein
            with
            [
                Type=int,
                dimension=1
            ]
    .... (und so weiter)
    

    ich dachte eigentlich ich habe die richtige Überladung erwischt

    Marshal::Copy(IntPtr, array<Byte>, Int32, Int32)
    

    hand, mogel



  • ev.

    Runtime::InteropServices::Marshal::Copy(ptr, bildDaten, int(0), bytes);
    

    ?



  • nein -.-



  • Hat sich geklärt,

    IntPtr ^ptr = bmpData->Scan0;
    

    muss einfach nur

    IntPtr ptr = bmpData->Scan0;
    

    sein ... das Beispiel in der MSDN ist auch recht hilfreich http://msdn.microsoft.com/de-de/library/5ey6h79d(VS.80).aspx

    danke, mogel


Anmelden zum Antworten