views:

98

answers:

3

Hi,

I have three UIImages added to three UIScrollviews that are positioned one under the other. I am trying to find a way to blur the adjacent edges that are between two scrollviews but am unable to find a way to do that.

Can someone please suggest a way to achieve this?

Any help will be appreciated

Thank You

Shumais Ul Haq

A: 

You could do some gaussian blurring on an image. This has been asked before.

static void blur(V2fT2f *quad, float t) // t = 1
{
    GLint tex;
    V2fT2f tmpquad[4];
    float offw = t / Input.wide;
    float offh = t / Input.high;
    int i;

    glGetIntegerv(GL_TEXTURE_BINDING_2D, &tex);

    // Three pass small blur, using rotated pattern to sample 17 texels:
    //
    // .\/.. 
    // ./\\/ 
    // \/X/\   rotated samples filter across texel corners
    // /\\/. 
    // ../\. 

    // Pass one: center nearest sample
    glVertexPointer  (2, GL_FLOAT, sizeof(V2fT2f), &quad[0].x);
    glTexCoordPointer(2, GL_FLOAT, sizeof(V2fT2f), &quad[0].s);
    glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
    glColor4f(1.0/5, 1.0/5, 1.0/5, 1.0);
    validateTexEnv();
    glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);

    // Pass two: accumulate two rotated linear samples
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE);
    for (i = 0; i < 4; i++)
    {
        tmpquad[i].x = quad[i].s + 1.5 * offw;
        tmpquad[i].y = quad[i].t + 0.5 * offh;
        tmpquad[i].s = quad[i].s - 1.5 * offw;
        tmpquad[i].t = quad[i].t - 0.5 * offh;
    }
    glTexCoordPointer(2, GL_FLOAT, sizeof(V2fT2f), &tmpquad[0].x);
    glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
    glActiveTexture(GL_TEXTURE1);
    glEnable(GL_TEXTURE_2D);
    glClientActiveTexture(GL_TEXTURE1);
    glTexCoordPointer(2, GL_FLOAT, sizeof(V2fT2f), &tmpquad[0].s);
    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
    glBindTexture(GL_TEXTURE_2D, tex);
    glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
    glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB,      GL_INTERPOLATE);
    glTexEnvi(GL_TEXTURE_ENV, GL_SRC0_RGB,         GL_TEXTURE);
    glTexEnvi(GL_TEXTURE_ENV, GL_SRC1_RGB,         GL_PREVIOUS);
    glTexEnvi(GL_TEXTURE_ENV, GL_SRC2_RGB,         GL_PRIMARY_COLOR);
    glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_RGB,     GL_SRC_COLOR);
    glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA,    GL_REPLACE);
    glTexEnvi(GL_TEXTURE_ENV, GL_SRC0_ALPHA,       GL_PRIMARY_COLOR);

    glColor4f(0.5, 0.5, 0.5, 2.0/5);
    validateTexEnv();
    glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);

    // Pass three: accumulate two rotated linear samples
    for (i = 0; i < 4; i++)
    {
        tmpquad[i].x = quad[i].s - 0.5 * offw;
        tmpquad[i].y = quad[i].t + 1.5 * offh;
        tmpquad[i].s = quad[i].s + 0.5 * offw;
        tmpquad[i].t = quad[i].t - 1.5 * offh;
    }
    glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);

    // Restore state
    glDisableClientState(GL_TEXTURE_COORD_ARRAY);
    glClientActiveTexture(GL_TEXTURE0);
    glBindTexture(GL_TEXTURE_2D, Half.texID);
    glDisable(GL_TEXTURE_2D);
    glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_RGB,     GL_SRC_ALPHA);
    glActiveTexture(GL_TEXTURE0);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    glDisable(GL_BLEND);
}
willcodejavaforfood
Thank you for you reply.I have read the thread that youhave linked to. From what I understand, it is blurring the whole image. That is not what I am looking for.I need to blur the edges of contents of the a scrollview, it does not matter what part of the imaeg is displayed, i need to have blurred edges of the displayed parts of the image.I am trying to blur the edges between two scroll views...so if A is first scrollview and B is the second and they are displayed as AAAABBB, then i would like to have the AB in the middle to be blurred.I hope that my question is clearer now.Thank You!
Shumais Ul Haq
That's how you do blurring. So apply that knowledge on that edges :)
willcodejavaforfood
just crop the original image and paste it on top of the blurred one, and you have blurred edges
Gary
A: 

You can use CALayer.mask to set a "mask layer" to add transparent regions. Set this on the scroll view (e.g. #import <QuartzCore/CALayer.h> ... scrollView.layer.mask = whatever) to give the edges more transparency.

I can't remember if layer masks are automatically resized. They also perform particularly poorly on older (e.g. 3G) devices. It might do what you want, though.

tc.
Thank you. I will look into it, hopefully it can do what i need.Thanks once again!
Shumais Ul Haq
A: 

When i create a CALayer mask and add it to my scroll view then noting inthat scrollview is displayed. Here is the relevent code, what am i doing wrong??

CALayer* maskLayer = [CALayer layer]; 
maskLayer.frame = CGRectMake(0, 0, 200, 100); 
maskLayer.cornerRadius = 45;
 maskLayer.opacity = 0.5; 
scrollView1.layer.mask = maskLayer;

Thank You

Shumais

Shumais Ul Haq
Adding an answer doesn't flag the question as changed; commenting on my answer would work better. In this case, the layer is completely transparent, so anything it masks will be completely transparent; try something like `maskLayer.backgroundColor = [UIColor blackColor].CGColor`.
tc.