15,919,613 members
Sign in
Sign in
Email
Password
Forgot your password?
Sign in with
home
articles
Browse Topics
>
Latest Articles
Top Articles
Posting/Update Guidelines
Article Help Forum
Submit an article or tip
Import GitHub Project
Import your Blog
quick answers
Q&A
Ask a Question
View Unanswered Questions
View All Questions
View C# questions
View C++ questions
View Javascript questions
View Visual Basic questions
View Python questions
discussions
forums
CodeProject.AI Server
All Message Boards...
Application Lifecycle
>
Running a Business
Sales / Marketing
Collaboration / Beta Testing
Work Issues
Design and Architecture
Artificial Intelligence
ASP.NET
JavaScript
Internet of Things
C / C++ / MFC
>
ATL / WTL / STL
Managed C++/CLI
C#
Free Tools
Objective-C and Swift
Database
Hardware & Devices
>
System Admin
Hosting and Servers
Java
Linux Programming
Python
.NET (Core and Framework)
Android
iOS
Mobile
WPF
Visual Basic
Web Development
Site Bugs / Suggestions
Spam and Abuse Watch
features
features
Competitions
News
The Insider Newsletter
The Daily Build Newsletter
Newsletter archive
Surveys
CodeProject Stuff
community
lounge
Who's Who
Most Valuable Professionals
The Lounge
The CodeProject Blog
Where I Am: Member Photos
The Insider News
The Weird & The Wonderful
help
?
What is 'CodeProject'?
General FAQ
Ask a Question
Bugs and Suggestions
Article Help Forum
About Us
Search within:
Articles
Quick Answers
Messages
Comments by defunktlemon (Top 36 by date)
defunktlemon
6-Dec-14 13:37pm
View
Fortunately, it's the harder way of the two which I am seeking to complete :D
So, your first assumption was right Bill. Form2 only holds Controls that modify the process of analysis being carried out on Form1.
Flow-of-Control:
1. Form1 (Main Form) loads/shows: Form2 not visible.
2. Button on Form1 pressed to start process which is carried out on Form1 : Form2 shown. "Original" image, with no results, displayed on Form1. The results are sent to Form2 to be displayed there, strings and integers.
3. Analysis has finished running (probably in 500 milliseconds or so): various Controls on Form2 will setup changes which will regulate/change/limit the analysis going to be done on the same image displayed in Form1 again ,not on Form2 but on Form1.
4. at some intervals and when analysis is complete, the image on Form1 is updated.
So, Form2 is basically a control box which can change the parameters being sent to Form1 analysis and then all the results are returned to Form2 to be displayed there.
The kind of controls are threshold slider, move and resize scoll bars to repositon the region of interest being analysed and buttons to run a single or continuous analysis on many images stored. As I said, I have all the code working for these elements but only if it's done on the same form. It's the pathways for two-way interaction which is causing me the problem. My lack of experience in object oriented programming; which I'm finding tricky and frustrating.
I hope your brain enjoys the rest and look forward to your return Bill.
defunktlemon
6-Dec-14 8:12am
View
All sounds correct Bill apart from the process isn't started until the second UI is opened. This will actually start the process and control it.
Initially, the UI, Form1, needs to show a loaded image only after a process has already been ran. When the user either right clicks on the image or clicks a button on Form1 they can open the second UI which will have the inspection button along with other buttons to re-start and control the process.
So, for example, if this process ran and failed, I would then be able to see the failed image and open up the second UI to adjust settings and run the analysis on it again to test which settings worked.
To be clear, I am using Visual Studio Express 2013 to do this in.
defunktlemon
25-Feb-13 22:52pm
View
Deleted
I fail to see how you can accuse me of any rude or anti-social behavior. Perhaps not the same for the other side can be said, though I have more dignity than to say it.
defunktlemon
25-Feb-13 22:34pm
View
Deleted
You answered my question but you didn't solve my problem. I hope that answers your question. So apparently, that is not all that matters.
As to the numbers game, those that count will count.
I think it best that our communication stop here Sergey. Please allow me to be answered by others and free you up to spend your considerable time, free of charge, without any your interest, for other users problems.
Perhaps it best that you 'blackspot' me from your list of those you wish to help and instruct the site owners to delete this question / page.
defunktlemon
25-Feb-13 19:50pm
View
Deleted
I'm afraid that I cannot accept a solution until it has solved my problem, i.e. solution.
The problem is far from solved as far as I am concerned. Don't you think that might be the 'purpose' of 'accepting the answer formally' (green button)?
Ask yourself this, if it is still confusing you; where on this page have you seen me posting a successful result (probably with a smiley face attached)? And some kind of acknowledgement and thanks?
defunktlemon
25-Feb-13 19:33pm
View
Deleted
mine is a learning, not a numbers game. Hope you can accept that, formally.
defunktlemon
25-Feb-13 19:27pm
View
Deleted
yes, I want to show a static image - I'm in the process of showing demonstrations of my work to my tutors who want to be able to 'see' my work.
defunktlemon
25-Feb-13 19:19pm
View
seriously?
defunktlemon
25-Feb-13 19:12pm
View
I ran it - it ran ok and loaded the image. but are the lockpicks and image display linked. they seem separate and unrelated. So, I run the lockpicks ok, but then run the buttonclick as a separate thing.
"better move it to the question where you can format it"
it was in the 'Have a Question or Comment'link. Is that wrong?
defunktlemon
25-Feb-13 18:55pm
View
yeah cool thanks - so, how do I do that?
defunktlemon
25-Feb-13 18:28pm
View
hey! how's this Sergey
public Form1()
{
InitializeComponent();
}
private void LockUnlockBitsExample(PaintEventArgs e)
{
Bitmap myImage = new Bitmap("C:\\Users\\jason\\Documents\\IProject\\code\\imageAlign\\imageAlign\\bin\\Debug\\good.jpg");
// Lock the bitmap's bits.
Rectangle rect = new Rectangle(0, 0, myImage.Height, myImage.Width);
System.Drawing.Imaging.BitmapData bmpData =
myImage.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadWrite,
myImage.PixelFormat);
// Get the address of the first line.
IntPtr ptr = bmpData.Scan0;
// Declare an array to hold the bytes of the bitmap.
int bytes = Math.Abs(bmpData.Stride) * myImage.Height;
byte[] rgbValues = new byte[bytes];
// Copy the RGB values into the array.
System.Runtime.InteropServices.Marshal.Copy(ptr, rgbValues, 0, bytes);
// Set every third value to 255. A 24bpp bitmap will look red.
for (int counter = 2; counter < rgbValues.Length; counter += 3)
rgbValues[counter] = 255;
// Copy the RGB values back to the bitmap
System.Runtime.InteropServices.Marshal.Copy(rgbValues, 0, ptr, bytes);
// Unlock the bits.
myImage.UnlockBits(bmpData);
// Draw the modified image.
e.Graphics.DrawImage(myImage, 0, 150);
}
private void button1_Click(object sender, EventArgs e)
{
openFileDialog1.Filter = "JPEG IMAGES|*.jpg";
openFileDialog1.InitialDirectory = "C:\\Users\\jason\\Documents\\IProject\\code\\imageAlign\\imageAlign\\bin\\Debug";
openFileDialog1.Title = "Open Image";
if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
panel1.BackgroundImage = Image.FromFile(openFileDialog1.FileName);
panel1.Invalidate();
}
Bitmap myImage;
myImage = (Bitmap)Image.FromFile(openFileDialog1.FileName);
panel1.BackgroundImage = myImage;
// Array for keeping the sums of each row of pixels
float[] resultArray = new float[myImage.Height];
// Populate the array with data from each row of pixels, using the brightness value
for (int i = 0; i < myImage.Height; i++)
{
float value = 0;
for (int j = 0; j < myImage.Width; j++)
{
value += myImage.GetPixel(j, i).GetBrightness();//get colour of pixel and that Hue-Saturation-Brightness values
}
resultArray[i] = value;
}
}
defunktlemon
25-Feb-13 17:14pm
View
so, can I go from the lockpixel into a new method to open and draw that image in a panel with a buttonclick method?
like, how do i get to see the image with the rectangle drawn on it from this point?
defunktlemon
25-Feb-13 16:50pm
View
I think this may be way too advanced for me - i'm just a newbie. Don't you think it is better for a newbie to not worry about performance so much and just use the Get / Set pixels as they are easier?
defunktlemon
25-Feb-13 16:41pm
View
I have a question about this method Sergey. As stated in the original problem above, I would like for this to scan the image in a few different sections and draw around those sections which have a certain pixel value higher than a threshold set. It is possible to do that with this method, right?
defunktlemon
25-Feb-13 16:34pm
View
ok. I have gotten the lockbits, or lickbits as you like to call it :), into the program.
But no image loads into the panel? Can I use a panel or should it be picturebox? If I am not mistaken you are not a fan of picturebox as much as get / set pixels :)
defunktlemon
25-Feb-13 12:30pm
View
you want me to use LockPixels?
defunktlemon
25-Feb-13 8:41am
View
Hi OriginalGriff.
If I add your declaration 'Image', I am then declaring a local variable already defined in that scope; as an Image and a Bitmap.
If I comment out the Bitmap declaration it seems ok - but with both of these methods the error on GetPixel (missing using directive or an assembly reference) reappears.
This is how the code looks, which I think is ok. It is after the 'If'statment. Is it wrong? I need the Image declaration as well?
Bitmap myImage;
myImage = (Bitmap)Image.FromFile(openFileDialog1.Filename);
Also, I can't understand your last comment -
"I would also recommend that your OpenFileDialog is constructed in the method, and you use a Bitmap as the generic Image does not have a GetPixel method."
OpenFileDialog is actioned after buttonClick1
panel1.BackgroundImage = myImage;
defunktlemon
25-Feb-13 7:23am
View
OriginalGriff.
Guess what? I need to change the code you helped me complete to have a slightly different functionality. And, I think you're the best man for the task of helping me achieve that, given that you gave the initial solution. But, as you suggested, this would be better in a new post. Do you have some time in the near future? I can stick a link here to the new problem.
defunktlemon
25-Feb-13 5:48am
View
ahh! I understand. Thank you johanne.
I have actually decided to go with the panel option, which has worked out well. At least, until I added some code to get the pixel values which created another problem. But that's another story - one found at the link below, if you're interested ;)
http://www.codeproject.com/Questions/551825/namingplusbackgroundpluspanelplusimage?cmt=403438#cmt2_551825
defunktlemon
24-Feb-13 13:48pm
View
yes - that has gotten rid of the red. thank you Groover - I have one more error and then I think I can fly :)
for (int j = 0; j < myImage.Width; j++)
{
value += myImage.GetPixel(j, i).GetBrightness();//get colour of pixel and that Hue-Saturation-Brightness values
}
On the GetPixel i'm asked if i'm missing a using directive or an assembly reference - isn't this normally if a namespace is missing?
defunktlemon
24-Feb-13 13:07pm
View
I decalred it as Bitmap myImage;
All errors left except one - 'use of unasigned local variable myImage'
or should it be - Bitmap myImage = panel1.BackgroundImage(Image.FromFile);
defunktlemon
24-Feb-13 12:58pm
View
it's not - I don't know what to declare it as. A bitmap - but the image is drawn on background so does that make it a Bitmap, I thought not - I thought if background panel image it was just held in memory.
defunktlemon
24-Feb-13 11:07am
View
not today - I'm exhausted as I'm sure you are - but if I have any questions about using that with my bigger plan would you mind if I continued this?
defunktlemon
24-Feb-13 10:58am
View
Oh my God!! You are my new best buddy Guru friend for life(however much life you have left)
I can't believe I have finally gotten this working at last(or you have) Been hitting this for weeks and weeks with others trying to help but all have fallen.
I have not had such excellent help on countless forums in all my life. Your responses today were highly detailed and totally committed. You earn a gold star sir - a beer if I could too.
Thank you thank you thank you.
I am your deepest admirer (even if you do have a long pony tail - even longer beard - and see the world in binary as all programmers of your era did.
Thank you sir. :)
defunktlemon
24-Feb-13 10:39am
View
also, it has in hte error box the Locals with e {X=29 Y = 14 Button = Left}
marked in red
defunktlemon
24-Feb-13 10:37am
View
It didn't make it to the first red dot. The form opened and when I clicked button1 the image loaded with not change in the dots. I then clicked button2 and the yellow arrow appeared over the first red dot - so I guess the paint_event is not hooked up?
defunktlemon
24-Feb-13 10:02am
View
I'll probably get arrested for posting too much code here - but just so you know what I have done here is the code from class From1: Form
private void button1_Click(object sender, EventArgs e)
{
openFileDialog1.Filter = "JPEG IMAGES|*.jpg";
openFileDialog1.InitialDirectory = "C:\\Users\\jason\\Documents\\IProject\\code\\imageAlign\\imageAlign\\bin\\Debug";
openFileDialog1.Title = "Open Image";
if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
panel1.BackgroundImage = Image.FromFile(openFileDialog1.FileName);
panel1.Invalidate();
}
}
private List<myrectangle> rects = new List<myrectangle>();
Random r = new Random();
Pen pen = new Pen(Brushes.Red, 2);
private void butAddARectangle_Click(object sender, EventArgs e)
{
Point p = new Point(r.Next(10, 100), r.Next(10, 100));
Size s = new Size(r.Next(10, 50), r.Next(10, 50));
rects.Add(new MyRectangle(p, s));
panel1.Invalidate();
}
private void MyPanel_Paint(object sender, PaintEventArgs e)
{
foreach (MyRectangle mr in rects)
{
mr.Draw(e.Graphics, pen);
}
}
defunktlemon
24-Feb-13 9:47am
View
Holy cow!... That really is some rather awesome explaining - I will have to digest that a few times to really get it I think. Greatly appreciated.
I think I have hooked up correctly. Not getting a result but no errors, which is nice.
I have two buttons on the form. The first opens the image in background of panel. The second is now hooked up to butAddRectangle_click - which I believe is correct.
My class code looks like the following:
public class MyRectangle
{
public Rectangle Rect { get; set; }
public MyRectangle(Point p, Size s)
{
Rect = new Rectangle(p, s);
}
//public MyRectangle()
//{
// // TODO: Complete member initialization
//}
public void Draw(Graphics g, Pen p)
{
g.DrawRectangle(p, Rect);
}
}
The second section you wrote is just pasted in my Form1.cs page.
Button 1 opens image ok but nothing happens when button 2 is clicked. Might this be because button two is not related to what the code in button1_click is doing?
defunktlemon
24-Feb-13 8:10am
View
I wonder if I should explain what I am trying to do overall to be sure we are on the same page.
After I have opened the image in the background of the form I will scan different sections of it to sum up the pixel values in each section. If the pixel values in each section are above a certain threshold set then the rectangle should be drawn over / around that section highlighting it so that people would know it is above the threshold. Are we still on the right track OriginalGriff?
defunktlemon
24-Feb-13 7:55am
View
wow! Now I'm really kazoonked! That is quite a complex piece of code for little ol' me. I have added the first part to the new class created, MyClass (with a capital beginning :))
And the second part you wrote to the 'public partial class Form1 : Form' page.
I need to 'hook them up'. Do you mean call the class - like 'MyRectangle mc = new MyRectangle();'?
Sorry - I'm newbie lemon.
When you say I need to had it context and a suitable pen, do you mean this:
using (Pen sb = new Pen(Color.Red,3))
{
e.Graphics.DrawRectangle(sb, 20, 20, 50, 50);
}
?
Thanks OG
defunktlemon
24-Feb-13 6:19am
View
I'm excited now and would like to try and put this into a class :)
I have created a class
<pre lang="c#"> class rectangle
{
private void panel1_Paint(object sender, PaintEventArgs e)
{
using (Pen sb = new Pen(Color.Red, 3))
{
e.Graphics.DrawRectangle(sb, 20, 20, 50, 50);
}</pre>
But don't know what to pass in the method call?
<pre lang="c#">rectangle mc = new rectangle();</pre>
defunktlemon
24-Feb-13 5:49am
View
Fantastic!! Yeah, I was kinda doing it wrong - just a bit.
So, when a class level private variable ends it automatically disposes of any resources used?
but I don't need to worry about that with the code as follows?
<pre lang="c#">private void button1_Click(object sender, EventArgs e)
{
//Bitmap newImage;
openFileDialog1.Filter = "JPEG IMAGES|*.jpg";
openFileDialog1.InitialDirectory = "C:\\Users\\jason\\Documents\\IProject\\code\\imageAlign\\imageAlign\\bin\\Debug";
openFileDialog1.Title = "Open Image";
if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
panel1.BackgroundImage = Image.FromFile(openFileDialog1.FileName);
panel1.Invalidate();
}
}
private void panel1_Paint(object sender, PaintEventArgs e)
{
using (Pen sb = new Pen (Color.Red,3))
{
e.Graphics.DrawRectangle(sb, 20, 20, 50, 50);
}
}</pre>
defunktlemon
24-Feb-13 4:45am
View
Thanks OringinalGriff - I put it into a button click event and it worked fine.
But, unless I have a picturebox I can't see the drawn rectangle. Does this mean that the pen can't be used in a panel?
defunktlemon
24-Feb-13 4:38am
View
Deleted
what event should it go in then?
defunktlemon
22-Feb-13 16:57pm
View
ok, I'm a bit lost now. What code have you changed johannesnestler?
I looked at your links Sergey and I don't need anything to work dynamically or interactively on these images. At least, not at this stage.
Let me explain what I am trying to do overall. I have an image which has been thresholded, using Otsu Thresholding found on this website. In this image there are different assets which when corrupted in the image will show up white, the rest of the image being black. I need to scan this image, with the assets in individually marked sections, to find the section location of the defective assets. I then need to draw on the image a box surrounding the section and write some text, probably to a file detailing what the defect is. This is all I need to do with drawing on the image. Could you please advise me on the best approach to achieve this kind of drawing. Thank you.
defunktlemon
20-Feb-13 15:31pm
View
It certainly does work - thank you johannestler. But it tiles the images again and again. This seems to be because of:
m_picturebox.Dock = DockStyle.Fill;
I changed the .Fill to other options but none give just a single full image.
Show More