1. مهمان گرامی، جهت ارسال پست، دانلود و سایر امکانات ویژه کاربران عضو، ثبت نام کنید.
    بستن اطلاعیه

تابعی برای ایجاد Reflection در عکس ها

شروع موضوع توسط minaaa ‏28/1/11 در انجمن Java Script

  1. کاربر پیشرفته

    تاریخ عضویت:
    ‏9/12/10
    ارسال ها:
    19,773
    تشکر شده:
    6,457
    امتیاز دستاورد:
    113
    به این تصویر نگاه کنید. فکر کنم احتیاج به توضیح نباشه که کار این تابع چیه





    [​IMG]nload="NcodeImageResizer.createOn(this);" border="0">



    اینم کد تابع:



    كد:
    [SOURCE="java"]
    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;
    }

    [/SOURCE]</pre>




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



    كد:
    imgSource= Image.createImage("/picture.jpg");
    reflectImg = createReflect(imgSource,0xffffff, imgSource.getHeight());</pre>


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