From BufferedImage to faster Image...
Hello all.
I have to use JAI, Java2D, & ImageIO to read a TIFF and convert it into a transparent PNG. It results in a BufferedImage, of course. However, I noticed that the BufferedImage does not perform as quickly as the Image that can be created by the Toolkit (or obtained from the ImageIcon). This is true at least for Windows. For example, on Windows, the image is an instance of sun.awt.windows.WImage. However I have to save the image and reload it in order to get this other image
My question is this: Is there any way to directly convert a BufferedImage to type WImage, or to whatever native Image type exists on a particular platform. Does Java provide such a mechanism? Does anyone know of a way to do this (w/o having to write and re-read the image)?
Thank you in advance for your input.
GraphicsConfiguration.getCompatibleImage() gives you this kind of image. Use something like
Image originalImage = // load your image here
BufferedImage bI = GraphicsConfiguration.getCompatibleImage();
Graphics g = bI.getGraphics();
g.draw(0,0,originalImage,null); // draw old image into new bI
not sure about the exact method signatures, just what I remember.
Similar Messages
-
BufferedImage convert to Image
Is there anyway to convert a BufferedImage into an Image. I've seen the other way around but not this way.
Any help would be greatly appreciated.thank you.
See, I've got this method (below), that actually creates this image for me.
private static BufferedImage loadImage(final URL url) throws Exception{ //IOException {
BufferedImage image;
// Load the image through Image I/O
image = ImageIO.read(url);
//image = imageIO.read(url);
// Check that the image was loaded and that we can get a GC
if (image != null && !GraphicsEnvironment.isHeadless()) {
final GraphicsConfiguration gc = GraphicsEnvironment
.getLocalGraphicsEnvironment()
.getDefaultScreenDevice()
.getDefaultConfiguration();
// This probably can't be null if it's not headless
// Not sure though so check anyway
if (gc != null) {
// Attempt to create compatible image with same transparency
final BufferedImage img = gc.createCompatibleImage(
image.getWidth(), image.getHeight(),
image.getTransparency());
// Check that img was created and isn't the same type
// If it's the same type we don't need to convert obviously
if (img != null && image.getType() != img.getType()) {
// Use ColorConvertOp to convert the rasters from one
// color space to the other
// This is faster than using Graphics to draw on the new
// image in many cases, sometimes 100x faster
ColorConvertOp op = new ColorConvertOp(
image.getColorModel().getColorSpace(),
img.getColorModel().getColorSpace(), null);
op.filter(image, img);
image = img;
return image;
}But, I need to call this from within the same class:
URL base;
try{
base = new URL ("http://home.cogeco.ca/~someplace/folder");
catch(Exception n)
System.out.println("Can't construct URL, first time around.");
try{
ll = loadImage(base); // right exception after calling method???
catch(Exception n)
System.out.println("problems");
}For some reason, I can't figure out if I'm handling the exception properly. Any ideas why I'm getting the following error?
load: tetrisapp.PictureData.class can't be instantiated.
java.lang.InstantiationException: tetrisapp.PictureData
at java.lang.Class.newInstance0(Class.java:340)
at java.lang.Class.newInstance(Class.java:308)
at sun.applet.AppletPanel.createApplet(AppletPanel.java:778)
at sun.applet.AppletPanel.runLoader(AppletPanel.java:707)
at sun.applet.AppletPanel.run(AppletPanel.java:361)
at java.lang.Thread.run(Thread.java:619)Tell me if you need more code. I'm guessing that the error is coming from the improper handling of the exception.
Message was edited by:
ManRed
Message was edited by:
ManRed -
How to convert BufferedImage back to Image
I have an Image from ImageIcon and i want to cut it using BufferedImage.getSubImage(...) and now from BufferedImage i want to turn it to Image again so that i can put in ImageIcon.
Here is my code:
URL img = new URL(location);
ImageIcon imgIcon = new ImageIcon(img);
Image image = imgIcon.getImage();
//turn image into bufferedImage via graphic draw
BufferedImage bi = new BufferedImage(..);
Graphics g = bi.createGraphics();
g.drawImage(image,0,0,null);
bi.getSubImage(...);
// how to turn bi back to Image newImage
any ideas??More correctly, BufferedImage extends Image as Image is an abstract class and not an interface.
Shaun -
How to get RGB value from pixel of an image.
hi, i need a little help... Is there any EASY way to get RGB value from point of an image? I searched javadoc but i only found very complex getRGB method working only with regions, and saving data into arrays.
Is there any other way that can use for example image.getGraphics() (so, i mean to get RGB from point of Graphics object) ?
Btw.: If you know, how Sprite.collidesWith(Sprite s, Boolean pixellevel) is working (with pixellevel = true), please write me. It could solve my problem too.
ThanksIs there any other way that can use for example image.getGraphics() (so, i mean to get RGB from point of Graphics object) ?You can think of the graphics object like a pencil or paintbrush. Does a paintbrush know the color of the surface it is painting on? No.
Btw.: If you know, how Sprite.collidesWith(Sprite s, Boolean pixellevel) is working (with pixellevel = true), please write me. It could solve my problem too.Download the reference implementation from this site and see for yourself.
luck, db -
How do I stop Firefox from grabbing my saved images and coverting them to Firefox?
I am working on images in Dreamweaver and Adobe Photoshop, and when I try to save them, Firefox coverts them into Firefox images with a Firefox icon and then I can't edit them properly in Photoshop or Dreamweaver. How do I stop Firefox from grabbing my saved images? in English
I will try that, but it's pretty time consuming to have to check that for each of my images. I am a web designer and I work with a lot of images.
Is there any way to set that globally for all of my saved images? -
How can I delete ONLY the GPS coordinates from my Hi Res images WITHOUT "Save four Web" or Lightroom
Hello,
I take hi res pics of rare wildlife and plants with both my Camera's and iPhone's GPS deliberately ENABLED. Use the photos and their GPS coordinates to document and plot my sightings with dates on maps. CANNOT disclose those locations to others. I do want to keep the metadata in my pics to the very end.
Use Photohop Extended CS 6 MAC. Save files as hi res TIFF or PSD and sometimes e-mail/upload my pics to the web when I'm done.
I CANNOT use "Save for Web" to delete my metadata — I don't want the jpeg's lossy compression. Need to preserve color profiles.
Don't have Lightroom.
How do use Photoshop to remove ONLY the GPS coordinates from my hi res images EXIF data??? Want to keep other EXIF data.
Surely Adobe can provide this life-saving service?
ThanksYep, as others mentioned, just use Bridge and delete the entries there. You can select a whole batch of files and do them all at once.
-
Is there any way to prevent Aperture from Auto Cropping an image?
Is there any way to prevent Aperture from auto cropping an image? I use the "Do Not Crop" aspect ratio often and Aperture constantly picks cropping aspects for me, which is driving me crazy. Can I set "Do Not Crop" as the ratio I want on a more permanent basis anyhow? Thanks for the help.
ChrisThis is a current bug. Please report it via "Aperture→Send Aperture Feedback".
Just to clarify, the problem is not auto-cropping, the problem is the the crop tool aspect ratio is arbitrarily set (in my case, always to something close to the current crop aspect ratio). You can reset it (on a per-crop basis) to "Do not constrain".
It is very bothersome.
You might try trashing your prefs. Details on the Trouble-shooting page. I have had the bug return more than once.
Message was edited by: Kirby Krieger -- minor clarifications. -
Just upgraded to Creative Cloud from elements 9 where images are stored in Organizer. How do I bring them into Creative Cloud and should I download them to Lightroom, Bridge, or Photoshop itself? Any suggestions?
lawrencer72634146 a écrit:
Just upgraded to Creative Cloud from elements 9 where images are stored in Organizer. How do I bring them into Creative Cloud and should I download them to Lightroom, Bridge, or Photoshop itself? Any suggestions?
It's important to keep in mind that the picture files are NOT stored in the Organizer. They are not stored in Lightroom or Bridge either...
The organizer is based on a catalog which stores the pictures properties, mainly the location of the pictures on your drive(s). It's the same idea of catalogs in Lightroom, and the nice thing is that Lightroom can convert organizer catalogs to its own format. The most obvious way for you will be to use Lightroom.
Bridge is a file browser which is a different way than to use catalogs. -
How to stop the dock from showing all hidden images when hiding then showing applications
How to stop the dock from showing all hidden images when hiding then showing applications
It's not really something to snap a screen shot of. I believe it would need to be a video clip. For instance, when I am working on multiple images in Photoshop, I often need many images open at the same time, but I only have one image viewable and active. The hero image is active on screen while I hide the other images in the dock by hitting the yellow - button on the images. Then I "Hide" Photoshop to do something in the Finder. When I go back to Photoshop, every image that is hidden in the dock will pop open again in the active window, not just the image I was currently working on. I want these images to stay in the dock until I need them, no matter how many times I Hide the Show Photoshop.
-
How to stop Adobe Reader 9 from printing in mirror image on my Mac?
How can I stop Adobe 9 Reader from printing in mirror image on my Mac?
How can I stop Adobe 9 Reader from printing in mirror image on my Mac?
-
How to recovery the deleted files from hard disk like images,media files
How to recovery the deleted files from hard disk like images, media files by using c#.net
It's important to define deleted and recovery. You can recover file from the recycle bin using the Win API. Here's an
example in C/C++. You need to
pinvoke SHFileOperation. -
When entering the digits from an Anti Spam Image they are not accepted by the host web site why
In e-bay when required to enter the digits from an anti spam image, ebay rejects the entered digets.
This only occurs when using Firefox, Internet explorer works fine.
Any body know why?hi john, you probably have to go trough your list of addons once (in the firefox ''menu ≡ > addons > extensions'') and disable them one by one to find out which in particular might be causing the problem.
-
If you change the image mode of this image from 8-bit RGB image to Grayscale
mode while in PSCS – what will the new Pixel Count be?If you mean by Pixel count the number of pixels, this will not change. The image will have the same size thus the same number of pixels.
-
How to delete keywords from more than one image at once?
Is there any way to delete all the keywords from a selected group of images all at once?
I've selected a group of images, but when I delete the keywords, it only deletes them from the highlighted (targeted?) image and not from the other selected images. I've also tried syncing metadata and I get the same results.
Help would be appreciated.
AntonioInteresting bug I just found, I think.
When the Grid is up on the second monitor, only one images is affected by the deletion of the keywords. When I put the Grid mode back on the main screen, I was able to delete keywords from all the selected images.
Shouldn't it work the same no matter what screen the Grid mode is on? -
Why a function within a SELECT FROM DUAL is faster?
1)I have a SELECT with a function. Ex:
"SELECT DISTINCT function(...) FROM table"
2)I changed the SELECT and put the function inside a SUB-SELECT with FROM DUAL. Ex:
"SELECT DISTINCT (SELECT function(...) FROM DUAL) FROM table"
3)The second SELECT is faster than the first.
I discovered this problem on my tables and my functions. So I did a generic example for this forum with a common function and large table. My results:
Table has 2.196.058 records and the field is a VARCHAR2:
SELECT DISTINCT SUBSTR(field, 2) FROM Table -> Executed in 110 seconds
SELECT DISTINCT (SELECT SUBSTR(field, 2) FROM DUAL) FROM Table -> Executed in 39 seconds
Why "SELECT DISTINCT (SELECT function(...) FROM DUAL) FROM table" is faster than "SELECT DISTINCT function(...) FROM table"
thanks,
FernandoHi hoek,
I followed your informations and, sorry, I am more confused! I did an interesting example below.
1)I created a table:
CREATE TABLE T
name VARCHAR2(50)
); 2)I inserted 10 lines:
NAME
A
B
C
D
E
F
G
H
I
J 3)I created a function that returns the parameter concatenated with the current millisecond:
CREATE OR REPLACE FUNCTION f (param1 IN VARCHAR2) RETURN VARCHAR IS
BEGIN
return param1 || '-' || to_char(CURRENT_TIMESTAMP, 'FF');
END; 4)The query(A): SELECT f(name) AS col1, f(name) AS col2, f(name) AS col3 FROM t; gave me:
COL1 COL2 COL3
A-693786000 A-693887000 A-693941000
B-693989000 B-694017000 B-694043000
C-694071000 C-694097000 C-694124000
D-694153000 D-694180000 D-694206000
E-694235000 E-694261000 E-694287000
F-694316000 F-694341000 F-694367000
G-694396000 G-694422000 G-694448000
H-694477000 H-694503000 H-694529000
I-694557000 I-694583000 I-694609000
J-694638000 J-694664000 J-694690000If I repeat the SELECT, new values are generated.
4)The query(B): SELECT (SELECT f(name) FROM Dual) AS col1, (SELECT f(name) FROM Dual) AS col2, (SELECT f(name) FROM Dual) AS col3 FROM t; gave me:
COL1 COL2 COL3
A-253546000 A-253643000 A-253746000
B-253791000 B-253821000 B-253850000
C-253881000 C-253909000 C-253937000
D-253969000 D-253997000 D-254026000
E-254057000 E-254085000 E-254113000
F-254145000 F-254173000 F-254202000
G-254232000 G-254261000 G-254289000
H-254320000 H-254348000 H-254376000
I-254407000 I-254436000 I-254464000
J-254495000 J-254523000 J-254551000The result generated new values too.
5)I changed the function and I put the DETERMINISTIC clause:
CREATE OR REPLACE FUNCTION f (param1 IN VARCHAR2) RETURN VARCHAR DETERMINISTIC IS
BEGIN
return param1 || '-' || to_char(CURRENT_TIMESTAMP, 'FF');
END; 6)I repeated the queries(A) and (B) and the result has generated different values. Then, with the DETERMINISTIC clause, the result has not changed
7)I changed the function and I put the RESULT_CACHE clause:
CREATE OR REPLACE FUNCTION f (param1 IN VARCHAR2) RETURN VARCHAR RESULT_CACHE IS
BEGIN
return param1 || '-' || to_char(CURRENT_TIMESTAMP, 'FF');
END;8)I repeated the query(A) and now, the result was different:
COL1 COL2 COL3
A-381048000 A-381048000 A-381048000
B-381242000 B-381242000 B-381242000
C-381322000 C-381322000 C-381322000
D-381400000 D-381400000 D-381400000
E-381481000 E-381481000 E-381481000
F-381556000 F-381556000 F-381556000
G-381634000 G-381634000 G-381634000
H-381815000 H-381815000 H-381815000
I-381895000 I-381895000 I-381895000
J-381971000 J-381971000 J-381971000The line columns are equals and if I repeat the SELECT, all the result is the same too. The query(B) returned the same result like the query(A)! Now I see the cache in action!
After the tests, I concluded that the function in the subquery doesn't use cache and it is faster than the normal function. The mistery continues...
Maybe you are looking for
-
Whenever I have bookmarked a page, I got a dialog box where I could give the bookmark a title and choose the folder to save it in. Now when I click 'Bookmark this page, no box appears. The page is still saved in bookmarks but then I have to go into O
-
H/W monitor problems on P7N SLI
Hello Forumgoers, First of all I want to thank the gods that MSI has such a helpful support system like this. You guys rock. Second, here's my problem: Recently my h/w monitoring software has been giving me strange readings on my CPU. I use nVidia Sy
-
How to clear caches using lion
how to clear caches using lion
-
DBVERIFY || 0005 Error during processing
Hi, PFA, In CRP server, VerifyDB job is getting failed with error code 0005. Reason: BR0278E Command output of '/oracle/CRP/102_64/bin/dbv file=/oracle/CRP/sapdata1/crp_70/crp.data70 blocksize=8192': 12714110 : map : Permission Denied DBVERIFY: Relea
-
Realtime video stream on the cell Phone
Hi, I have to develop a prototype to show a cell phone handling a CCTV feed 1. I am trying to figure out how easy or difficult it isn The cell phone should be able to display real-time feed coming from a CCTV and provide the cell phone user the abili