Friday, April 4, 2008
Resize windows Form Controls w.r.t Screen Resolution
Add this class to your project and change the namespace name
Layout Manager Class
Now, your form will set displayed for all resolution monitors.....
Happy coding....
Friday, January 25, 2008
Unsharp Mask Algorithm in C#
Unsharp masking is a traditional darkroom technique that has proven very suitable for digital imaging.
The principle of unsharp masking is to create a blurred copy of the image and compare it to the underlying original. The difference in colour values between the two images is greatest for the pixels near sharp edges. When this difference is subtracted from the original image, the edges will be accentuated.
private unsafe Bitmap UnsharpMask(Bitmap img, double amount, double radius, double threshold)
{
if (amount > 500) amount = 500;
amount = amount * 2;
if (radius > 50) radius = 50;
radius = radius * 2;
if (threshold > 255) threshold = 255;
if (radius == 0)
{
img.Dispose();
return img;
}
int w = img.Width; int h = img.Height;
Bitmap imgBlur = new Bitmap(w, h);
ConvMatrix con = new ConvMatrix();
imgBlur = (Bitmap)img.Clone();
BitmapFilter.Conv3x3(imgBlur, con);
BitmapData imgdata1 = img.LockBits(new Rectangle(0, 0, w, h), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
BitmapData imgdata2 = imgBlur.LockBits(new Rectangle(0, 0, w, h), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
byte* p1 = (byte*)(void*)imgdata1.Scan0;
byte* p2 = (byte*)(void*)imgdata2.Scan0;
if (threshold > 0)
{
for (int x = 0; x < y =" 0;" imgrvalue =" p1[2];" imggvalue =" p1[1];" imgbvalue =" p1[0];" imgblurrvalue =" p2[2];" imgblurgvalue =" p2[1];" imgblurbvalue =" p2[0];" rnew =" (Math.Abs(imgRValue">= (int)threshold)
? Math.Max(0, Math.Min(255, ((int)amount * (imgRValue - imgBlurRValue)) + imgRValue)) : imgRValue;
int gNew = (Math.Abs(imgGValue - imgBlurGValue) >= (int)threshold)
? Math.Max(0, Math.Min(255, ((int)amount * (imgGValue - imgBlurGValue)) + imgGValue)) : imgGValue;
int bNew = (Math.Abs(imgBValue - imgBlurBValue) >= (int)threshold)
? Math.Max(0, Math.Min(255, ((int)amount * (imgBValue - imgBlurBValue)) + imgBValue)) : imgBValue;
if ((imgRValue != rNew) || (imgGValue != gNew) || (imgBValue != bNew))
{
p1[0] = (byte)bNew;
p1[1] = (byte)gNew;
p1[2] = (byte)rNew;
//img.SetPixel(x, y, System.Drawing.Color.FromArgb(rNew, gNew, bNew));
}
p1 = p1 + 3;
p2 = p2 + 3;
}
}
}
else
{
for (int x = 0; x < y =" 0;" imgrvalue =" p1[2];" imggvalue =" p1[1];" imgbvalue =" p1[0];" imgblurrvalue =" p2[2];" imgblurgvalue =" p2[1];" imgblurbvalue =" p2[0];" rnew =" ((int)amount"> 255)
rNew = 255;
else if (rNew < rnew =" 0;" gnew =" ((int)amount"> 255)
gNew = 255;
else if (gNew < gnew =" 0;" bnew =" ((int)amount"> 255)
bNew = 255;
else if (bNew < bnew =" 0;" p1 =" p1" p2 =" p2" topleft =" 1," topmid =" 2," topright =" 1;" midleft =" 2," pixel =" 4," midright =" 2;" bottomleft =" 1," bottommid =" 2," bottomright =" 1;" factor =" 16;" offset =" 0;" topleft =" TopMid" topright =" MidLeft" pixel =" MidRight" bottomleft =" BottomMid" bottomright =" nVal;" 0 ="=" bsrc =" (Bitmap)b.Clone();" bmdata =" b.LockBits(new" bmsrc =" bSrc.LockBits(new" stride =" bmData.Stride;" stride2 =" stride" scan0 =" bmData.Scan0;" srcscan0 =" bmSrc.Scan0;" p =" (byte*)(void*)Scan0;" psrc =" (byte*)(void*)SrcScan0;" noffset =" stride" nwidth =" b.Width" nheight =" b.Height" y =" 0;" x =" 0;" npixel =" ((((pSrc[2]" npixel =" 0;"> 255) nPixel = 255;
p[5 + stride] = (byte)nPixel;
nPixel = ((((pSrc[1] * m.TopLeft) + (pSrc[4] * m.TopMid) + (pSrc[7] * m.TopRight) +
(pSrc[1 + stride] * m.MidLeft) + (pSrc[4 + stride] * m.Pixel) + (pSrc[7 + stride] * m.MidRight) +
(pSrc[1 + stride2] * m.BottomLeft) + (pSrc[4 + stride2] * m.BottomMid) + (pSrc[7 + stride2] * m.BottomRight)) / m.Factor) + m.Offset);
if (nPixel < npixel =" 0;"> 255) nPixel = 255;
p[4 + stride] = (byte)nPixel;
nPixel = ((((pSrc[0] * m.TopLeft) + (pSrc[3] * m.TopMid) + (pSrc[6] * m.TopRight) +
(pSrc[0 + stride] * m.MidLeft) + (pSrc[3 + stride] * m.Pixel) + (pSrc[6 + stride] * m.MidRight) +
(pSrc[0 + stride2] * m.BottomLeft) + (pSrc[3 + stride2] * m.BottomMid) + (pSrc[6 + stride2] * m.BottomRight)) / m.Factor) + m.Offset);
if (nPixel < npixel =" 0;"> 255) nPixel = 255;
p[3 + stride] = (byte)nPixel;
p += 3;
pSrc += 3;
}
p += nOffset;
pSrc += nOffset;
}
}
b.UnlockBits(bmData);
bSrc.UnlockBits(bmSrc);
return true;
}
Wednesday, December 26, 2007
Non-Smokers, avoid Second hand smoking, Beware of Smokers!!!
Secondhand smoke, also known as environmental tobacco smoke (ETS) or passive smoke, is a mixture of 2 forms of smoke from burning tobacco products:
- Sidestream smoke: smoke that comes from the end of a lighted cigarette, pipe, or cigar
- Mainstream smoke: smoke that is exhaled by a smoker
So, Smokers dont make harm to your friends and Non-smokers avoid standing near smokers when he smoke and if possible try to make your smoking friends to stop smoking..
Smokers, Please Stop smoking atleast when you are with your non-smoking friends. This is good for both of your health...
Google Search results in your mobile phone via SMS
Text message your search query to 54664 ('5GOOG' on most devices) and we'll text message back results.
Google SMS is a premium SMS service; queries sent to 54664 will be charged at the following rates:
- Aircel: Rs. 3.00
- Airtel: Rs. 2.00
- BPL: Rs. 3.00
- BSNL: Rs. 0.80/1.00 (post-paid/pre-paid)
- Reliance: Rs. 3.00
- Spice: Rs. 3.00
- Tata: Rs. 3.00
- Note: Incoming messages from Google are not charged.
If you are away from your computer, feeling hungry and you want to know the address of near by restaurants. At that time, you feel that if am in home or office i can search in Google for the nearby restaurants. Don't worry, Google is now providing an Google search SMS search. All you need is a mobile phone, no need of GPRS connection too..
Just send an SMS to 54664 with your search query, you will get the search results in a short while. The Provider may charge for this SMS and the charge varies between providers..
Enjoy!!! Google search anywhere, anytime from your mobile phone...
Monday, December 24, 2007
Geocode and Reverse Geocode
The process of geocode is getting the latitude and longtitude values of the corresponding address and the Reverse Geocode is the process of getting the address of the corresponding latitude and longtitude values. This can be shown here...
We can also develop our own page with geocode and reverse geocode using this ArcWebservice
FPDF library to create pdf files
Here is my code which requires fpdf.php and array of image file name with full path, which u can download from the above link..
require('fpdf.php');
$pdf = new FPDF();
foreach($fileList as &$filename)
{
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,substr(strrchr($filename,"/"),1));
$pdf->Image($filename,5,30,200,200,'jpg','');
}
$pdf->Output();
?>
Upload image using J2ME and KSOAP
Here, the UploadPhoto class calls the PaymentInfo function which is in the server side and passing parameters as soapobjects like savePaymentInfo and PaymentInfo which is send as a string and the image which is uploading is converted to Base64String which can be converted again to image in the server side...
To use this function, you have to download ksoap jar file and add it to the project library.
Here is the code from the client side i.e. mobile application
class UploadPhoto
{
try
{
SoapObject savePaymentInfo = new SoapObject("http://tempuri.org/", "SavePaymentInfo");
SoapObject PaymentInfo = new SoapObject("http://tempuri.org/", "PaymentInfo");
PaymentInfo.addProperty("AddLocation", addLocation);
PaymentInfo.addProperty("CreditCardId", "12345");
PaymentInfo.addProperty("Msisdn", "11111");
int length = new String(midlet.postCardString).length();
String stringToSend = new String(midlet.postCardString).substring(0,length-2);
PaymentInfo.addProperty("PostCards", stringToSend);
PaymentInfo.addProperty("ResizePhoto", resizePhototoPhone);
PaymentInfo.addProperty("SecurityCode", "5678");
PaymentInfo.addProperty("UploadPhotoServer", uploadPhototoServer);
PaymentInfo.addProperty("SendPhotoMyHome", sendPhototoPC);
if("true".compareTo(domesticPostcard) == 0)
{
PaymentInfo.addProperty("PostCardType", "Domestic");
}
else
{
PaymentInfo.addProperty("PostCardType", "InterNational");
}
savePaymentInfo.addProperty("paymentInfo", PaymentInfo);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.bodyOut = savePaymentInfo;
envelope.dotNet = true;
envelope.encodingStyle = SoapSerializationEnvelope.XSD;
HttpTransport httpTransport = new HttpTransport("http://url.asmx");
httpTransport.debug = true;
httpTransport.call("http://tempuri.org/SavePaymentInfo", envelope);
SoapObject result = (SoapObject)envelope.bodyIn;
String res = result.getProperty("SavePaymentInfoResult").toString();
if( res.equals("true") )
{
yesNoAlertMessageType = "PostCard(s)";
textBox.setString("");
deleteSendData();
displayreadfileCanvas = true;
httpTransport.reset();
midlet.displayGaugeAlert = false;
midlet.stopProcess();
repaint();
midlet.displayYesNoAlert = true;
midlet.errorMessage = "Sent Successfully";
repaint();
}
else if( res.equals("false"))
{
yesNoAlertMessageType = "PostCard(s)";
textBox.setString("");
displayreadfileCanvas = true;
httpTransport.reset();
midlet.displayGaugeAlert = false;
midlet.stopProcess();
repaint();
midlet.displayYesNoAlert = true;
midlet.errorMessage = "Sending Failed";
repaint();
}
}
catch (IOException ex)
{
System.out.println(ex.getMessage());
midlet.displayErrAlert = true;
midlet.errorMessage = "Server does not Exist";
repaint();
displayreadfileCanvas = true;
}
catch (XmlPullParserException ex)
{
System.out.println(ex.getMessage());
midlet.displayGaugeAlert = false;
repaint();
midlet.displayErrAlert = true;
midlet.errorMessage = "Server does not Exist";
repaint();
displayreadfileCanvas = true;
}
catch(Exception ex)
{
System.out.println(ex.getMessage());
midlet.displayGaugeAlert = false;
repaint();
midlet.displayErrAlert = true;
midlet.errorMessage = "Server does not Exist";
repaint();
displayreadfileCanvas = true;
}
};

