Welcome to MSDN Blogs Sign in | Join | Help

서진호의 윈도우 폰 이야기

The Story of Windows 7, Windows Phone, Windows Mobile, Windows Touch, Windows Embedded(CE/eXP/Robotics) Platform

Tags

News

  • 주의)이 웹로그에 표현된 관점/의견은 개인적인 의견이며 MS의 고용주의 관점/의견을 대변하는 것은 아닙니다. 또한 이 게시자료는 어떠한 보증도 없이“있는 그대로(AS IS)” 제공되며 또한 여러분에게 아무런 권리도 부여하지 않습니다.
윈도우 모바일 6.5(1) – 윈도우 모바일 6.5의 티타늄 스타일을 개발하자!!

지난번 약속대로 오늘부터 윈도우 모바일 애플리케이션 개발자들을 위한 시리즈로 연재를 시작해 보겠습니다. 그 동안 손이 근질근질해서 참는 데 혼났습니다.

첫번째로 나도 윈도우 모바일 6.5에서 적용된 티타늄 스타일 애플리케이션을 개발할 수 있다!! 입니다. 이 티타늄 스타일은 Zune에서 처음 사용되었습니다. 사용해 보시면 아시겠지만 단순하면서 고급스러운 모던 이미지를 창출할 수 있습니다.

Zune01

티타늄(Titanium) 스타일은 내부적으로 DirectDraw 기술과 알파 블렌딩(Alpha Blending) 이라는 기술을 통해 구현되어 있습니다. “Creating a Compelling UI for Windows Mobile and the Microsoft .NET Compact Framework” 라는 제목으로 MSDN 기사에 잘 설명되어 있는데, 여기에서 가장 핵심적인 부분은 엔진 부분을 담당하고 있는 Platform API  폴더의 GraphicsExtension.cs 파일의 DrawAlPha 메서드 입니다. 아래의 코드 조각을 보시면 BlendFunction 구조체를 이용하여 이미지를 투명화 처리하고 백그라운드 이미지와 중첩되는 부분을 알파 채널을 이용해서 제거 시켜줍니다.

Code Snippet
  1. /// <summary>
  2.         ///  Draws an image with transparency
  3.         /// </summary>
  4.         /// <param name="gx">Graphics to drawn on.</param>
  5.         /// <param name="image">Image to draw.</param>
  6.         /// <param name="transparency">Transparency constant</param>
  7.         /// <param name="x">X location</param>
  8.         /// <param name="y">Y location</param>
  9.         public static void DrawAlpha(this Graphics gx, Bitmap image, byte transparency, int x, int y)
  10.         {
  11.             using (Graphics gxSrc = Graphics.FromImage(image))
  12.             {
  13.                 IntPtr hdcDst = gx.GetHdc();
  14.                 IntPtr hdcSrc = gxSrc.GetHdc();
  15.                 BlendFunction blendFunction = new BlendFunction(); // Create BlendFunction Class
  16.                 blendFunction.BlendOp = (byte)BlendOperation.AC_SRC_OVER;   // Only supported blend operation
  17.                 blendFunction.BlendFlags = (byte)BlendFlags.Zero;           // Documentation says put 0 here
  18.                 blendFunction.SourceConstantAlpha = transparency;           // Constant alpha factor
  19.                 blendFunction.AlphaFormat = (byte)0;                        // Don't look for per pixel alpha
  20.                 PlatformAPIs.AlphaBlend(hdcDst, x, y, image.Width, image.Height,
  21.                                hdcSrc, 0, 0, image.Width, image.Height, blendFunction);
  22.                 gx.ReleaseHdc(hdcDst);                                      // Required cleanup to GetHdc()
  23.                 gxSrc.ReleaseHdc(hdcSrc);                                   // Required cleanup to GetHdc()
  24.             }
  25.         \

또한 사용자의 포커스를 위해 윈도우의 구석(Edge)를 부드럽게 처리하게 위해 FillGradientRectagle 메서드를 이용하여 컬러들을 처리해 줍니다.

Code Snippet
  1. /// <summary>
  2.         /// Fills the rectagle with gradient colors
  3.         /// </summary>
  4.         /// <param name="gx">Destination graphics</param>
  5.         /// <param name="rc">Desctination rectangle</param>
  6.         /// <param name="startColorValue">Starting color for gradient</param>
  7.         /// <param name="endColorValue">End color for gradient</param>
  8.         /// <param name="fillDirection">The direction of the gradient</param>
  9.         public static void FillGradientRectangle(this Graphics gx, Rectangle rc, Color startColorValue, Color endColorValue, FillDirection fillDirection)
  10.         {          
  11.             GradientFill.Fill(
  12.               gx,
  13.               rc,
  14.               startColorValue,
  15.               endColorValue,
  16.               fillDirection);            
  17.         \
그리고 나서, .NET CF 에서 Form 을 하나 디자인 한 다음 Form_Paint 이벤트 핸들링 처리에서 알파 채널을 이용한 색칠 또는 이미지 처리를 해주면 Zune에서 적용된 티타늄 스타일처럼 여러분들의 애플리케이션을 직접 알파 블렌딩 효과를 이용할 수 있습니다.

Code Snippet
  1. protected override void OnPaint(PaintEventArgs e)
  2.         {
  3.             // Draw a background first
  4.             this.offGx.Clear(this.BackColor);
  5.             if (this.backgroundImage != null)
  6.             {
  7.                 this.offGx.DrawImage(this.backgroundImage, 0, 0);
  8.             }          
  9.             // Pass the graphics to the canvas to render
  10.             if (this.canvas != null)
  11.             {
  12.                 this.canvas.Render(offGx);
  13.             }
  14.             // Blit the offscreen bitmap
  15.             e.Graphics.DrawImage(offBitmap, 0, 0);          
  16.         \

관련된 상세 소스는 다음과 같이 공유해 드리오니 적용해 보시기 바랍니다. 참고로 이 소스 모두 윈도우 모바일 6.1 과 윈도우 모바일 6.5 모두 사용 가능합니다.

Comments

No Comments

Leave a Comment

(required) 

(required) 

(optional)

(required) 

  
Enter Code Here: Required

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Page view tracker