Image en forme de cercle

mathieu57100 Messages postés 103 Date d'inscription jeudi 24 juin 2004 Statut Membre Dernière intervention 9 février 2006 - 6 oct. 2005 à 14:32
SnOOpss Messages postés 571 Date d'inscription samedi 3 avril 2004 Statut Membre Dernière intervention 5 décembre 2013 - 6 oct. 2005 à 18:28
bonjour,
j'aimerai savoir comment faire appraitre une image seulement dans un cercle, la partie de l'image hors du cercle n'apparaitrait pas.
j'ai essayé avec un composant Timage et un Tshape en forme de cercle, mais ca ne donne pas ce que je veux.
merci d'avance pour vos réponses.

4 réponses

kortin Messages postés 65 Date d'inscription dimanche 27 juillet 2003 Statut Membre Dernière intervention 21 avril 2006
6 oct. 2005 à 16:47
Pour utiliser une shape, il faut une couleur de mask qui délimitera la région.
0
mathieu57100 Messages postés 103 Date d'inscription jeudi 24 juin 2004 Statut Membre Dernière intervention 9 février 2006
6 oct. 2005 à 16:57
merci pour ta réponse, mais je ne peux pas connaitre à l'avance la couleur de la région, car c'est à l'utiisateur d'insérer une image, par un bouton du genre 'Parcourir...'
0
kortin Messages postés 65 Date d'inscription dimanche 27 juillet 2003 Statut Membre Dernière intervention 21 avril 2006
6 oct. 2005 à 17:13
Bon, on est d'accord sur le fait que ton utilisateur va charger une image rectangle.
Donc, il te suffit de travailler l'image pour ne garder ke le cercle du millieu. Tu laisse le reste disons vert (0,255,0) et tu appliques ton mask. Pour travailler l'image, tu peux utiliser le device context.
0
SnOOpss Messages postés 571 Date d'inscription samedi 3 avril 2004 Statut Membre Dernière intervention 5 décembre 2013
6 oct. 2005 à 18:28
Tu as un example sur Petzold

cf extrait
The MATTHEW.BMP file referred to in the resource script is a digitized black-and-white photograph of a nephew of mine. It's 200 pixels wide, 320 pixels high, and has 8 bits per pixel. However, BITMASK is written so that this file can be just about anything.

Notice that BITMASK colors its window background with a light gray brush. This is to assure ourselves that we're properly masking the bitmap and not just coloring part of it white.

Let's look at WM_CREATE processing. BITMASK uses the LoadBitmap function to obtain a handle to the original image in the variable hBitmapImag. The GetObject function obtains the bitmap width and height. The bitmap handle is then selected in a memory device context whose handle is hdcMemImag.

Next the program creates a monochrome bitmap the same size as the original image. The handle is stored in hBitmapMask and selected into a memory device context whose handle is hdcMemMask. The mask bitmap is colored with a black background and a white ellipse by using GDI functions on the memory device context:


SelectObject (hdcMemMask, GetStockObject (BLACK_BRUSH)) ;
Rectangle (hdcMemMask, 0, 0, cxBitmap, cyBitmap) ;
SelectObject (hdcMemMask, GetStockObject (WHITE_BRUSH)) ;
Ellipse (hdcMemMask, 0, 0, cxBitmap, cyBitmap) ;

Because this is a monochrome bitmap, the black area is really 0 bits and the white area is really 1 bits.

Then a BitBlt call alters the original image by using this mask:


BitBlt (hdcMemImag, 0, 0, cxBitmap, cyBitmap,
hdcMemMask, 0, 0, SRCAND) ;

The SRCAND raster operation performs a bitwise AND operation between the bits of the source (the mask bitmap) and the bits of the destination (the original image). Wherever the mask bitmap is white, the destination is preserved. Wherever the mask bitmap is black, the destination becomes black as well. An elliptical area in the original image is now surrounded by black.

Now let's look at WM_PAINT processing. Both the altered image bitmap and the mask bitmap are selected into memory device contexts. Two BitBlt calls perform the magic. The first does a BitBlt of the mask bitmap on the window:


BitBlt (hdc, x, y, cxBitmap, cyBitmap, hdcMemMask, 0, 0, 0x220326) ;

This uses a raster operation for which there is no name. The logical operation is D & ~S. Recall that the source?the mask bitmap?is a white ellipse (1 bits) surrounded by black (0 bits). The raster operation inverts the source so that it's a black ellipse surrounded by white. The raster operation then performs a bitwise AND of this inverted source with the destination?the surface of the window. When the destination is ANDed with 1 bits, it remains unchanged. When ANDed with 0 bits, the destination becomes black. Thus, this BitBlt operation draws a black ellipse in the window.

The second BitBlt call draws the image bitmap on the window:


BitBlt (hdc, x, y, cxBitmap, cyBitmap, hdcMemImag, 0, 0, SRCPAINT) ;

The raster operation performs a bitwise OR operation between the source and the destination. The outside of the source bitmap is black, so it leaves the destination unchanged. Within the ellipse, the destination is black, so the image is copied unchanged. The result is shown in Figure 14-18.

A few notes:

You may need a mask that is quite complex?for example, one that blots out the whole background of the original image. You'll probably need to create this manually in a paint program and save it to a file.
0
Rejoignez-nous