Jump to content

Codelab help needed


Recommended Posts

So, anyways, I'm trying to make a gradient from 0% alpha to 100% alpha and allow my self to choose the size of the gradient and the distance from the edge of the photo/selection. In it's current state, I can get it to go from 195 alpha to 255, which isn't what I want :(.

Thank you for all your help! :D

#region UICode
int Amount1=60;	//[0,255]Length
int Amount2=50;	//[0,255]Distance from Edge
#endregion

void Render(Surface dst, Surface src, Rectangle rect)
{
   // Delete any of these lines you don't need
   Rectangle selection = this.EnvironmentParameters.GetSelection(src.Bounds).GetBoundsInt();
   //long CenterX = (long)(((selection.Right - selection.Left) / 2)+selection.Left);
   long temp = 0;
   long LeftX = (long)(selection.Left + Amount1);
   long LeftMath, RightMath;
   long RightX = (long)(((selection.Right - selection.Left))+selection.Left - Amount1);
   //long CenterY = (long)(((selection.Bottom - selection.Top) / 2)+selection.Top);
   ColorBgra PrimaryColor = (ColorBgra)EnvironmentParameters.PrimaryColor;

   ColorBgra CurrentPixel;
   for(int y = rect.Top; y < rect.Bottom; y++)
   {
       for (int x = rect.Left; x < rect.Right; x++)
       {
           CurrentPixel = src[x,y];
           // TODO: Add pixel processing code here
           if ((x <= LeftX))
           {
               temp = x;
               LeftMath = temp / LeftX;
           // Access RGBA values this way, for example:
               CurrentPixel.R = (byte)CurrentPixel.R;
               CurrentPixel.G = (byte)CurrentPixel.G;
               CurrentPixel.B = (byte)CurrentPixel.B;
               //temp = temp-LeftX-LeftMath;
               //temp=x;
               temp=LeftX-temp-LeftMath;
               if(temp>255)temp=255;else if(temp<0)temp=100;
               CurrentPixel.A = (byte)(-temp);
           }
           else if ((x >= RightX))
           {
               RightMath = x / RightX;
           // Access RGBA values this way, for example:
               CurrentPixel.R = (byte)CurrentPixel.R;
               CurrentPixel.G = (byte)CurrentPixel.G;
               CurrentPixel.B = (byte)CurrentPixel.B;
               temp = x-RightX+RightMath;
               CurrentPixel.A = (byte)(temp*255);
           }
           dst[x,y] = CurrentPixel;
       }
   }
}

Link to comment
Share on other sites

  • 2 weeks later...

Didn't solve the problem you asked for but if you change

if(temp>255)temp=255;else if(temp<0)temp=100;

to

if(temp>255)temp=255;else if(temp<0)temp=1;

It removes that solid line going down each side.

I'm a little confused by "temp" what exactly is it doing?

I'm new at Codelab, and don't have much C# experience, but enough to know basic coding

I'm trying to learn the ropes really.

SamusSig-1.png
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...