ورود

View Full Version : تابعی برای ایجاد Reflection در عکس ها



ermia2008
پنج شنبه 26 شهریور 1388, 01:43 صبح
سلام دوستان

یه این تصویر نگاه کنید. فکر کنم احتیاج به توضیح نباشه که کار این تابع چیه
امیدوارم مفید واقع بشه

http://ermia2008.persiangig.com/image/reflection.PNG

اینم کد تابع:




public static Image createReflect(Image image, int bgColor, int reflectionHeight)
{
int w = image.getWidth();
int h = image.getHeight();

Image reflectedImage = Image.createImage(w, h + reflectionHeight);

Graphics g = reflectedImage.getGraphics();

g.setColor(bgColor);
g.fillRect(0, 0, w, h + reflectionHeight);

g.drawImage(image, 0, 0, Graphics.TOP | Graphics.LEFT);

int[] rgba = new int[w];
int currentY = -1;

for(int i = 0; i < reflectionHeight; i++)
{
int y = (h - 1) - (i * h / reflectionHeight);

if(y != currentY)
image.getRGB(rgba, 0, w, 0, y, w, 1);

int alpha = 0xff - (i * 0xff / reflectionHeight);

for(int j = 0; j < w; j++)
{
int origAlpha = (rgba[j] >> 24);
int newAlpha = (alpha & origAlpha) * alpha / 0xff;

rgba[j] = (rgba[j] & 0x00ffffff);
rgba[j] = (rgba[j] | (newAlpha << 24));
}

g.drawRGB(rgba, 0, w, 0, h + i, w, 1, true);
}
return reflectedImage;
}




برای فراخوانیش به این صورت عمل کنید:



imgSource= Image.createImage("/picture.jpg");
reflectImg = createReflect(imgSource,0xffffff, imgSource.getHeight());



که ffffff همون رنگ سفیده که در واقع رنگ پس زمینه هست

موفق باشید