Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8864955
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T16:23:00+00:00 2026-06-14T16:23:00+00:00

I get weird information about invalidOperationException in PresentationCore.dll while constructing an image by gcnew

  • 0

I get weird information about invalidOperationException in PresentationCore.dll while constructing an image by gcnew Image().

I attach project and the JPG file (which can be put in C:\) It actually cannot be checked other way because configuration of project (references) took a long time, and just copied code will not work.

http://www.speedyshare.com/Vrr84/Jpg.zip

How can I solve that problem?

enter image description here


 // 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;
using namespace System::Windows::Media;
using namespace System::Windows::Controls;
int _tmain(int argc, _TCHAR* argv[])
{


    // 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
        Image^ myImage = gcnew Image();//<----------- ERROR
        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 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 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T16:23:03+00:00Added an answer on June 14, 2026 at 4:23 pm

    The core issue is there:

    The calling thread must be STA […]

    Your main thread must be marked as a single-threaded apartment (STA for short) for WPF to function correctly. The fix? Add [System::STAThread] to your _tmain, thus informing the runtime that the main thead has to be STA.

    [System::STAThread]
    int _tmain(int argc, _TCHAR* argv[])
    {
        // the rest of your code doesn't change
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've seen a number of questions about using JS to get detailed information about
I get some weird overflow whenever I want to fit an object inside foreignObject
I get a weird problem. Getting java.util.ConcurrentModificationException . But I'm not modifying the current
Hello I get a weird error in this code: function validateForm(aform) { var s=;
when i use connection.queries in django i get a weird exception: 'list' object is
I'm trying to use Asp.NET WebAPI module but I get a weird error. When
I tried to get into pyglet and opengl and come up with weird results
I've stuck into some weird problem. Here is the code AccountsController.cs // GET /api/accounts
i'm trying to get started with silverlight 2. i have a weird bug. every
I've a weird string escape problem with my PHP script. I'm trying to get

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.