Questo codice copiato da CodeProject.com http://www.codeproject.com/Articles...Adjustment
PrivateSub TsImConvertNeg_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TsImConvertNeg.Click If ImmCorrente IsNothingThenExitSub undoImage = CType(ImmCorrente.Clone, Image) MenuMAnnulla.Enabled = True ' conversione negativo Dim cm As ColorMatrix = New ColorMatrix(NewSingle()() _ {NewSingle() {-1, 0, 0, 0, 0}, _ NewSingle() {0, -1, 0, 0, 0}, _ NewSingle() {0, 0, -1, 0, 0}, _ NewSingle() {0, 0, 0, 1, 0}, _ NewSingle() {0, 0, 0, 0, 1}}) Ridisegna(cm) End Sub ''' PrivateFunction Ridisegna(ByVal cm As ColorMatrix) AsBoolean
Try Dim bmp AsNew Bitmap(ImmCorrente) Dim rc AsNew Rectangle(0, 0, ImmCorrente.Width, ImmCorrente.Height) Dim mGrafic As Graphics = Graphics.FromImage(bmp) ' associare l'oggetto ColorMatrix a un oggetto ImageAttributes Dim imgattr AsNew ImageAttributes()_ imgattr.SetColorMatrix(cm) 'applicare ColorMatrix mGrafic.DrawImage(bmp, rc, 0, 0, ImmCorrente.Width, _ ImmCorrente.Height, GraphicsUnit.Pixel, imgattr) ImmCorrente = bmp Zoom(FatZoom) mGrafic.Dispose() mClos = True ' richiesta salvataggio ReturnTrue Catch ex As Exception Messaggi.Errore(mClassName, _ System.Reflection.MethodBase.GetCurrentMethod(), ex) ReturnFalse EndTry EndFunction |
restituisce immagine nera e non capisco il perché dovrebbe restituire un immagine simile a questa.
? ? le altre conversioni che utilizzano la stessa funzione funzionano regolarmente.