Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / Perl / Tk / July 2008



Tip: Looking for answers? Try searching our database.

Problem reading "png", 'jpg" images with Tk::Photo

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Sean - 24 Jun 2008 07:20 GMT
Hi,

I have been trying to read ".png" & ".jpg" image files using "Tk::Photo".
The code works fine if I use ".xpm" or ".gif".
===================
perl -v
This is perl, v5.8.8 built for MSWin32-x86-multi-thread
(with 18 registered patches, see perl -V for more detail)

Copyright 1987-2007, Larry Wall

Binary build 822 [280952] provided by ActiveState http://www.ActiveState.com
Built Jul 31 2007 19:34:48
==============================
Here is my code

use         Tk;
use     warnings;
use     strict;
my $mw = new MainWindow;
my $tile = $mw->Photo( -format => 'png', -file=>'Back.png');
$mw->Icon(-image => $tile);
MainLoop;
====================================
Here is what I get when I run it.

--> perl -w my_test.pl
@ 535 not utf8
SV = PV(0x241db5c) at 0x24337c4
 REFCNT = 1
 FLAGS = (POK,pPOK,UTF8)
 PV = 0x243b03c "couldn't recognize data in image file
\"8\333A\2\1\""\0Malformed UTF-8 character (
unexpected non-continuation byte 0x41, immediately after start byte 0xdb) in
subroutine entry at C:/
PRG/Perl/lib/Tk/Image.pm line 21.
[UTF8 "couldn't recognize data in image file "8\x{0}\x{2}\x{1}""]
 CUR = 45
 LEN = 48
SV = PVMG(0x1db627c) at 0x24337c4
 REFCNT = 1
 FLAGS = (SMG,POK,pPOK,UTF8)
 IV = 0
 NV = 0
 PV = 0x243b03c "couldn't recognize data in image file
\"8\333A\2\1\""\0Malformed UTF-8 character (
unexpected non-continuation byte 0x41, immediately after start byte 0xdb) in
subroutine entry at C:/
PRG/Perl/lib/Tk/Image.pm line 21.
[UTF8 "couldn't recognize data in image file "8\x{0}\x{2}\x{1}""]
 CUR = 45
 LEN = 48
 MAGIC = 0x243b15c
   MG_VIRTUAL = &PL_vtbl_utf8
   MG_TYPE = PERL_MAGIC_utf8(w)
   MG_LEN = 44
couldn't recognize data in image file "8?A" at C:/PRG/Perl/lib/Tk/Image.pm
line 21.
=================================================

Regards,

-Sean
Jack D - 24 Jun 2008 07:31 GMT
> Hi,
>
[quoted text clipped - 21 lines]
> MainLoop;
> ====================================
[snip]
> couldn't recognize data in image file "8?A" at
> C:/PRG/Perl/lib/Tk/Image.pm line 21.
> =================================================

JPEGs and PNGs have their own loaders.

You need to add....

use Tk::PNG; #and/or
use Tk::JPEG;

To your program

Jack
Lee - 03 Jul 2008 20:37 GMT
> > Hi,
>
[quoted text clipped - 34 lines]
>
> To your program

I had the same error, and added the line you suggest, but now get:

 Fail to create pixmap with Tk_GetPixmap in ImgPhotoInstanceSetSize.

 This application has requested the Runtime to terminate it in an
unusual way.
 Please contact the application's support team for more information.

To avoid posting a load of source, has anyone else seen this?

Thanks
Lee
zentara - 04 Jul 2008 12:09 GMT
>> "Sean" <imfeaw5...@pacbell.net> wrote in message
>>
>> > I have been trying to read ".png" & ".jpg" image files using "Tk::Photo".
>> > The code works fine if I use ".xpm" or ".gif".

>> > Here is my code
>>
[quoted text clipped - 21 lines]
>
>I had the same error, and added the line you suggest, but now get:

>To avoid posting a load of source, has anyone else seen this?
>
>Thanks
>Lee

I'm pretty sure your problem is that the Icon method only accepts
a gif, or bmp; NOT png nor jpg.

#!/usr/bin/perl
use Tk;

my $mw = tkinit;

my $image = 'z-icon.gif';    # 32x32 GIF or BMP

my $icon = $mw->Photo(-file => $image);

$mw->idletasks;        # this line is crucial

$mw->iconimage($icon);
MainLoop;
__END__

zentara
Signature

I'm not really a human, but I play one on earth.
http://zentara.net/CandyGram_for_Mongo.html

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.