Hi,
Maybe there is a shorter and more elegant way,
but here is how I do it (C++, but it's easy to convert):
TRect selRect;
selRect.left = paintView->SelectedRect.x;
selRect.bottom = paintView->SelectedRect.y;
selRect.right = selRect.left + paintView->SelectedRect.width;
selRect.top = selRect.bottom - paintView->SelectedRect.height;
// pointer to original image in paintView.
TIEBitmap *image = paintView->IEBitmap;
TIEBitmap *tempImg = new TIEBitmap(image, selRect);
TIEBitmap *tempAlpha = new TIEBitmap();
tempAlpha->CopyFromTIEMask(paintView->SelectionMask);
// if original bitmap has alpha channel, we will merge selection
// and original image alpha channels
if (image->HasAlphaChannel)
image->MergeAlphaRectTo(tempImg, paintView->SelectedRect.x, paintView->SelectedRect.y, 0, 0, tempImg->Width, tempImg->Height);
else
{
tempImg->AlphaChannel->Fill(255);
tempAlpha->CopyRectTo(tempImg->AlphaChannel, paintView->SelectedRect.x, paintView->SelectedRect.y, 0, 0, tempImg->Width, tempImg->Height);
}
// assign tempImage to a new layer
paintView->LayersAdd();
paintView->IEBitmap->Assign(tempImage); // copy with alpha channel
delete tempImage;
delete tempAlpha;
paintView is of type TImageEnView or TImageEnVect.
With best regards,
Siniša