|
|
Home » U++ Library support » U++ Library : Other (not classified elsewhere) » StreamRasterEncoder puzzle
StreamRasterEncoder puzzle [message #15282] |
Tue, 15 April 2008 15:07  |
nixnixnix
Messages: 415 Registered: February 2007 Location: Kelowna, British Columbia
|
Senior Member |
|
|
So here's a puzzle for you:
The following piece of code writes all four image types but the resulting PNG and TIF files cannot be read by photoshop elements. They can be read by other less fussy types of image viewer. And here's the bit that's puzzling, when I use the same plugins elsewhere to write TIF and PNG, photoshop reads the resulting files just fine and even with this code, photoshop can read the resulting BMP and JPG files just fine. Can you find the error?
bool RasterLayer::SaveLegendAsImage(String path)
{
StreamRasterEncoder* pEnc=NULL;
if(path.Find(".jpg") || path.Find(".JPG"))
{
pEnc = new JPGEncoder(100); // top quality
}
else if(path.Find(".png") || path.Find(".PNG"))
{
pEnc = new PNGEncoder(); // default 32bpp
}
else if(path.Find(".tif") || path.Find(".TIF"))
{
pEnc = new TIFEncoder(); // default 24bpp
}
else if(path.Find(".bmp") || path.Find(".BMP"))
{
pEnc = new BMPEncoder(); // default 24bpp
}
else
{
return false;
}
ImageDraw id(2000,2000);
DrawLegend(id);
Image img = id.GetStraight();
pEnc->SaveFile(path,img);
delete pEnc;
return true;
}
Cheers,
Nick
EDIT: the following code (and you can see the different things I've tried commented out) has the same effect
bool RasterLayer::SaveLegendAsImage(String& path)
{
ImageDraw id(1500,2000);
DrawLegend(id);
// Image img = id.GetStraight();
// Image img(id);
ImageBuffer ib(id);
Image img(ib);
if(path.Find(".jpg") || path.Find(".JPG"))
{
JPGEncoder enc(100); // top quality
if(!enc.SaveFile(path,img))
{
PromptOK("problem saving legend");
return false;
}
}
else if(path.Find(".png") || path.Find(".PNG"))
{
PNGEncoder enc; // default 32bpp
if(!enc.SaveFile(path,img))
{
PromptOK("problem saving legend");
return false;
}
}
else if(path.Find(".tif") || path.Find(".TIF"))
{
TIFEncoder enc; // default 24bpp
if(!enc.SaveFile(path,img))
{
PromptOK("problem saving legend");
return false;
}
}
else if(path.Find(".bmp") || path.Find(".BMP"))
{
BMPEncoder enc; // default 24bpp
if(!enc.SaveFile(path,img))
{
PromptOK("problem saving legend");
return false;
}
}
else
{
return false;
}
return true;
}
[Updated on: Tue, 15 April 2008 17:39] Report message to a moderator
|
|
|
|
|
Re: StreamRasterEncoder puzzle [message #15311 is a reply to message #15282] |
Wed, 16 April 2008 09:33   |
mr_ped
Messages: 826 Registered: November 2005 Location: Czech Republic - Praha
|
Experienced Contributor |
|
|
Mirek: I was still missing the point after your comment, as I thought... if both finds return zero, it will lead only to pEnc be NULL, not to corrupted PNG file.
Then I finally realized (after looking into String.h) the JPEG is always stored no matter what input path does contain, because the Find does return either position OR -1 in case substring is not found. 
(nixnixnix: looks like I'm even dumber than you )
I got a bit surprised from the case sensitivity too, I'm checking the String.h and I see, that except defining stricmp and strnicmp even on POSIX/WINCE platform, there's no other support in U++ for those things.
It feels somewhat awkward to see thing like "if(path.Find(".jpg") || path.Find(".JPG"))" (and I don't mean the hidden bug this time, but the duplicity of "jpg" text).
[Updated on: Wed, 16 April 2008 09:36] Report message to a moderator
|
|
|
|
|
|
Goto Forum:
Current Time: Mon Apr 28 14:06:14 CEST 2025
Total time taken to generate the page: 0.00826 seconds
|
|
|