public Image BlendImage(Image img1, Image img2, int bval) {
Image gImage = Image.createImage(img1.getWidth(), img1.getHeight());
Graphics gg = mImage.getGraphics();
gg.setColor(0xFFE3FFF);
gg.fillRect(0, 0, img1.getWidth(), img1.getHeight());
int[] ri = new int[img1.getWidth() * img1.getHeight()];
img1.getRGB(ri, 0, img1.getWidth(), 0, 0, img1.getWidth(), img1.getHeight());
Effect.blend(ri, bval);
Image temp = Image.createRGBImage(ri, img1.getWidth(), img1.getHeight(), true);
gg.drawImage(img2, 0, 0, 0);
gg.drawImage(temp, 0, 0, 0);
Graphics g1 = img1.getGraphics();
g1.drawImage(mImage, 0, 0, 0);
mImage = null;
temp = null;
System.gc();
return img1;
}
class Effect {
public static void blend(int[] r, int aVal, int mClr1, int mClr2) {
int len = r.length;
for (int i = 0; i < len; i++) {
int a = 0;
int c = (r[i] & 0x00FFFFFF);
if (mClr1 == c) {
a = 0;
} else if (mClr2 == c) {
a = 255;
} else if (alphaValue > 0) {
a = aVal;
}
a = (a << 24);
c+= a;
r[i] = c;
}
}
public static void blend(int[] r, int aVal) {
blend(raw, aVal, 0xFFFFFFFF, 0xFFFFFFFF);
}
}
// Enjoy with Images !!!!!
Monday, December 28, 2009
Friday, December 25, 2009
Date Class - validating Date, formatting ,getting current date ... etc
“No dream is bigger than the dreamer…….”
import java.util.Calendar;
import java.util.Date;
public class gDate {
public final int DATE_FORMAT_DD_MM_YY = 0 ;
public final int DATE_FORMAT_DD_MM_YYYY = 1 ;
public final int DATE_FORMAT_MM_DD_YYYY = 2 ;
public final int DATE_FORMAT_DDMMYYYY = 3 ;
public final int DATE_FORMAT_MMDDYYYY = 4 ;
private int format = 0;
private String sep = "-" ;
public String getDate(int format,String separator) {
this.format = format;
Date xdate = new Date();
java.util.Calendar rightNow = java.util.Calendar.getInstance();
rightNow.setTime(xdate);
String year = String.valueOf(rightNow.get(java.util.Calendar.YEAR));
String month = String.valueOf(rightNow.get(java.util.Calendar.MONTH) + 1);
String day = String.valueOf(rightNow.get(java.util.Calendar.DATE));
if (day.length() < 2) {
day = "0" + day;
}
if (month.length() < 2) {
month = "0" + month;
}
if (separator == null) {
separator = sep ;
}
String ndate = year + "-" + month + "-" + day;
ndate = year + month + day;
switch ( format) {
case 0 :
ndate = day+separator+month+separator+year.substring(year.length()-2) ;
break;
case 1 :
ndate = day+separator+month+separator+year ;
break;
case 2 :
ndate = month+separator+day+separator+year ;
break;
case 3 :
ndate = day+month+year ;
break;
case 4 :ndate = month+day+year ;
break;
}
return ndate;
}
public boolean validateDate(String stringdate) {
boolean valid = false;
Calendar cal = Calendar.getInstance();
cal.set(Calendar.DATE, Integer.parseInt(stringdate.substring(8, 10) ) );
cal.set(Calendar.MONTH, Integer.parseInt(stringdate.substring(5, 7))-1 );
cal.set(Calendar.YEAR, Integer.parseInt(stringdate.substring(0, 4)) );
try {
cal.getTime();
valid = true;
} catch (IllegalArgumentException ex) {
System.out.println(ex.getMessage());
}
return valid;
}
public Date setDate(String dte) {
String dyStr = dte.substring(6, 8);
String mtStr = dte.substring(4, 6);
String yrStr = dte.substring(0, 4);
Calendar cal = Calendar.getInstance();
cal.set(Calendar.DATE, Integer.parseInt(dyStr));
cal.set(Calendar.MONTH, Integer.parseInt(mtStr));
cal.set(Calendar.YEAR,Integer.parseInt(yrStr));
try {
cal.getTime();
} catch (IllegalArgumentException ex) {
System.out.println(ex.getMessage());
}
return new Date();
}
public boolean isDate(Date date) {
Date olddate = setDate("12610101");
if (!date.equals(olddate)) {
return false;
}
return true;
}
}
import java.util.Calendar;
import java.util.Date;
public class gDate {
public final int DATE_FORMAT_DD_MM_YY = 0 ;
public final int DATE_FORMAT_DD_MM_YYYY = 1 ;
public final int DATE_FORMAT_MM_DD_YYYY = 2 ;
public final int DATE_FORMAT_DDMMYYYY = 3 ;
public final int DATE_FORMAT_MMDDYYYY = 4 ;
private int format = 0;
private String sep = "-" ;
public String getDate(int format,String separator) {
this.format = format;
Date xdate = new Date();
java.util.Calendar rightNow = java.util.Calendar.getInstance();
rightNow.setTime(xdate);
String year = String.valueOf(rightNow.get(java.util.Calendar.YEAR));
String month = String.valueOf(rightNow.get(java.util.Calendar.MONTH) + 1);
String day = String.valueOf(rightNow.get(java.util.Calendar.DATE));
if (day.length() < 2) {
day = "0" + day;
}
if (month.length() < 2) {
month = "0" + month;
}
if (separator == null) {
separator = sep ;
}
String ndate = year + "-" + month + "-" + day;
ndate = year + month + day;
switch ( format) {
case 0 :
ndate = day+separator+month+separator+year.substring(year.length()-2) ;
break;
case 1 :
ndate = day+separator+month+separator+year ;
break;
case 2 :
ndate = month+separator+day+separator+year ;
break;
case 3 :
ndate = day+month+year ;
break;
case 4 :ndate = month+day+year ;
break;
}
return ndate;
}
public boolean validateDate(String stringdate) {
boolean valid = false;
Calendar cal = Calendar.getInstance();
cal.set(Calendar.DATE, Integer.parseInt(stringdate.substring(8, 10) ) );
cal.set(Calendar.MONTH, Integer.parseInt(stringdate.substring(5, 7))-1 );
cal.set(Calendar.YEAR, Integer.parseInt(stringdate.substring(0, 4)) );
try {
cal.getTime();
valid = true;
} catch (IllegalArgumentException ex) {
System.out.println(ex.getMessage());
}
return valid;
}
public Date setDate(String dte) {
String dyStr = dte.substring(6, 8);
String mtStr = dte.substring(4, 6);
String yrStr = dte.substring(0, 4);
Calendar cal = Calendar.getInstance();
cal.set(Calendar.DATE, Integer.parseInt(dyStr));
cal.set(Calendar.MONTH, Integer.parseInt(mtStr));
cal.set(Calendar.YEAR,Integer.parseInt(yrStr));
try {
cal.getTime();
} catch (IllegalArgumentException ex) {
System.out.println(ex.getMessage());
}
return new Date();
}
public boolean isDate(Date date) {
Date olddate = setDate("12610101");
if (!date.equals(olddate)) {
return false;
}
return true;
}
}
Subscribe to:
Posts (Atom)