LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-22-2011, 05:41 AM   #1
kalleanka
Member
 
Registered: Aug 2003
Location: Mallorca, Spain
Distribution: xubuntu
Posts: 551

Rep: Reputation: 38
PNG - scale - window background in xlib


Hi,

i cant find an easy way to load a png as a background in a xwindow (ths is to make a simple icon). Its easy in gtk but i do not want a huge lib for it. I looked at libpng and cairo but i cant figure out how to do it. What i want to do is something like this:


a_type *my_image = load_png_from_file(image.png);

scale_image(my_image, sx, sy);

// could be ximage etc insteed of pixmap
pix = a_type_2_pixmap(my_image);

//combine mask if needed

xsetwindowbackgroundpixmap(disp, win, pix) ;




any tips or idees!!
 
Old 10-22-2011, 06:39 AM   #2
kalleanka
Member
 
Registered: Aug 2003
Location: Mallorca, Spain
Distribution: xubuntu
Posts: 551

Original Poster
Rep: Reputation: 38
I found this list http://libpng.org/pub/png/pngaptk.html with libs for PNG.
 
Old 10-24-2011, 02:27 PM   #3
kalleanka
Member
 
Registered: Aug 2003
Location: Mallorca, Spain
Distribution: xubuntu
Posts: 551

Original Poster
Rep: Reputation: 38
ok i found imlib2 and wrote a test program. Now i need to fix the shape-mask to be transparent (so only the icon is showed). In Xlib I use Xshapecombinemask(). How is it done with imlib2? Any idees?

test:

Code:
#include <X11/Xlib.h>
#include <Imlib2.h>
#include <stdio.h>

Display *disp;
Window   win;
Visual  *vis;
Colormap cm;
int      depth;

int main(int argc, char **argv)
{
    XEvent ev;
    Imlib_Image image;
    Pixmap pix, mask;
    int w, h;
    
    disp  = XOpenDisplay(NULL);
    vis   = DefaultVisual(disp, DefaultScreen(disp));
    depth = DefaultDepth(disp, DefaultScreen(disp));
    cm    = DefaultColormap(disp, DefaultScreen(disp));
   
    win = XCreateSimpleWindow(disp, DefaultRootWindow(disp), 0, 0, 600, 600, 0, 0, 0);
   
  // XSelectInput(disp, win, ButtonPressMask | ButtonReleaseMask | PointerMotionMask | ExposureMask);
   
    XMapWindow(disp, win);
    XSync(disp, False);

    imlib_context_set_dither(1);
    imlib_context_set_display(disp);
    imlib_context_set_visual(vis);

    image = imlib_load_image("./bg.png");
    imlib_context_set_image(image);

    pix = XCreatePixmap(disp, win, 600, 600, depth);
    imlib_context_set_drawable(pix);   
    imlib_render_image_on_drawable_at_size(50, 50, 500, 500);

    XSetWindowBackgroundPixmap(disp, win, pix);
    XClearWindow(disp, win);

    while (1)
    {
         XNextEvent(disp, &ev);
         switch (ev.type)
         {
               case ButtonPress:
                  break;
               default:
                  break;
         }
    }
    return (0);
}
 
Old 10-25-2011, 07:38 AM   #4
kalleanka
Member
 
Registered: Aug 2003
Location: Mallorca, Spain
Distribution: xubuntu
Posts: 551

Original Poster
Rep: Reputation: 38
so im just going to fill the background with a color(same as mother). Its good enought for me.

like this:
gc = XCreateGC(dpy, pix, 0, &xgcv);
XSetForeground(dpy, gc, my_color);
XFillRectangle(dpy, pix, gc, 0, 0, w, h);
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: SCALE 8x Update: Jobs@SCALE (not Steve), T-shirts, SCALE Uni and UpSCALE talks LXer Syndicated Linux News 0 02-13-2010 01:10 PM
Why can't I get all of the Window Attributes using Xlib? billmanhillman Programming 3 11-09-2009 08:14 AM
Can't get Xlib window to display tron_thomas Programming 10 03-14-2009 02:24 PM
Seeking PNG viewer to See Background Apps through Alpha Channels bryankaplan Linux - Desktop 5 02-02-2007 03:36 PM
Error loading the default background.png oneforjb Red Hat 3 09-08-2006 08:45 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:24 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration