Project Home
Project Home
Documents
Documents
Wiki
Wiki
Discussion Forums
Discussions
Project Information
Project Info
Forum Topic - How to show a PNG image with transparent background: (4 Items)
   
How to show a PNG image with transparent background  
I have a PNG image. I modify the background of image to transparency in the Photoshop. I write the code like this:

    if (img.flags & IMG_TRANSPARENCY) {
            /* we can handle transparency in GF using chroma */
            gf_chroma_t        chroma;
            memset(&chroma, 0, sizeof chroma);
            chroma.mode = GF_CHROMA_OP_SRC_MATCH | GF_CHROMA_OP_NO_DRAW;
            if (img.format & IMG_FMT_PALETTE) {
                    chroma.color0 = img.palette[img.transparency.index];
            } else if (IMG_FMT_BPP(img.format) < 24) {
                    chroma.color0 = img.transparency.rgb16;
            } else {
                    chroma.color0 = img.transparency.rgb32;
            }
            gf_context_set_chroma(*p_context, &chroma);
    }
    if (img.format & IMG_FMT_ALPHA) {
            gf_alpha_t        alpha;
            memset(&alpha, 0, sizeof alpha);
            alpha.mode = GF_ALPHA_M1_SRC_PIXEL_ALPHA | GF_BLEND_SRC_M1 |
                GF_BLEND_DST_1mM1;
            gf_context_set_alpha(*p_context, &alpha);
    }
    // blit the image onto a target surface
    gf_draw_blit2(*p_context, *p_surface, NULL, 0, 0, img.w - 1, img.h - 1, 0, 0);

I found   (img.flags & IMG_TRANSPARENCY) this branch always nagative. But my Image has transparent background. How shold
 I do? 
RE: How to show a PNG image with transparent background  
What kind of PNG, 32-bit?

-----Original Message-----
From: Di Jin [mailto:community-noreply@qnx.com] 
Sent: May-03-13 4:47 AM
To: advanced-graphics
Subject: How to show a PNG image with transparent background

I have a PNG image. I modify the background of image to transparency in the Photoshop. I write the code like this:

    if (img.flags & IMG_TRANSPARENCY) {
            /* we can handle transparency in GF using chroma */
            gf_chroma_t        chroma;
            memset(&chroma, 0, sizeof chroma);
            chroma.mode = GF_CHROMA_OP_SRC_MATCH | GF_CHROMA_OP_NO_DRAW;
            if (img.format & IMG_FMT_PALETTE) {
                    chroma.color0 = img.palette[img.transparency.index];
            } else if (IMG_FMT_BPP(img.format) < 24) {
                    chroma.color0 = img.transparency.rgb16;
            } else {
                    chroma.color0 = img.transparency.rgb32;
            }
            gf_context_set_chroma(*p_context, &chroma);
    }
    if (img.format & IMG_FMT_ALPHA) {
            gf_alpha_t        alpha;
            memset(&alpha, 0, sizeof alpha);
            alpha.mode = GF_ALPHA_M1_SRC_PIXEL_ALPHA | GF_BLEND_SRC_M1 |
                GF_BLEND_DST_1mM1;
            gf_context_set_alpha(*p_context, &alpha);
    }
    // blit the image onto a target surface
    gf_draw_blit2(*p_context, *p_surface, NULL, 0, 0, img.w - 1, img.h - 1, 0, 0);

I found   (img.flags & IMG_TRANSPARENCY) this branch always nagative. But my Image has transparent background. How shold
 I do? 



_______________________________________________

Advanced Graphics
http://community.qnx.com/sf/go/post101108
To cancel your subscription to this discussion, please e-mail advanced-graphics-unsubscribe@community.qnx.com
答复: How to show a PNG image with transparent background  
Dear,Sir.

Please check the attaching file. 
I generate it by Fireworks.

 

Thanks and Best Regards!

*******************************************

金狄

天元鼎正电子科技(北京)有限公司

北京市海淀区上地七街1号汇众大厦106

邮编:100085

电话:010-62970815

手机:18601122606

*******************************************

 


-----邮件原件-----
发件人: Derek Leach [mailto:community-noreply@qnx.com] 
发送时间: 2013年5月3日 21:27
收件人: advanced-graphics
主题: RE: How to show a PNG image with transparent background

What kind of PNG, 32-bit?

-----Original Message-----
From: Di Jin [mailto:community-noreply@qnx.com]
Sent: May-03-13 4:47 AM
To: advanced-graphics
Subject: How to show a PNG image with transparent background

I have a PNG image. I modify the background of image to transparency in the
Photoshop. I write the code like this:

    if (img.flags & IMG_TRANSPARENCY) {
            /* we can handle transparency in GF using chroma */
            gf_chroma_t        chroma;
            memset(&chroma, 0, sizeof chroma);
            chroma.mode = GF_CHROMA_OP_SRC_MATCH | GF_CHROMA_OP_NO_DRAW;
            if (img.format & IMG_FMT_PALETTE) {
                    chroma.color0 = img.palette[img.transparency.index];
            } else if (IMG_FMT_BPP(img.format) < 24) {
                    chroma.color0 = img.transparency.rgb16;
            } else {
                    chroma.color0 = img.transparency.rgb32;
            }
            gf_context_set_chroma(*p_context, &chroma);
    }
    if (img.format & IMG_FMT_ALPHA) {
            gf_alpha_t        alpha;
            memset(&alpha, 0, sizeof alpha);
            alpha.mode = GF_ALPHA_M1_SRC_PIXEL_ALPHA | GF_BLEND_SRC_M1 |
                GF_BLEND_DST_1mM1;
            gf_context_set_alpha(*p_context, &alpha);
    }
    // blit the image onto a target surface
    gf_draw_blit2(*p_context, *p_surface, NULL, 0, 0, img.w - 1, img.h - 1,
0, 0);

I found   (img.flags & IMG_TRANSPARENCY) this branch always nagative. But my
Image has transparent background. How shold I do? 



_______________________________________________

Advanced Graphics
http://community.qnx.com/sf/go/post101108
To cancel your subscription to this discussion, please e-mail
advanced-graphics-unsubscribe@community.qnx.com




_______________________________________________

Advanced Graphics
http://community.qnx.com/sf/go/post101114
To cancel your subscription to this discussion, please e-mail
advanced-graphics-unsubscribe@community.qnx.com

Attachment: Image dash_left_light.png 3.11 KB
答复: How to show a PNG image with transparent background  
 
Dear Sir.

I found my PNG file is a 32bit PNG, and then I change it to 8bit and 24bit,
but it still can not be transparented.


 

Thanks and Best Regards!

*******************************************

金狄

天元鼎正电子科技(北京)有限公司

北京市海淀区上地七街1号汇众大厦106

邮编:100085

电话:010-62970815

手机:18601122606

*******************************************

 


-----邮件原件-----
发件人: Derek Leach [mailto:community-noreply@qnx.com] 
发送时间: 2013年5月3日 21:27
收件人: advanced-graphics
主题: RE: How to show a PNG image with transparent background

What kind of PNG, 32-bit?

-----Original Message-----
From: Di Jin [mailto:community-noreply@qnx.com]
Sent: May-03-13 4:47 AM
To: advanced-graphics
Subject: How to show a PNG image with transparent background

I have a PNG image. I modify the background of image to transparency in the
Photoshop. I write the code like this:

    if (img.flags & IMG_TRANSPARENCY) {
            /* we can handle transparency in GF using chroma */
            gf_chroma_t        chroma;
            memset(&chroma, 0, sizeof chroma);
            chroma.mode = GF_CHROMA_OP_SRC_MATCH | GF_CHROMA_OP_NO_DRAW;
            if (img.format & IMG_FMT_PALETTE) {
                    chroma.color0 = img.palette[img.transparency.index];
            } else if (IMG_FMT_BPP(img.format) < 24) {
                    chroma.color0 = img.transparency.rgb16;
            } else {
                    chroma.color0 = img.transparency.rgb32;
            }
            gf_context_set_chroma(*p_context, &chroma);
    }
    if (img.format & IMG_FMT_ALPHA) {
            gf_alpha_t        alpha;
            memset(&alpha, 0, sizeof alpha);
            alpha.mode = GF_ALPHA_M1_SRC_PIXEL_ALPHA | GF_BLEND_SRC_M1 |
                GF_BLEND_DST_1mM1;
            gf_context_set_alpha(*p_context, &alpha);
    }
    // blit the image onto a target surface
    gf_draw_blit2(*p_context, *p_surface, NULL, 0, 0, img.w - 1, img.h - 1,
0, 0);

I found   (img.flags & IMG_TRANSPARENCY) this branch always nagative. But my
Image has transparent background. How shold I do? 



_______________________________________________

Advanced Graphics
http://community.qnx.com/sf/go/post101108
To cancel your subscription to this discussion, please e-mail
advanced-graphics-unsubscribe@community.qnx.com




_______________________________________________

Advanced Graphics
http://community.qnx.com/sf/go/post101114
To cancel your subscription to this discussion, please e-mail
advanced-graphics-unsubscribe@community.qnx.com