Solved

I'll give the points to get this answered.

Posted on 1997-04-21
21
238 Views
Last Modified: 2010-04-04
My friend and I, (He has asked this question here but no one will answer him) are devloping an App.  We want to change an image once scanned or loaded from a file.
Example: Our Timage now contains a .BMP we want to be able to contrast, lighten, darken, change red value, and blue level.  The last two red and blue are not as critical as contrast, lighten and darken.  Will somebody please post the code for this.  We don't want to buy a book.  All we want is the code. Thanks
Rob.

As I am giving my full points, I would expect a little more in the way of an answer.  We are both new to Delphi and maybe a (grin, grin) small routine would help out?  I know "bad joke".  How about it? Anyone have a routine?
I did the code myself, but it did not work.  I translated what you had.  Delphi did it, but not the whole image, just one pixel.  Oh well, I'll have to wait or drop the idea.
I used Canvas.Pixels I could only get one pixel to change.  I think it requires more than what Delphi offers.  I have afriend in Denmark and he said it would require a lot of code.  Who knows, I would like to do it, but I guess I won't be. Okay, how do you get the RGB out of TCOLOR?  This code to lighten etc... will be valuable to a lot people.  I wrote a freeware Twain component and I get tons of requests for it. See what I mean? the intense stuff is hot.  I don't sell components.  I write software for myself. It relaxes me. (Ya right) Andrew does the same.  It's a curiosity thing.

Partial solution.
We have discovered that if you place a scrollbar on the screen and in the onchange handler go
Mainform.Color := RGB(Scrollbar1.Position,ScrollBar1.Postion,ScrollBar.Position) that the form will change.  Now the problem is how to do this with an image?  I think maybe something to do with the canvas and pixels.  But how to determine how many pixels?  Any suggestions?
Maybe I should explain.  I have only been using Delphi for about a month.  I sort get what you mean.  I am getting frustrated.  I don't believe that there is an answer to this.  Is there a way or not a way?  Would someone please tell me the code? I figured out the first part now all i need is to know:
How to do it in memory.
How to do the whole image at once.
Thanks
I figured it out anyway.  It's not done with Pixels[x,y] it's a little more than that.  
0
Comment
Question by:Robert Bowden
  • 9
  • 7
  • 3
  • +1
21 Comments
 
LVL 2

Expert Comment

by:gysbert1
ID: 1335582
Contrast is a bit more tricky, but lighten and darken can be done
by simply iterating through all the pixels in the TImage using the pixels property, and adding the same value to the Red, Green, and blue components of the pixel value. You can obviously also adjust the red and blue levels separately. I'm not sure offhand how to do contrast...
0
 
LVL 3

Expert Comment

by:mheacock
ID: 1335583
Here's some very simple pseudo-code.

For X := 0 to width - 1
    For Y := 0 to height - 1
      Read Pixel RGB
      If (you want to lighten image)
         increase each RGB component by an equal amount
      If (you want to darken image)
         decrease each RGB component by an equal amount)
      If (you want to work on red)
         increase/decrease R by some amount
      If (you want to work on blue)
         increase/decrease B by some amount
      If (you want to work on green)
         increase/decrease G by some amount

This is very easy to implement.  Look at the TColor type in
help for info on altering the RGB value.  Look at the Pixel
property of canvases....canvas.pixel[x, y] = A...

This is how you'd do it true colour mode...if you are working with palettes, then there are quicker, but more complex ways of doing this using palette animation...but I'm not about to go into that...I now refuse to work with palettes...they are a thing of the past in my opinion...4MB video cards are too damn inexpensive to be working with palettes.

Also, make sure you don't do this on the TImage itself.
Do all these calculations on a bitmap buffer (in memory), then
copy the bitmap to the TImage after completion.  It'll be
much faster  this way.
0
 
LVL 3

Accepted Solution

by:
mheacock earned 200 total points
ID: 1335584
I meant to give my previous comment as an answer...some of the indenting didn't come out properly...but still readable.
0
 

Author Comment

by:Robert Bowden
ID: 1335585
Edited text of question
0
 
LVL 3

Expert Comment

by:mheacock
ID: 1335586
I don't have the time...so you can reject...someone should be able to convert the psuedo code to Delphi code with no problems..an easy 200+ points (if you grade well).
0
 
LVL 3

Expert Comment

by:mheacock
ID: 1335587
Contrast is trickier...I might be able to get an algorithm for you.  BTW, you might want to try converting the pseudo-code yourself...you can learn a lot by actually trying to do the coding yourself...(not a bad joke).
0
 
LVL 3

Expert Comment

by:mheacock
ID: 1335588
As an 'unpaid' expert I view myself as more of a college lab instructor than a paid consultant who will do the code for you...as I see it, my job here is to show you the road not taken help you along, help you learn, get you going in the right directions, not spoon feed you or anyone.
0
 

Author Comment

by:Robert Bowden
ID: 1335589
Edited text of question
0
 
LVL 4

Expert Comment

by:StevenB
ID: 1335590
In that I answered the first question for 15 points with pretty much the same advice given above perhaps someone could have the decency to either grade, reject or respond to my answer rather than just asking it again somewhere else?
0
 
LVL 3

Expert Comment

by:mheacock
ID: 1335591
If you don't know how to get the RGB components out of TColor,
ask and you shall receive some code on how to do that.

As for the pseudo-code above, anyone with any programming experience in any language (well, perhasps not Prolog or Lisp)
can convert it.
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 3

Expert Comment

by:mheacock
ID: 1335592
Post your code and I'll see if I can help you refine what
you've got and get it working...I'm willing to help you work
on code you already have.
0
 

Author Comment

by:Robert Bowden
ID: 1335593
Edited text of question
0
 

Author Comment

by:Robert Bowden
ID: 1335594
Edited text of question
0
 

Author Comment

by:Robert Bowden
ID: 1335595
Edited text of question
0
 
LVL 4

Expert Comment

by:StevenB
ID: 1335596
Each pixel on a canvas can be referenced by X,Y coordinates using the Pixel[X,Y:LongInt] property. This property yields a Colour. This property can also be used to set a colour. So then:

Simply loop through all the pixels on the canvas (two nested loops 0-width & 0-height) and change the colours. It will not require a lot of code and should be finnished in time for someone to grade my answer to the first instance of this question asked elsewhere.
0
 

Author Comment

by:Robert Bowden
ID: 1335597
Edited text of question
0
 
LVL 3

Expert Comment

by:mheacock
ID: 1335598
Reject my answer...I no longer have time to answer questions
here...it is much too time consuming.
0
 

Author Comment

by:Robert Bowden
ID: 1335599
Edited text of question
0
 
LVL 3

Expert Comment

by:mheacock
ID: 1335600
So?  What did you figure out?  Clue us all in.
0
 
LVL 4

Expert Comment

by:StevenB
ID: 1335601
 Yes I'm facinated too, this has become almost a soap opera.
0
 
LVL 2

Expert Comment

by:gysbert1
ID: 1335602
Here for example is some code to brighten the image (Note that doing it this way is very easy but incredibly slow)

var
  x, y : integer;
  l : longint;
  t : integer;
  blue, green, red : integer;
begin
  for y:=0 to Image1.Picture.Height-1 do
            for x:=0 to Image1.Picture.Width-1 do
      begin
                        l:=Image1.Canvas.Pixels[x,y];
        blue:=(l shr 16) and $ff;
        green:=(l shr 8) and $ff;
        red:=l and $ff;
        blue:=blue+20;
        red:=red+20;
        green:=green+20;
        if red>$ff then red:=$ff;
        if blue>$ff then blue:=$ff;
        if green>$ff then green:=$ff;
        l:=(blue shl 16) + (green shl 8) + red;
        Image1.Canvas.Pixels[x,y]:=l;
      end;
end;

0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now