I have a problem with vshost.exe. At the beginning of my using this code, the program runs properly, but after I copy the program, now comes a warning like this:
vshost.exe has stopped working
What makes this happen? code as follows:
YIQprocess2 YIQ2 = new YIQprocess2();
YIQ2.Image = EditImage;
YIQ2.YIQmethod2();
cetakgambar();
This is my class :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Drawing.Imaging;
namespace SkinCancerR01.BusinessRule
{
public class YIQprocess2
{
public Bitmap Image { get; set; }
public int seed, t, nilaikecil, nilaibesar, sementara;
public void YIQmethod2()
{
Bitmap EditImage = this.Image;
BitmapData bmData = EditImage.LockBits(new Rectangle(0, 0, EditImage.Width, EditImage.Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
int stride = bmData.Stride;
System.IntPtr Scan0 = bmData.Scan0;
unsafe
{
byte* p = (byte*)(void*)Scan0;
int nOffset = stride - EditImage.Width * 3;
byte red, green, blue, Yx, Ix, Qx;
for (int y = 0; y < EditImage.Height; ++y)
{
for (int x = 0; x < EditImage.Width; ++x)
{
blue = p[x];
green = p[x + 1];
red = p[x + 2];
Yx = (byte)(.299 * red + .587 * green + .114 * blue);
Ix = (byte)(.596 * red - .275 * green - .321 * blue);
Qx = (byte)(.212 * red - .528 * green + .311 * blue);
if ((y == 0) && (x == 0))
{
nilaikecil = Yx;
nilaibesar = Yx;
}
else
{
if (Yx < nilaikecil)
{
nilaikecil = Yx;
}
else if (Yx > nilaibesar)
{
nilaibesar = Yx;
}
}
p += 3;
}
p += nOffset;
}
}
t = (nilaibesar - nilaikecil) / 3;
unsafe
{
byte* p = (byte*)(void*)Scan0;
int nOffset = stride - EditImage.Width * 3;
byte red, green, blue, Yx, Ix, Qx;
for (int y = 0; y < EditImage.Height; ++y)
{
for (int x = 0; x < EditImage.Width; ++x)
{
blue = p[x];
green = p[x + 1];
red = p[x + 2];
Yx = (byte)(.299 * red + .587 * green + .114 * blue);
Ix = (byte)(.596 * red - .275 * green - .321 * blue);
Qx = (byte)(.212 * red - .528 * green + .311 * blue);
if ((x == 0) || (seed == 0))
{
seed = Yx;
}
else
{
sementara = Yx - seed;
sementara = Math.Abs(sementara);
if (sementara >= t)
{
for (int i = 0; i < 2; ++i)
{
p[x] = p[x + 1] = p[x + 2] = 255;
++x;
}
seed = 0;
}
}
p += 3;
}
p += nOffset;
}
}
EditImage.UnlockBits(bmData);
}
}
}