Welcome Guest! You need to login or register to make posts.

Notification

Icon
Error

Options
Go to last post Go to first unread
keesjalink  
#1 Posted : Monday, March 22, 2004 6:12:00 AM(UTC)
keesjalink

Rank: Member

Groups: Member
Joined: 3/22/2004(UTC)
Posts: 18

Dear All,
I (newby) try to do make a routine in VB6 which allows the user to adjust intensity and contrast of a bitmap (8bppgray) by typing in B and C values in a textbox. If I do:

Code:
BitmapViewer1.Bitmap.ColorAdjustment.BrightnessContrast B, C


then each time the textbox changes, the contrast is adjusted in a cumulative way (the user first tries B=20, but thinks it is not enough, so he increases to B=25, than the effect is much more than 25).
I tried to remedy this by reverting to a copy of the original each time the textbox value changes:
first save a copy:

Code:
dim BitmapBu as bitmap '(global, Bu=backup)
Set Bitmap1Bu = BitmapViewer1.Bitmap.Clone


then in the routine that adjusts the contrast, first revert to saved original, and then apply the new B,C values on that original.

Code:
  Set BitmapViewer1.Bitmap = Bitmap1Bu 
  BitmapViewer1.Bitmap.ColorAdjustment.BrightnessContrast B,C 


However, it still works cumulative....?????? Why?
How do I solve this?

Edited by user Monday, December 24, 2007 6:06:18 PM(UTC)  | Reason: Not specified

Andrew  
#2 Posted : Monday, March 22, 2004 12:58:00 PM(UTC)
Andrew

Rank: Advanced Member

Groups: Member, Administration
Joined: 8/2/2003(UTC)
Posts: 876

Thanks: 2 times
Was thanked: 27 time(s) in 27 post(s)
Dear Kees,

When you write

Code:
Set object1 = object2


you just put a reference of object2 to object1 (not a copy). This way both these variables points to the same object.

If you need to make it copying back to the BitmapViewer, you should use Clone method again:

Set objBitmapViewer1.Bitmap = Bitmap1Bu.Clone

Edited by user Monday, December 24, 2007 6:06:30 PM(UTC)  | Reason: Not specified

Andrew  
#3 Posted : Monday, March 22, 2004 1:08:00 PM(UTC)
Andrew

Rank: Advanced Member

Groups: Member, Administration
Joined: 8/2/2003(UTC)
Posts: 876

Thanks: 2 times
Was thanked: 27 time(s) in 27 post(s)
There is an alternative way:

Code:
Dim objBitmapBu As Bitmap
Set objBitmapBu = BitmapViewer1.Bitmap.Clone
objBitmapBu.ApplyInPlace = False


Then in code you write just:

Code:
Set objBitmapViewer1.Bitmap = objBitmapBu.ColorAdjustment.BrightnessContrast (B, C)


The idea of this code is the following: when you disable ApplyInPlace property, the behaviour of the effects is changed. Instead of applying it in-place, Bitmap returns modified copy. In other word, Graphics Mill automatically clones bitmap and applies effect on copy.

The only think you should remember when setting ApplyInPlace to False is that all methods which should change the bitmap will return changed copy instead of changing the bitmap itself. So if you need to do something like this, do not forget to change this property back to True.

Edited by user Monday, December 24, 2007 6:06:48 PM(UTC)  | Reason: Not specified

keesjalink  
#4 Posted : Monday, March 22, 2004 3:07:00 PM(UTC)
keesjalink

Rank: Member

Groups: Member
Joined: 3/22/2004(UTC)
Posts: 18

Thanks. problem solved (and fast!)

(by the way, why do you guys always write "objBitmapViewer1.Bitmap" instead of just "BitmapViewer1.Bitmap"? Is that a convention?)


Kees
Andrew  
#5 Posted : Monday, March 22, 2004 3:26:00 PM(UTC)
Andrew

Rank: Advanced Member

Groups: Member, Administration
Joined: 8/2/2003(UTC)
Posts: 876

Thanks: 2 times
Was thanked: 27 time(s) in 27 post(s)
There is a convension to add type prefix to the variable name to VB (and especially VBScript) code. It makes code more clear and understandable.

However in case of BitmapViewer, name BitmapViewer1 is generated by VB when you put control on form. So appending obj prefix in this case is just a habit...
keesjalink  
#6 Posted : Wednesday, March 24, 2004 7:41:00 PM(UTC)
keesjalink

Rank: Member

Groups: Member
Joined: 3/22/2004(UTC)
Posts: 18

Actually, if I use Andrews solution mentioned above, a subtle thing goes very wrong (probably because I still don't understand exactly what happens).
after cloning my 8bppgray image

Code:
Set Bitmap1Bu = BitmapViewer1.Bitmap.Clone


I wrote:

Code:
private sub cmdBrightContrast_Changed
  Bitmap1Bu.ApplyInPlace = False
  Set BitmapViewer1.Bitmap = Bitmap1Bu.ColorAdjustment.BrightnessContrast(B,C)
  Bitmap1Bu.ApplyInPlace = True
end sub


then this works nicely FOR THIS BITMAP. But after I open another image into the same bitmapviewer:


Code:
Private Sub cmdLoadIntens_Click()
BitmapViewer1.Bitmap.LoadFromFile ("whatever.bmp")
BitmapViewer1.Bitmap.Data.ConvertTo8bppGrayscale
Set Bitmap1Bu = BitmapViewer1.Bitmap.Clone '---again setting the clone
End Sub


this new image is displayed correctly, and it can also be altered for Brightness/contrast, but as soon as I ask (somewhere else in my code) whether it is 8bbpgray it appears to be 24bit. Is this because there is still a reference to the first opened image?
(ask for full code if you need it).

Thanks, Kees

Edited by user Monday, December 24, 2007 6:07:10 PM(UTC)  | Reason: Not specified

Andrew  
#7 Posted : Wednesday, March 24, 2004 8:26:00 PM(UTC)
Andrew

Rank: Advanced Member

Groups: Member, Administration
Joined: 8/2/2003(UTC)
Posts: 876

Thanks: 2 times
Was thanked: 27 time(s) in 27 post(s)
It is possible you disable ApplyInPlace for BitmapViewer1.Bitmap somewhere, so line BitmapViewer1.Bitmap.Data.ConvertTo8bppGrayscale does not convert the bitmap itself.

If it won't help, please submit case with full code.

Edited by user Friday, May 23, 2008 4:15:13 PM(UTC)  | Reason: Not specified

Users browsing this topic
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.