Форум программистов, компьютерный форум, киберфорум
C++/CLI Windows Forms
Войти
Регистрация
Восстановить пароль
Блоги Сообщество Поиск Заказать работу  
 
Рейтинг 4.86/7: Рейтинг темы: голосов - 7, средняя оценка - 4.86
1 / 1 / 0
Регистрация: 24.04.2020
Сообщений: 12

Преобразование Bitmap в Image

17.07.2020, 19:23. Показов 1614. Ответов 1
Метки нет (Все метки)

Студворк — интернет-сервис помощи студентам
компилятор ругается на отсутствие экземпляров конструктора и на невозможность преобразования аргумента
Проблемная часть:
C++
1
2
3
4
5
6
7
8
9
10
        if (pictureBox3->Image == nullptr) {
            srand((unsigned)time(nullptr));
            int integer = rand() % 35;
            string n;
            ostringstream stream;
            stream << integer;
            n = stream.str();
            string path = "card\\";
            pictureBox3->Image = gcnew Bitmap(path + n + ".jpg");
        }
Именно в этой строке между "Bitmap" и "("
C++
1
pictureBox3->Image = gcnew Bitmap(path + n + ".jpg");
Весь код:
C++
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
#pragma once
#include <ctime>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <windows.h>
#include <string>
#include <sstream>
#include<iostream>
#include<cstdlib>
namespace ochko2 {
 
    using namespace System;
    using namespace System::ComponentModel;
    using namespace System::Collections;
    using namespace System::Windows::Forms;
    using namespace System::Data;
    using namespace System::Drawing;
    using namespace std;
    /// <summary>
    /// Сводка для MyForm
    /// </summary>
    public ref class MyForm : public System::Windows::Forms::Form
    {
    public:
        MyForm(void)
        {
            InitializeComponent();
            //
            //TODO: добавьте код конструктора
            //
            
            pictureBox1->Image = Image::FromFile("card\\6.png");
            pictureBox2->Image = Image::FromFile("card\\8.png");
        }
 
    protected:
        /// <summary>
        /// Освободить все используемые ресурсы.
        /// </summary>
        ~MyForm()
        {
            if (components)
            {
                delete components;
            }
        }
    private: System::Windows::Forms::Label^ label1;
    private: System::Windows::Forms::Button^ button1;
    private: System::Windows::Forms::Button^ button2;
    private: System::Windows::Forms::PictureBox^ pictureBox1;
    private: System::Windows::Forms::PictureBox^ pictureBox2;
    private: System::Windows::Forms::PictureBox^ pictureBox3;
    private: System::Windows::Forms::PictureBox^ pictureBox4;
    private: System::Windows::Forms::PictureBox^ pictureBox5;
    private: System::Windows::Forms::PictureBox^ pictureBox6;
    private: System::Windows::Forms::PictureBox^ pictureBox7;
    private: System::Windows::Forms::PictureBox^ pictureBox8;
    private: System::Windows::Forms::Label^ label2;
    private: System::Windows::Forms::Label^ label3;
    private: System::Windows::Forms::Label^ label4;
 
 
 
 
 
 
    protected:
 
    private:
        /// <summary>
        /// Обязательная переменная конструктора.
        /// </summary>
        double null = 0;
        System::ComponentModel::Container ^components;
 
#pragma region Windows Form Designer generated code
        /// <summary>
        /// Требуемый метод для поддержки конструктора — не изменяйте 
        /// содержимое этого метода с помощью редактора кода.
        /// </summary>
        void InitializeComponent(void)
        {
            this->label1 = (gcnew System::Windows::Forms::Label());
            this->button1 = (gcnew System::Windows::Forms::Button());
            this->button2 = (gcnew System::Windows::Forms::Button());
            this->pictureBox1 = (gcnew System::Windows::Forms::PictureBox());
            this->pictureBox2 = (gcnew System::Windows::Forms::PictureBox());
            this->pictureBox3 = (gcnew System::Windows::Forms::PictureBox());
            this->pictureBox4 = (gcnew System::Windows::Forms::PictureBox());
            this->pictureBox5 = (gcnew System::Windows::Forms::PictureBox());
            this->pictureBox6 = (gcnew System::Windows::Forms::PictureBox());
            this->pictureBox7 = (gcnew System::Windows::Forms::PictureBox());
            this->pictureBox8 = (gcnew System::Windows::Forms::PictureBox());
            this->label2 = (gcnew System::Windows::Forms::Label());
            this->label3 = (gcnew System::Windows::Forms::Label());
            this->label4 = (gcnew System::Windows::Forms::Label());
            (cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->pictureBox1))->BeginInit();
            (cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->pictureBox2))->BeginInit();
            (cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->pictureBox3))->BeginInit();
            (cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->pictureBox4))->BeginInit();
            (cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->pictureBox5))->BeginInit();
            (cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->pictureBox6))->BeginInit();
            (cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->pictureBox7))->BeginInit();
            (cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->pictureBox8))->BeginInit();
            this->SuspendLayout();
            // 
            // label1
            // 
            this->label1->AutoSize = true;
            this->label1->Font = (gcnew System::Drawing::Font(L"Mistral", 72, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
                static_cast<System::Byte>(204)));
            this->label1->Location = System::Drawing::Point(621, 9);
            this->label1->Name = L"label1";
            this->label1->Size = System::Drawing::Size(240, 114);
            this->label1->TabIndex = 0;
            this->label1->Text = L"ОЧКО";
            this->label1->Click += gcnew System::EventHandler(this, &MyForm::label1_Click);
            // 
            // button1
            // 
            this->button1->Location = System::Drawing::Point(1328, 534);
            this->button1->Name = L"button1";
            this->button1->Size = System::Drawing::Size(75, 61);
            this->button1->TabIndex = 1;
            this->button1->Text = L"Ещё";
            this->button1->UseVisualStyleBackColor = true;
            this->button1->Click += gcnew System::EventHandler(this, &MyForm::button1_Click);
            // 
            // button2
            // 
            this->button2->Location = System::Drawing::Point(1409, 534);
            this->button2->Name = L"button2";
            this->button2->Size = System::Drawing::Size(75, 61);
            this->button2->TabIndex = 2;
            this->button2->Text = L"Стоп";
            this->button2->UseVisualStyleBackColor = true;
            this->button2->Click += gcnew System::EventHandler(this, &MyForm::button2_Click);
            // 
            // pictureBox1
            // 
            this->pictureBox1->Location = System::Drawing::Point(1101, 345);
            this->pictureBox1->Name = L"pictureBox1";
            this->pictureBox1->Size = System::Drawing::Size(200, 250);
            this->pictureBox1->TabIndex = 3;
            this->pictureBox1->TabStop = false;
            this->pictureBox1->Click += gcnew System::EventHandler(this, &MyForm::pictureBox1_Click);
            // 
            // pictureBox2
            // 
            this->pictureBox2->Location = System::Drawing::Point(1052, 345);
            this->pictureBox2->Name = L"pictureBox2";
            this->pictureBox2->Size = System::Drawing::Size(200, 250);
            this->pictureBox2->TabIndex = 4;
            this->pictureBox2->TabStop = false;
            this->pictureBox2->Click += gcnew System::EventHandler(this, &MyForm::pictureBox2_Click);
            // 
            // pictureBox3
            // 
            this->pictureBox3->Location = System::Drawing::Point(1002, 345);
            this->pictureBox3->Name = L"pictureBox3";
            this->pictureBox3->Size = System::Drawing::Size(200, 250);
            this->pictureBox3->TabIndex = 5;
            this->pictureBox3->TabStop = false;
            // 
            // pictureBox4
            // 
            this->pictureBox4->Location = System::Drawing::Point(944, 345);
            this->pictureBox4->Name = L"pictureBox4";
            this->pictureBox4->Size = System::Drawing::Size(200, 250);
            this->pictureBox4->TabIndex = 6;
            this->pictureBox4->TabStop = false;
            // 
            // pictureBox5
            // 
            this->pictureBox5->Location = System::Drawing::Point(846, 345);
            this->pictureBox5->Name = L"pictureBox5";
            this->pictureBox5->Size = System::Drawing::Size(200, 250);
            this->pictureBox5->TabIndex = 7;
            this->pictureBox5->TabStop = false;
            // 
            // pictureBox6
            // 
            this->pictureBox6->Location = System::Drawing::Point(895, 345);
            this->pictureBox6->Name = L"pictureBox6";
            this->pictureBox6->Size = System::Drawing::Size(200, 250);
            this->pictureBox6->TabIndex = 8;
            this->pictureBox6->TabStop = false;
            // 
            // pictureBox7
            // 
            this->pictureBox7->Location = System::Drawing::Point(796, 345);
            this->pictureBox7->Name = L"pictureBox7";
            this->pictureBox7->Size = System::Drawing::Size(200, 250);
            this->pictureBox7->TabIndex = 9;
            this->pictureBox7->TabStop = false;
            // 
            // pictureBox8
            // 
            this->pictureBox8->Location = System::Drawing::Point(747, 345);
            this->pictureBox8->Name = L"pictureBox8";
            this->pictureBox8->Size = System::Drawing::Size(200, 250);
            this->pictureBox8->TabIndex = 10;
            this->pictureBox8->TabStop = false;
            // 
            // label2
            // 
            this->label2->AutoSize = true;
            this->label2->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 27.75F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
                static_cast<System::Byte>(204)));
            this->label2->Location = System::Drawing::Point(1212, 9);
            this->label2->Name = L"label2";
            this->label2->Size = System::Drawing::Size(191, 42);
            this->label2->TabIndex = 11;
            this->label2->Text = L"Ваш счёт:";
            this->label2->Click += gcnew System::EventHandler(this, &MyForm::label2_Click);
            // 
            // label3
            // 
            this->label3->AutoSize = true;
            this->label3->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 27.75F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
                static_cast<System::Byte>(204)));
            this->label3->Location = System::Drawing::Point(1402, 9);
            this->label3->Name = L"label3";
            this->label3->Size = System::Drawing::Size(0, 42);
            this->label3->TabIndex = 12;
            // 
            // label4
            // 
            this->label4->AutoSize = true;
            this->label4->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 27.75F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
                static_cast<System::Byte>(204)));
            this->label4->Location = System::Drawing::Point(1409, 9);
            this->label4->Name = L"label4";
            this->label4->Size = System::Drawing::Size(39, 42);
            this->label4->TabIndex = 13;
            this->label4->Text = L"0";
            // 
            // MyForm
            // 
            this->AccessibleRole = System::Windows::Forms::AccessibleRole::None;
            this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
            this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
            this->ClientSize = System::Drawing::Size(1496, 607);
            this->Controls->Add(this->label4);
            this->Controls->Add(this->label3);
            this->Controls->Add(this->label2);
            this->Controls->Add(this->pictureBox1);
            this->Controls->Add(this->pictureBox2);
            this->Controls->Add(this->pictureBox3);
            this->Controls->Add(this->pictureBox4);
            this->Controls->Add(this->pictureBox6);
            this->Controls->Add(this->button2);
            this->Controls->Add(this->button1);
            this->Controls->Add(this->label1);
            this->Controls->Add(this->pictureBox5);
            this->Controls->Add(this->pictureBox7);
            this->Controls->Add(this->pictureBox8);
            this->Name = L"MyForm";
            this->Text = L"MyForm";
            this->Load += gcnew System::EventHandler(this, &MyForm::MyForm_Load);
            (cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->pictureBox1))->EndInit();
            (cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->pictureBox2))->EndInit();
            (cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->pictureBox3))->EndInit();
            (cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->pictureBox4))->EndInit();
            (cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->pictureBox5))->EndInit();
            (cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->pictureBox6))->EndInit();
            (cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->pictureBox7))->EndInit();
            (cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->pictureBox8))->EndInit();
            this->ResumeLayout(false);
            this->PerformLayout();
 
        }
#pragma endregion
    
    private: System::Void label1_Click(System::Object^ sender, System::EventArgs^ e) {
    }
 
    private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
        if (pictureBox3->Image == nullptr) {
            srand((unsigned)time(nullptr));
            int integer = rand() % 35;
            string n;
            ostringstream stream;
            stream << integer;
            n = stream.str();
            string path = "card\\";
            pictureBox3->Image = gcnew Bitmap(path + n + ".jpg");
        }
        ///pictureBox3->Image = Image::FromFile("card\\18.png");
        ///pictureBox4->Image = Image::FromFile("card\\19.png");
    }
    private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e) {
    }
    private: System::Void pictureBox2_Click(System::Object^ sender, System::EventArgs^ e) {
    }
    private: System::Void pictureBox1_Click(System::Object^ sender, System::EventArgs^ e) {
    }
    private: System::Void MyForm_Load(System::Object^ sender, System::EventArgs^ e) {
    }
    private: System::Void label2_Click(System::Object^ sender, System::EventArgs^ e) {
    }
};
}
0
cpp_developer
Эксперт
20123 / 5690 / 1417
Регистрация: 09.04.2010
Сообщений: 22,546
Блог
17.07.2020, 19:23
Ответы с готовыми решениями:

Как загрузить Bitmap в Image^ из ресурсов?
Как загрузить Bitmap в Image^ из ресурсов?

Как преобразовать Bitmap (System::Drawing::Image) в IplImage*frame (openCV)?
Как преобразовать Bitmap (System::Drawing::Image) в IplImage*frame (openCV)

Преобразование HTML документа элемента управления WebBrowser в Image
Здравствуйте! Собственно вопрос то и озвучен в теме. Возможно ли преобразовать программно HTML документ который отображает контрол...

1
nd2
3438 / 2817 / 1249
Регистрация: 29.01.2016
Сообщений: 9,427
18.07.2020, 02:22
Цитата Сообщение от Hamlet_88 Посмотреть сообщение
C++
1
2
3
4
5
6
7
8
9
10
if (pictureBox3->Image == nullptr) {
            srand((unsigned)time(nullptr));
            int integer = rand() % 35;
            string n;
            ostringstream stream;
            stream << integer;
            n = stream.str();
            string path = "card\\";
            pictureBox3->Image = gcnew Bitmap(path + n + ".jpg");
        }
C++
1
2
3
4
5
6
7
8
9
10
11
if (pictureBox1->Image == nullptr) 
        {
            srand((unsigned)time(nullptr));
            int integer = rand() % 35;
            /*std::string n;
            std::ostringstream stream;
            stream << integer;
            n = stream.str();*/
            String^ path = "card\\";
            pictureBox1->Image = gcnew Bitmap(path + Convert::ToString(n) + ".jpg");
        }
0
Надоела реклама? Зарегистрируйтесь и она исчезнет полностью.
raxper
Эксперт
30234 / 6612 / 1498
Регистрация: 28.12.2010
Сообщений: 21,154
Блог
18.07.2020, 02:22
Помогаю со студенческими работами здесь

Image или Bitmap как в них рисовать?
Как нарисовать например в Image несколько Polygon? например если рисовать сразу в Graphics то g-&gt;FillPolygon(brush, pt); ...

Преобразование bitmap в image
Гугл полон обратными преобразованиями, а вот с этим что то туго.

Как обрезать Image (bitmap) в другой Image (bitmap)
Не получается никак пробовал с помощью Canvas-&gt;CopyRect. Вот метод где первый параметр изображение которое загрузили а второй обрезанное...

Получение фото с веб камеры, занесение его в Bitmap и преобразование Bitmap в массив
В общем необходимо подключиться к веб камере сделать снимок и отправить его в сеть. Задачу я разделил на несколько этапов. 1. Сам...

Builder c++. Image->Canvas. bitmap Подогнать рисунок в рамки Image
Добрый день! Долго искал работу canvasa на image. Нашел следующую реализацию, но при добавлении на image изображение выходит за рамки....


Искать еще темы с ответами

Или воспользуйтесь поиском по форуму:
2
Ответ Создать тему
Новые блоги и статьи
Подключение Box2D v3 к SDL3 для Android: физика и отрисовка коллайдеров
8Observer8 29.01.2026
Содержание блога Box2D - это библиотека для 2D физики для анимаций и игр. С её помощью можно определять были ли коллизии между конкретными объектами. Версия v3 была полностью переписана на Си, в. . .
Инструменты COM: Сохранение данный из VARIANT в файл и загрузка из файла в VARIANT
bedvit 28.01.2026
Сохранение базовых типов COM и массивов (одномерных или двухмерных) любой вложенности (деревья) в файл, с возможностью выбора алгоритмов сжатия и шифрования. Часть библиотеки BedvitCOM Использованы. . .
Загрузка PNG с альфа-каналом на SDL3 для Android: с помощью SDL_LoadPNG (без SDL3_image)
8Observer8 28.01.2026
Содержание блога SDL3 имеет собственные средства для загрузки и отображения PNG-файлов с альфа-каналом и базовой работы с ними. В этой инструкции используется функция SDL_LoadPNG(), которая. . .
Загрузка PNG с альфа-каналом на SDL3 для Android: с помощью SDL3_image
8Observer8 27.01.2026
Содержание блога SDL3_image - это библиотека для загрузки и работы с изображениями. Эта пошаговая инструкция покажет, как загрузить и вывести на экран смартфона картинку с альфа-каналом, то есть с. . .
Влияние грибов на сукцессию
anaschu 26.01.2026
Бифуркационные изменения массы гриба происходят тогда, когда мы уменьшаем массу компоста в 10 раз, а скорость прироста биомассы уменьшаем в три раза. Скорость прироста биомассы может уменьшаться за. . .
Воспроизведение звукового файла с помощью SDL3_mixer при касании экрана Android
8Observer8 26.01.2026
Содержание блога SDL3_mixer - это библиотека я для воспроизведения аудио. В отличие от инструкции по добавлению текста код по проигрыванию звука уже содержится в шаблоне примера. Нужно только. . .
Установка Android SDK, NDK, JDK, CMake и т.д.
8Observer8 25.01.2026
Содержание блога Перейдите по ссылке: https:/ / developer. android. com/ studio и в самом низу страницы кликните по архиву "commandlinetools-win-xxxxxx_latest. zip" Извлеките архив и вы увидите. . .
Вывод текста со шрифтом TTF на Android с помощью библиотеки SDL3_ttf
8Observer8 25.01.2026
Содержание блога Если у вас не установлены Android SDK, NDK, JDK, и т. д. то сделайте это по следующей инструкции: Установка Android SDK, NDK, JDK, CMake и т. д. Сборка примера Скачайте. . .
КиберФорум - форум программистов, компьютерный форум, программирование
Powered by vBulletin
Copyright ©2000 - 2026, CyberForum.ru