[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

I'll give the points to get this answered.

Posted on 1997-04-21
21
Medium Priority
?
246 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 400 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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
 
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

649 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