GDI+ 에서 이미지 반투명 처리하기..

31437 
Created at 2006-09-29 01:53:09 
312   0   0   0  
GDI 에선 AlphaBlend 라는 함수로 가능하기는 하는데

찍을 부분의 이미지 색상과 혼합을 해야 제대로 구현이 됩니다

계산식이야 MSDN 에도 있고 여기 Q&A 에 검색해도 있습니다.

AlphaBlend 로 하다가 계산하는거 짜증나서

GDI+ 찾아 보니까 있더군여..

MSDN 에서 발췌했습니다.

여기 검색해봐도 없길래... 갖다 붙여 넣습니다... 참고하세요..

 

 
Using a Color Matrix to Set Alpha Values in Images

The Bitmap class (which inherits from the Image class) and the ImageAttributes class provide functionality for getting and setting pixel values. You can use the ImageAttributes class to modify the alpha values for an entire image, or you can call the SetPixel method of the Bitmap class to modify individual pixel values. For more information on setting individual pixel values, see Setting the Alpha Values of Individual Pixels.

The following example draws a wide black line and then displays an opaque image that covers part of that line.

Bitmap bitmap(L"Texture1.jpg");
Pen pen(Color(255, 0, 0, 0), 25);

// First draw a wide black line.
graphics.DrawLine(&pen, Point(10, 35), Point(200, 35));

// Now draw an image that covers part of the black line.
graphics.DrawImage(&bitmap,
   Rect(30, 0, bitmap.GetWidth(), bitmap.GetHeight()));

The following illustration shows the resulting image, which is drawn at (30, 0). Note that the wide black line doesn't show through the image.

The ImageAtributes class has many properties that you can use to modify images during rendering. In the following example, an ImageAttributes object is used to set all the alpha values to 80 percent of what they were. This is done by initializing a color matrix and setting the alpha scaling value in the matrix to 0.8. The address of the color matrix is passed to the SetColorMatrix method of the ImageAttributes object, and the address of the ImageAttributes object is passed to the DrawImage method of a Graphics object.

 

 

// 다음 코드가 반투명 효과를 일으키게하는 소스이며.. 주석과 같이 4행4열의 0.8값을 주의깊게 보십시요

// 이 값을 바꿔주면서 이미지를 확인해 보시면 잘 알수 있을겁니다...

// 그럼.. 참고하세요..

 

 

// Create a Bitmap object and load it with the texture image.
Bitmap bitmap(L"Texture1.jpg");
Pen pen(Color(255, 0, 0, 0), 25);

// Initialize the color matrix.
// Notice the value 0.8 in row 4, column 4.
ColorMatrix colorMatrix = {1.0f, 0.0f, 0.0f, 0.0f, 0.0f,
                           0.0f, 1.0f, 0.0f, 0.0f, 0.0f,
                           0.0f, 0.0f, 1.0f, 0.0f, 0.0f,
                           0.0f, 0.0f, 0.0f, 0.8f, 0.0f,
                           0.0f, 0.0f, 0.0f, 0.0f, 1.0f};

// Create an ImageAttributes object and set its color matrix.
ImageAttributes imageAtt;
imageAtt.SetColorMatrix(&colorMatrix, ColorMatrixFlagsDefault,
   ColorAdjustTypeBitmap);

// First draw a wide black line.
graphics.DrawLine(&pen, Point(10, 35), Point(200, 35));

// Now draw the semitransparent bitmap image.
INT iWidth = bitmap.GetWidth();
INT iHeight = bitmap.GetHeight();
graphics.DrawImage(
   &bitmap,
   Rect(30, 0, iWidth, iHeight),  // Destination rectangle
   0,                             // Source rectangle X
   0,                             // Source rectangle Y
   iWidth,                        // Source rectangle width
   iHeight,                       // Source rectangle height
   UnitPixel,
   &imageAtt);

During rendering, the alpha values in the bitmap are converted to 80 percent of what they were. This results in an image that is blended with the background. As the following illustration shows, the bitmap image looks transparent; you can see the solid black line through it.

Where the image is over the white portion of the background, the image has been blended with the color white. Where the image crosses the black line, the image is blended with the color black.

Tags: GDI+ MFC WIN32 윈도우즈 Share on Facebook Share on X

◀ PREVIOUS
자기자신 IP알아내기(로칼컴퓨터)
▶ NEXT
System Log-Off, Suspend, Reboot, Shutdown 시키기
  Comments 0
Login for comment
SIMILAR POSTS

자기자신 IP알아내기(로칼컴퓨터) (created at 2006-09-29)

System Log-Off, Suspend, Reboot, Shutdown 시키기 (created at 2006-09-29)

프로세스명으로 프로세스 죽이는 함수 (created at 2006-09-29)

빈폴더 찾아내기 (created at 2006-09-29)

ATL/ActiveX 에서 자바스크립트로 데이터(문자열) 보내기 (created at 2006-09-29)

wave 파일 mixing 하기. (웨이브 믹싱) (created at 2006-09-29)

File Attribute 바꾸는 방법 (created at 2006-09-29)

디렉토리 복사 루틴 (하부디렉토리까지 몽땅) (created at 2006-09-29)

디렉토리와 그 안에 있는 모든 파일 지우기 (created at 2006-09-29)

Create a standard windows shortcut file (created at 2006-09-29)

Starting an application as an icon in the system tray (created at 2006-09-29)

Extracting a Program's Version Information (created at 2006-09-29)

ShellExecute 실행 끝날때 까지 기다리기 (created at 2006-09-29)

DirectShow에서 비디오 출력 크기 조정해주기 (created at 2006-09-29)

공유폴더 찾아주기 (created at 2006-09-29)

로컬 IP 알아내기 (created at 2006-09-29)

스크린세이버 동작 못하게 막아주기 (created at 2006-09-29)

PC 셧다운 (shutdown) (created at 2006-09-29)

how to record keyboard & mouse event (created at 2006-09-29)

웹브라우져에 붙이기 위한 ActiveX 프로그래밍 방법 (created at 2006-09-29)

투명 윈도우 구현 방법 (created at 2006-09-29)

ActiveX를 Safe한 Component로 등록하는 방법 (created at 2006-09-29)

ActiveX의 등록 - Safe Code 넣어주기 (updated at 2023-12-17)

윈도우 찾아서 Top Most로 올려주기 (updated at 2023-12-17)

Application defined window call procedure (created at 2006-09-29)

Application Event써서 Keyboard 받아내기 (created at 2006-09-29)

Web Browser Control에서 Enter키 먹게 하기 (created at 2006-09-29)

String Find 알고리즘 (created at 2006-09-29)

HTTP Downloading Reference Source Code (created at 2006-09-29)

File Search Sample Code (created at 2006-09-29)

OTHER POSTS IN THE SAME CATEGORY

PC 셧다운 (shutdown) (created at 2006-09-29)

스크린세이버 동작 못하게 막아주기 (created at 2006-09-29)

로컬 IP 알아내기 (created at 2006-09-29)

공유폴더 찾아주기 (created at 2006-09-29)

DirectShow에서 비디오 출력 크기 조정해주기 (created at 2006-09-29)

ShellExecute 실행 끝날때 까지 기다리기 (created at 2006-09-29)

Extracting a Program's Version Information (created at 2006-09-29)

Starting an application as an icon in the system tray (created at 2006-09-29)

Create a standard windows shortcut file (created at 2006-09-29)

디렉토리와 그 안에 있는 모든 파일 지우기 (created at 2006-09-29)

디렉토리 복사 루틴 (하부디렉토리까지 몽땅) (created at 2006-09-29)

File Attribute 바꾸는 방법 (created at 2006-09-29)

wave 파일 mixing 하기. (웨이브 믹싱) (created at 2006-09-29)

ATL/ActiveX 에서 자바스크립트로 데이터(문자열) 보내기 (created at 2006-09-29)

System Log-Off, Suspend, Reboot, Shutdown 시키기 (created at 2006-09-29)

자기자신 IP알아내기(로칼컴퓨터) (created at 2006-09-29)

프로세스명으로 프로세스 죽이는 함수 (created at 2006-09-29)

빈폴더 찾아내기 (created at 2006-09-29)

IE 패치에 따른 object, embed, applet 대처 방안 (created at 2006-09-28)

Virtusertable (created at 2006-09-28)

웹서버 및 웹메일 설정 방법 (created at 2006-09-28)

음력-양력 변환기 (created at 2006-09-28)

어떤 파라메터가 넘어왔는지 알아내는 함수 (created at 2006-09-28)

PHP에서 메일 함수가 동작하지 않을때 (created at 2006-09-28)

웹페이지 긁어서 타이틀 뿌려주는 소스 (created at 2006-09-28)

PHP로 객체지향 프로그래밍 하는 방법 (created at 2006-09-28)

파일에서 한줄만 읽어다 return 해주는 소스 (created at 2006-09-28)

HTML 긁어오는 프로그램 소스 (created at 2006-09-28)

작업관리자에 프로그램 안뜨게 하기 (created at 2006-09-28)

파일 업로드 (file upload) 사이즈 늘리기 (created at 2006-09-28)

UPDATES

햄과 소세지가 우리 몸에 일으키는 부작용 (updated at 2024-04-27)

글루코사민 vs. 콘드로이친: 무엇이 더 나은 관절 건강 보조제일까? (created at 2024-04-22)

광주 5·18 민주화운동 알린 테리 앤더슨 前 AP 기자 (created at 2024-04-22)

콘드로이친의 염증 감소효과 (updated at 2024-04-22)

코사민 DS - 글루코사민+콘드로이친 복합물이 함유된 퇴행성 관절 건강보조제 (updated at 2024-04-22)

삼겹살 먹을때 환상조합 (created at 2024-04-22)

일본 여중생의 특이한 취향 (created at 2024-04-22)

우리가 먹는 약물이 바꿔버린 생태계 (created at 2024-04-21)

일본에서 그린 상상속의 사무직과 현실속의 사무직 (updated at 2024-04-21)

북한 미대생들이 그린 북한 최고존엄 김정은 (created at 2024-04-21)

입사 후 1년도 되지 않은 회사에서 구조조정에 의한 퇴직 불응에 따른 해고 처리시 대응 가능한 방법 (updated at 2024-04-20)

한고은님의 옛날 사진 (updated at 2024-04-20)

소녀대 - Bye Bye Girl (updated at 2024-04-13)

대한민국 날씨 근황 (created at 2024-04-13)

성일종 인재육성 강조하며 이토 히로부미 언급 - 인재 키운 선례? (updated at 2024-04-13)

일제강점기가 더 살기 좋았을지도 모른다는 조수연 국민의힘 후보 - 친일파? (updated at 2024-04-13)

Marshall Ha님의 샤오미 SU7 시승기 - 테슬라의 일론 머스크님이 긴장할만한 느낌 (updated at 2024-04-09)

윙크하는 귀염둥이 반려견들 (created at 2024-04-08)

달콤 살벌한 고백 (created at 2024-04-08)

북한 최정예 공수부대 훈련 모습 (updated at 2024-04-02)

맛있었던 친구 어머니의 주먹밥이 먹고 싶어요 (created at 2024-04-02)

자리 마음에 안든다고 6급 공무원 패는 농협 조합장 (created at 2024-03-26)

85세 딸 짜장면 사주는 102세 어머니 (created at 2024-03-26)

1990년대 감각파 도둑 (created at 2024-03-26)

치매에 걸린 69살의 브루스 윌리스가 전부인 데미무어를 보고 한 말 (updated at 2024-03-22)

경제는 대통령이 살리는 것이 아닙니다 라던 윤석열대통령 - 상황 안좋아지자 여러 전략을 펼쳤지만, 부작용 속출했던 2024년의 봄 (updated at 2024-03-13)

극빈의 생활을 하고 배운것이 없는 사람은 자유가 뭔지도 모를 뿐 아니라 왜 개인에게 필요한지에 대한 필요성을 못느낀다는 윤석열 대통령 (updated at 2024-03-08)

조선일보를 안본다는 사람들이 말하는 그 이유 - 천황폐하, 전두환 각하, 김일성 장군 만세? (created at 2024-03-07)

광폭타이어를 장착하면 성능이 좋아질거라는 착각 (updated at 2024-03-03)

면허시험장에서 면허갱신하면 하루만에 끝나나? (updated at 2024-03-03)