Приветствую Вас Гость | RSS

Меню сайта

Реклама

Категории раздела
Bitmap [50]
Canvas [0]
DirectX и DelphiX [39]
GIF [3]
ICO [24]
JPEG [14]
MetaFile [6]
OpenGL [9]
ScreenSaver и ScreenMate [13]
Векторная графика [2]
Графика [37]
Изображения [0]
Картография [6]
Компоненты и Графика [0]
Создание игр [17]
Цвета и Палитра [0]
Шрифты [0]

Наш опрос
Какие компоненты добавлять больше?
Всего ответов: 49

Статистика

Онлайн всего: 1
Гостей: 1
Пользователей: 0

Форма входа

Главная » Статьи » Графика и Игры » Графика

Как создать регион (HRNG) по маске
function BitmapToRgn(Image: TBitmap): HRGN;
var
TmpRgn: HRGN;
x, y: integer;
ConsecutivePixels: integer;
CurrentPixel: TColor;
CreatedRgns: integer;
CurrentColor: TColor;
begin
CreatedRgns := 0;
Result := CreateRectRgn(0, 0, Image.Width, Image.Height);
inc(CreatedRgns);

if (Image.Width = 0) or (Image.Height = 0) then
exit;

for y := 0 to Image.Height - 1 do
begin
CurrentColor := Image.Canvas.Pixels[0,y];
ConsecutivePixels := 1;
for x := 0 to Image.Width - 1 do
begin
CurrentPixel := Image.Canvas.Pixels[x,y];

if CurrentColor = CurrentPixel then
inc(ConsecutivePixels)
else
begin
// Входим в новую зону
if CurrentColor = clWhite then
begin
TmpRgn := CreateRectRgn(x-ConsecutivePixels, y, x, y+1);
CombineRgn(Result, Result, TmpRgn, RGN_DIFF);
inc(CreatedRgns);
DeleteObject(TmpRgn);
end;
CurrentColor := CurrentPixel;
ConsecutivePixels := 1;
end;
end;

if (CurrentColor = clWhite) and (ConsecutivePixels > 0) then
begin
TmpRgn := CreateRectRgn(x-ConsecutivePixels, y, x, y+1);
CombineRgn(Result, Result, TmpRgn, RGN_DIFF);
inc(CreatedRgns);
DeleteObject(TmpRgn);
end;
end;
end;

Категория: Графика | Добавил: Angel (13.07.2008)
Просмотров: 453 | Рейтинг: 0.0/0
  Delphi Lab   Главная   Регистрация   Вход  
Интересная Цитата

Поиск

Магазин


Copyright MyCorp © 2025 Хостинг от uCoz