Article View: free.it.visual-basic
Article #2872ritagliare una regione
From: luckydor
Date: Mon, 20 Jan 2003 20:04
Date: Mon, 20 Jan 2003 20:04
95 lines
3852 bytes
3852 bytes
Vorrei ritagliare una regione da un'immagine,
con il metodo + veloce possibile.
Leggere i pixel, confrontarli col colore di fondo,
quindi creare una regione x poi combinarla;
� perfetta... per� impiega troppo tempo.
Se riuscissi ad individuare tutti i punti del
perimetro della figura si potrebbe utilizzare
CreatePolygonRgn
e creare la regione che m'interessa in un colpo solo.
Ma c'� un altro modo....
Private Sub Command1_Click()
' ScaleMode = vbPixels
FontName = "Times New Roman"
FontSize = 50
BackColor = vbGreen
Dim Rgn As Long
BeginPath hdc
Print "Luckydor"
EndPath hdc
Rgn = PathToRegion(hdc)
SetWindowRgn Me.hWnd, Rgn, True
DeleteObject Rgn
End Sub
Praticamente:
BeginPath 'apro una Path con
disegno
EndPath ' chiudo la Path
PathToRegion 'creo la regione
Eseguendo invece (tratto MSDN alla voce Paths):
Private Sub Command2_Click()
Me.AutoRedraw = True
' Start recording Path
BeginPath hdc
'Do some draw operations
ForeColor = vbYellow
FillColor = vbRed
FillStyle = vbSolid
Line (ScaleWidth * 0.2, ScaleHeight * 0.3)-(ScaleWidth * 0.8, ScaleHeight
* 0.7)
Circle (ScaleWidth * 0.5, ScaleHeight * 0.5), ScaleHeight * 0.3
' Stop recording path
EndPath hdc
'~~~~~~~~~~~~~~~~~~~~~~
Rgn = PathToRegion(hdc)
SetWindowRgn Me.hWnd, Rgn, True
DeleteObject Rgn
'~~~~~~~~~~~~~~~~~~~~~~
'Do something to finished path
StrokeAndFillPath hdc
' Update device context
Refresh
End Sub
La regione viene creata (Rgn) ma il Form scompare del tutto.
Ho caricato in Picture1 un'immagine
e disegnato nel Form con:
Me.Picture = Picture1
Me.Picture = Picture1.Image
Me.PaintPicture Picture1.Image, 0, 0
BitBlt Me.hdc, 0, 0, Picture1.Width, Picture1.Height, Picture1.hdc, 0,
0, vbSrcCopy
Non viene nemmeno creata la regione.
Evidentemente sbaglio in qualche cosa.
Sicuro che avete la soluzione resto in standby.
------------------api in gioco------
Private Declare Function EndPath Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function BeginPath Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function PathToRegion Lib "gdi32" (ByVal hdc As Long) As
Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As
Long
Private Declare Function SetWindowRgn Lib "user32" (ByVal hWnd As Long,
ByVal hRgn As Long, ByVal bRedraw As Boolean) As Long
Private Declare Function StrokeAndFillPath Lib "gdi32" (ByVal hdc As Long)
As Long
------------------------------
Non sono stato capace nemmeno di utilizzare l'API:
Public Declare Function GetPath Lib "gdi32" Alias "GetPath" (ByVal hdc As
Long, lpPoint As POINTAPI, lpTypes As Byte, ByVal nSize As Long) As Long
lpTypes che cos � cosa devo metterci, e nSize ?
Technical Details
Message-ID:
<gDYW9.78353$AA2.3538216@news2.tin.it>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-03!sn-xit-01!sn-xit-08!supernews.com!news.tele.dk!news.tele.dk!small.news.tele.dk!news.mailgate.org!nntp.infostrada.it!news-out.tin.it!news-in.tin.it!news2.tin.it.POSTED!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ITALIAN,ASCII X-Google-Thread: f94ee,675589fe1d218b77,start X-Google-Attributes: gidf94ee,public X-Google-ArrivalTime: 2003-01-20 12:04:43 PST Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-03!sn-xit-01!sn-xit-08!supernews.com!news.tele.dk!news.tele.dk!small.news.tele.dk!news.mailgate.org!nntp.infostrada.it!news-out.tin.it!news-in.tin.it!news2.tin.it.POSTED!not-for-mail From: "luckydor" <orfwim@tin.it> Newsgroups: free.it.visual-basic Subject: ritagliare una regione Lines: 102 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4522.1200 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4522.1200 Message-ID: <gDYW9.78353$AA2.3538216@news2.tin.it> Date: Mon, 20 Jan 2003 20:04:28 GMT NNTP-Posting-Host: 213.45.108.91 X-Complaints-To: newsmaster@tin.it X-Trace: news2.tin.it 1043093068 213.45.108.91 (Mon, 20 Jan 2003 21:04:28 MET) NNTP-Posting-Date: Mon, 20 Jan 2003 21:04:28 MET Organization: TIN