Mailing Lists: Apple Mailing Lists
Image of Mac OS face in stamp
Re: How to convert pict file into jpg/gif?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to convert pict file into jpg/gif?



you can not :-)

if mime is image/x-pict
QT should understand it

only problem could be that 512 empty header



On Mar 19, 2004, at 11:55 AM, x l wrote:

Thank you, it works!

Now i only have to make sure the inputstream that i
got from the transferable is a pict format that
Quicktime understands. How can i ensure the
inputstream (image/x-pict) be a quicktime pict format.



--- Dmitry Markman <email@hidden> wrote:
1. if you don't need java.awt.Image
converting code is fairly simple (with QTJava) THANK
YOU APPLE.

public static void saveAsJPEG(File inFile,File
outFile){
try{
Pict pict = Pict.fromFile(inFile);
GraphicsExporter gex = new
GraphicsExporter(QTUtils.toOSType("JPEG"));
gex.setInputPicture(pict);
QTFile qtf = new QTFile(outFile);
gex.setOutputFile(qtf);
gex.doExport();
}catch(Throwable t){}
}

so just call
saveAsJPEG(new File("test.pict"),new
File("test.jpg"));

2.if you do need java image do the following

try{
Pict pict = Pict.fromFile(new
File("test.pict"));
byte []pictbytes = pict.getBytes();
//check here 512 length 0 header
//if you have that header do nothing
//if you don't have that header you must add it:
byte []newpictbytes = new
byte[512+pictbytes.length];



System.arraycopy(pictbytes,0,newpictbytes,512,pictbytes.length);
QTHandle qt = new
QTHandle(newpictbytes);
GraphicsImporter gc = new
GraphicsImporter(QTUtils.toOSType("PICT"));
gc.setDataHandle(qt);
QDRect qdRect = gc.getNaturalBounds();

GraphicsImporterDrawer myDrawer = new
quicktime.app.view.GraphicsImporterDrawer(gc);
QTImageProducer qtProducer = new
QTImageProducer (myDrawer,
new
Dimension(qdRect.getWidth(),qdRect.getHeight()));
Image img =
Toolkit.getDefaultToolkit().createImage(qtProducer);

//YOU'RE ALL SET


}catch(Throwable t){
System.out.println("Picture Exception "+t);
}


On Mar 18, 2004, at 3:20 PM, x l wrote:

here is the attached file:

thx

--- Dmitry Markman <email@hidden> wrote:
send me that file, if you want
and I'll take a look

On Mar 18, 2004, at 1:05 PM, x l wrote:

thank you again for your quick reply. i tried
the
code, i have problem reading my pict file. this
pict
file is written when i drag and drop the file
from
Netscape to my app, i was able to open the file
using
Preview and Quicktime Player. However, when i
read
the file using Pict.fromFile(), i can't see the
Dimension from qdRect, they are 0 x 0. How can
i
ensure the pict file in proper format?

Thanks again.

Margaret Fung
--- Dmitry Markman <email@hidden> wrote:
Margaret, you don't have to look for 1.3.1 to
work
with qtjava

qtjava 6.1 works happily with 1.4.X (QT >= 6.4)


that code will work with 1.4.X
Pict p = ....
QTHandle qt = new QTHandle(p. getBytes());
GraphicsImporter gc = new
GraphicsImporter(QTUtils.toOSType("PICT"));
gc.setDataHandle(qtHandle);
QDRect qdRect = gc.getNaturalBounds();
quicktime.app.view.GraphicsImporterDrawer
myDrawer =
new
quicktime.app.view.GraphicsImporterDrawer (gc);
quicktime.app.view.QTImageProducer qtProducer =
new
quicktime.app.view.QTImageProducer (myDrawer,
new

Dimension(qdRect.getWidth(),qdRect.getHeight()));

//YOU CAN USE EXPORTER IF YOU WISH

Image javaImage =


Toolkit.getDefaultToolkit().createImage(qtProducer);

//create BufferedImage here
GraphicsEnvironment ge =


GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice gd =
ge.getDefaultScreenDevice();
GraphicsConfiguration gc =
gd.getDefaultConfiguration();
BufferedImage retValue = null;
BufferedImage bim =





gc.createCompatibleImage(qdRect.getWidth(),qdRect.getHeight());

try{
Graphics g2d = bim.createGraphics()
g2d.drawImage(javaImage,null,0,0);
g2d.dispose();
java.io.FileOutputStream fos = new
java.io.FileOutputStream(<yourname here>);


javax.imageio.ImageIO.write(bim,"png",fos);//check
out that command
you can convert it to jpeg/tiff for sure I'm
not
sure about gif
/*
possible values are
jpeg
tiff
gif
png
JPG
jpg
JPEG

use
javax.imageio.ImageIO.getReaderFormatNames()
to
find out what types
javax.imageio.ImageIO.write does support
*/
fos.close();
}catch(Throwable t){
System.out.println("TEST THROWABLE "+t);
}


On Mar 13, 2004, at 12:13 PM, x l wrote:

Thanks for the reply.

My Mac OS has 1.4.2 installed. Where can i
find
the
jdk 1.3.1? so that i can run the QTJava
correctly? I
tried on apple site, and no luck. My
application
needs to run on both window and mac. so i
would
like
to use QTJava.

Thanks
Margaret



Thanks for the reply.

My application needs to do multi-platform.
Where
--- Dmitry Markman <email@hidden> wrote:
well, Margaret

=== message truncated ===


__________________________________
Do you Yahoo!?
Yahoo! Mail - More reliable, more storage, less spam
http://mail.yahoo.com
_______________________________________________
java-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/java-dev
Do not post admin requests to the list. They will be ignored.


Dmitry Markman
_______________________________________________
java-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/java-dev
Do not post admin requests to the list. They will be ignored.


References: 
 >Re: How to convert pict file into jpg/gif? (From: x l <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2011 Apple Inc. All rights reserved.