@mardokvk
Я junior-программист, мой профиль С#, изучаю С++.

Как удалить Bitmap?

Как удалить Bitmap? И нужно ли вообще его удалять? Может нужно удалять hBitmap?

Пример кода:
int Comparison_two_bmp(wchar_t* templateName, HBITMAP hBmp, int x, int y)
{
	Color clr_t, clr_main;
	int CountPx = 0;

	GdiplusStartupInput gdiplusStartupInput;
	ULONG_PTR gdiplusToken;
	GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
	Bitmap bmpTemplate(LoadHbitmapFromFile(templateName), NULL);
	Bitmap bmp(hBmp, NULL);
	for (int y_t = 0; y_t < bmpTemplate.GetHeight(); y_t++)
		for (int x_t = 0; x_t < bmpTemplate.GetWidth(); x_t++)
		{
			bmp.GetPixel(x + x_t, y + y_t, &clr_main);
			bmpTemplate.GetPixel(x_t, y_t, &clr_t);
			if (clr_t.GetValue() == clr_main.GetValue())
				CountPx++;
			else
				return CountPx;
		}


	
	return CountPx;
}
  • Вопрос задан
  • 82 просмотра
Решения вопроса 1
wataru
@wataru Куратор тега C++
Разработчик на С++, экс-олимпиадник.
Сам Bitmap - это класс с деструктором. Он сам нормально удалится, если только вы его не через new выделяли и забыли сделать delete потом.

hBitmap - да, удалять надо.
В документации этот момент даже расписан:
You are responsible for deleting the GDI bitmap and the GDI palette. However, you should not delete the GDI bitmap or the GDI palette until after the GDI+ Bitmap object is deleted or goes out of scope.


Это делается через DeleteObject.
Ответ написан
Комментировать
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы