ImageEn for Delphi and C++ Builder ImageEn for Delphi and C++ Builder

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
Forum membership is Free!  Click Join to sign-up
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 Displaying mask over image
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

spetric

Croatia
308 Posts

Posted - Aug 19 2014 :  02:06:11  Show Profile  Reply
Hi,

I'm struggling with one task.

Initial conditions:

1. Image is loaded and display in ImageEnView (24-bit).
2. An offsreen TIEBitmap grayscale mask is created (8-bit), with the same with and height as original 24-bit image.
3. Some brush stroke is drawn on grayscale mask (in OnMouseMove event).

The problem:

I want to display (in ImageEnView) original image with XOR-ed mask.
How to achieve this, without altering original image content?

I've tried few solutions:

1. In OnMouseMove event, I'm simply XOR-ing mask with original image. This solution is quite cumbersome as original image pixels are altered and when such operation is not needed any more, I need to restore original image (XOR-ing with mask again). Also, keeping track if image is XOR-ed with mask or not is additional problem.

2. Adding some kind of special layer also works, but as layer is 24-bit image, I have additional tasks to perform: permanently copying pixels from mask to this layer and also, I need to keep track of this special layer in order to distinguish it from other layers.

3. I've tried with OnDrawBackBuffer event (which seems most promising solution), but there is another problem: how to determine a position of original image inside BackBuffer?

Any other solution? Maybe another event?

TIA,
Siniša



spetric

Croatia
308 Posts

Posted - Aug 21 2014 :  14:55:24  Show Profile  Reply
Done it. I'm not completely satisfied, but it works ok.

First, I've tried with nontransparent 24-bit ObjBitmap object (same size as original image). Filled it with clBlack and set BlendOperation to ielXOR. While drawing across image, mask pixels inside bound rectangle are copied to all 3 channels of ObjBitmap in order to get white color which will be xor-ed with original image.

However, while performing this operation, original image is hidden and ObjBitmap is shown in normal mode. XOR operation/blending is performed after mouse button is released. This is the difference between layer and ObjBitmap approach, as layer blending is performed almost instantly (in onmousemove event).

Anyway, I've changed approach a bit and created ObjBitmap with transparent channel, filled it with white and alphachannel with black. Now, while drawing is performed, alpha channel pixels are replaced by mask pixels (both bitmaps are grayscale).

So, while drawing, I have white strokes over image and when mouse button is released, XOR blending is performed.

Well, not what I initially wanted, but quite satisfying.

Any clue why XOR-ing is not performed in the same manner as with layers?

Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: