Hi,
First of all congratulation for this forum,it's really useful.
My point is:
I have made an application of image processing.
This application contains three picture boxes and three buttons,pictureBox1, pictureBox2,pictuerBox3.
The first button which name is "Load" loads the picture we choose in the first picture box (pictureBox1)
The second button which name is "Process" edits the loaded image and in the same time, image appears in the second picture Box(pictureBox2)
The third button which name is "Stage 2" edits the pixel (resize them) and loads the image from the second picture box to the third picture box (pictureBox3).
My problem is that in the last picture box my loaded image appears with horizontal lines...How can I eliminate the horizontal white lines from the third image in the last picture box (pictureBox3)????
The full code for all these above is:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace SetPixel_4
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
//Action of "Load" button
private void button1_Click(object sender, EventArgs e)
{ //Load an image
try
{
OpenFileDialog open = new OpenFileDialog();
open.Filter = "Image Files(*.jpg; *.jpeg; *.gif; *.bmp)|*.jpg; *.jpeg; *.gif; *.bmp";
if (open.ShowDialog() == DialogResult.OK)
{
pictureBox1.Image = new Bitmap(open.FileName);
}
}
catch (Exception)
{
throw new ApplicationException("Failed loading image");
}
}
// Pass the image to process to our method
private void SetMyPicture(Image pbImage)
{
// Make sure that the image isn't null first
if (pbImage != null)
{
Bitmap myBitmap = new Bitmap(pbImage);
for (int Xcount = 0; Xcount < myBitmap.Width; Xcount=Xcount+10)
{
for (int Ycount = 0; Ycount < myBitmap.Height; Ycount++)
{
if (Xcount % 10 == 0)
{
myBitmap.SetPixel(Xcount, Ycount, Color.White);
}
}
}
for (int Xcount = 0; Xcount < myBitmap.Width; Xcount++)
{
for (int Ycount = 0; Ycount < myBitmap.Height; Ycount = Ycount+10)
{
if (Ycount % 10 == 0)
{
myBitmap.SetPixel(Xcount, Ycount, Color.White);
}
}
}
pictureBox2.Image = myBitmap;
}
}
//Action of "Process" button
private void button2_Click_1(object sender, EventArgs e)
{
// calling my method and give it the first picturebox's Image.
SetMyPicture(pictureBox1.Image);
}
//Action for button "Stage 2"
private void button3_Click(object sender, EventArgs e)
{
Stage2(pictureBox2.Image);
}
// The method Stage2
private void Stage2(Image pbImage)
{
int skipx=0;
int skipy;
Color scolor;
int newx, newy;
newx = pbImage.Width - System.Convert.ToInt32(Math.Floor((double) (pbImage.Width/10)))-1;
newy = pbImage.Height - System.Convert.ToInt32(Math.Floor((double)(pbImage.Height/10)))-1;
// Make sure that the image isn't null first
if (pbImage != null){
Bitmap myBitmap = new Bitmap(newx , newy);
Bitmap sImage = new Bitmap(pbImage);
for (int x = 0; x < myBitmap.Width; x++)
{
if (x % 10 == 0){
skipx++;
}
else{
for (int y = 0; y < myBitmap.Height; y++)
{
skipy = 0;
if (y % 10 == 0){
skipy++;
}
else
{
scolor = sImage.GetPixel(x, y); //get color
myBitmap.SetPixel(x-skipx, y-skipy, scolor);
}
}
}
}
pictureBox3.Image = myBitmap;
}
}
}
}
Thank you in advance for your time!!!
I'll be waiting for your answers...
This is what i mean:
http://img140.imageshack.us/img140/9915/51371256.jpg (screenshot of my application)
My problem is in the third picture box (pictureBox3).All i want to do is, after pressing "Stage 2" button (stage 2 method) to eliminate the horizontal lines from there and have the resized picture...!
Loading
Jaish MathewsPosted May 18, 2010, 5:59 AM
Below are the modified methods. What I done is
//New global variable
Bitmap global = null;
=======================
//New method to set pixel in 3rd image
private void SetImagePixel(Bitmap myBitmap, int x)
{
Color scolor;
for (int y = 0; y < myBitmap.Height; y++)
{
scolor = global.GetPixel(x, y); //get color
myBitmap.SetPixel(x, y, scolor);
}
}
===========================================
//New line in existing SetMyPicture to store the 2nd image to global Bitmap
private void SetMyPicture(Image pbImage)
{
// Make sure that the image isn't null first
if (pbImage != null)
{
Bitmap myBitmap = new Bitmap(pbImage);
// New global Bitmap setting before processing for white columns and later will
//be used to read the exact colors
global = new Bitmap(pbImage); ;
......................................
...............................
}
//Modified Stage2 method which is now calling SetImagePixel()
private void Stage2(Image pbImage)
{
int newx, newy;
newx = pbImage.Width - System.Convert.ToInt32(Math.Floor((double)(pbImage.Width / 10))) - 1;
newy = pbImage.Height - System.Convert.ToInt32(Math.Floor((double)(pbImage.Height / 10))) - 1;
// Make sure that the image isn't null first
if (pbImage != null)
{
Bitmap myBitmap = new Bitmap(newx, newy);
for (int x = 0; x < myBitmap.Width; x++)
{
SetImagePixel(myBitmap, x);
}
pictureBox3.Image = myBitmap;
}
}
Christos AlexiouPosted May 18, 2010, 8:43 AM
Thank you very much Jaish!!!Thanx for your time!!!
Jaish MathewsPosted May 18, 2010, 7:40 AM
These type of issues expecting to be fixed from your side. I am just seeing 2 methods with same name "SetImagePixel()" in your code by just reading from heer itself. You may copied 2 times.
Christos AlexiouPosted May 18, 2010, 7:17 AM
private void Stage2(Image pbImage)
{
int newx, newy;
newx = pbImage.Width - System.Convert.ToInt32(Math.Floor((double)(pbImage.Width / 10))) - 1;
newy = pbImage.Height - System.Convert.ToInt32(Math.Floor((double)(pbImage.Height / 10))) - 1;
// Make sure that the image isn't null first
if (pbImage != null)
{
Bitmap myBitmap = new Bitmap(newx, newy);
for (int x = 0; x < myBitmap.Width; x++)
{
SetImagePixel(myBitmap, x);
}
pictureBox3.Image = myBitmap;
}
}
}
}
But Jaish the SetImagePixel(myBitmap,x) (the bold) is underlined...
After building a solution have the message: Error 1 Type 'SetPixel_4.Form1' already defines a member called 'SetImagePixel' with the same parameter types C:\Users\Christos\Desktop\SetPixel_4\SetPixel_4\Form1.cs 106 22 SetPixel_4
Jaish MathewsPosted May 18, 2010, 7:15 AM
Christos AlexiouPosted May 18, 2010, 6:35 AM
All i have to do now is to modify the existing methods in the first code or have to do other changes???
Christos AlexiouPosted May 18, 2010, 5:06 AM
1)The cross lines in the second picture box (pictureBox2) show me the pixels of the photo which i want to resize.
2) %10 is modulo to have the step in the for loop from pixel to pixel.
Do you think that is much better to change something in this code...??
If you have a better solution,that's ok!!!But I have no idea for something better...
Thank you for your time anyway!!!!
Jaish MathewsPosted May 18, 2010, 4:59 AM
Christos AlexiouPosted May 18, 2010, 4:44 AM
Of course you replied to me and thank you for that.But I don't know what color is the appropriate to fill the white lines so I can have the resized image...
Jaish MathewsPosted May 18, 2010, 4:27 AM
You need to fill with proper colors on mentioned blocks. But what color needs to be used, your option.
Christos AlexiouPosted May 18, 2010, 1:58 AM
First of all,thank you for your time!
My problem is not to get any lines in the third picture Box (pictureBox3) but to eliminate them...
I have read what you wrote me...but i didn't get the right result...to have the pure resized picture.
Jaish MathewsPosted May 18, 2010, 1:50 AM
The white line is appearing as you are not setting any Pixel color in below lines
if (y % 10 == 0)
{
skipy++;
}
and also here
if (x % 10 == 0)
{
skipx++;
}
I just set green color inside Y part like below and I got green lines.
if (y % 10 == 0)
{
myBitmap.SetPixel(x - skipx, y - skipy, Color.Green);
skipy++;
}
So point is that when ever looping through pixels one by one, make sure that you are not leaving any pixel points without an assigned color. If no color has assigned, default white will be displayed.