Poonam
image effects
1 Answer(s)      3 years and 8 months ago
Posted in : Java Beginners

View Answers

September 24, 2009 at 4:20 PM


Hi Friend,

We are providing you a code that will show you image crop effect:

import java.sql.*;
import java.awt.*;
import java.io.*;
import javax.swing.*;
import java.awt.image.*;
import java.awt.event.*;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.awt.image.CropImageFilter;
import java.awt.image.FilteredImageSource;

public class Upload extends JPanel {
BufferedImage image;
Image img;
JButton browse, crop;
File file = null;
public Upload() {


crop = new JButton("Crop Image");
this.add(crop);


crop.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
ImageIcon icon = new ImageIcon("C:\\image.jpg");
img = icon.getImage();
img = createImage(new FilteredImageSource(img.getSource(),new CropImageFilter(75, 70, 140, 150)));

try{
File f = new File("screen.jpg");
ImageIO.write( toBufferedImage(img), "jpg", f);
}
catch(Exception ex){}
}
});
}
public static BufferedImage toBufferedImage(Image image) {
if (image instanceof BufferedImage) {return (BufferedImage)image;}
image = new ImageIcon(image).getImage();
boolean hasAlpha = hasAlpha(image);

BufferedImage image1 = null;
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
try {
int transparency = Transparency.OPAQUE;
if (hasAlpha == true) {transparency = Transparency.BITMASK;}

GraphicsDevice gs = ge.getDefaultScreenDevice();
GraphicsConfiguration gc = gs.getDefaultConfiguration();
image1 = gc.createCompatibleImage(image.getWidth(null), image.getHeight(null), transparency);
}
catch (HeadlessException e) {}

if (image1 == null) {
int type = BufferedImage.TYPE_INT_RGB;
if (hasAlpha == true) {type = BufferedImage.TYPE_INT_ARGB;}
image1 = new BufferedImage(image.getWidth(null), image.getHeight(null), type);
}
Graphics g = image1.createGraphics();
g.drawImage(image, 0, 0, null);
g.dispose();

return image1;
}
public static boolean hasAlpha(Image image) {
if (image instanceof BufferedImage) {return ((BufferedImage)image).getColorModel().hasAlpha();}
PixelGrabber pg = new PixelGrabber(image, 0, 0, 1, 1, false);
try {pg.grabPixels();} catch (InterruptedException e) {}
return pg.getColorModel().hasAlpha();
}
public void paint(Graphics g) {
g.drawImage( image, 0, 0, null);
g.drawImage( img, 0, 0, null);
}
public static void main(String[] args) {
JFrame frame = new JFrame("Upload Demo");
JPanel panel = new Upload();
frame.getContentPane().add(panel);
frame.setSize(300, 100);
frame.setVisible(true);
}
}

For other effects,please visit the following link:
http://www.roseindia.net/java/example/java/swing/graphics2D/image-effect.shtml
http://www.roseindia.net/java/example/java/swing/graphics2D/other-image.shtml

Thanks









Related Pages:
image effects - Java Beginners
image effects  hey can u help me in loadin an image file... that will show you image crop effect: import java.sql.*; import java.awt.... java.awt.image.FilteredImageSource; public class Upload extends JPanel { BufferedImage image; Image img
Spark Effects in Flex4
one bitmap image to another. 4. Filter Effects: This effect applies...Spark Effects in Flex4: There are five categories of spark effects which are following: 1. Property Effects: These effects are used for change of one
Show Other Image Effects
Show Other Image Effects       This section illustrates you some other image effects To show image effects like sharpen, blur, show edge, reset ,etc, we have create
mouse over effects in css
mouse over effects in css  I have written a mouse over effect in CSS. But it is not working in HTML. Can any one suggest me? Thanks
Color Effect On Image
Image. We are providing you an example, where an image shows different color effects.... The ActionListener class is used to call those effects on the image. ... Color Effect On Image     
Show Image Effect
Show Image Effect       This section shows you image effects. To show Image effects, we have... toolkit. The method getImage() of class ToolKit returns an image
jQuery UI effects
jQuery UI effects       jQuery UI effects effects.core.js The jQuery UI effects depends heavily on this file  This file is utilizes
Describe the effects of a server failure on the application
Describe the effects of a server failure on the application Prev  Chapter 7. Validate, tune and troubleshoot... Describe the effects of a server failure on the application
image
image  how to add the image in servlet code
Image
Image  how to insert image in xsl without using xml. the image was displayed in pdf..Please help me
Image
Image  how to insert image in xsl without using xml. the image was displayed in pdf..Please help me
Image
Image  how to insert image in xsl without using xml. the image was displayed in pdf..Please help me
Weight Loss Surgery Side Effects
Weight Loss Surgery Side Effects This article we are discussing the side effects of weight loss surgery. What kind of side effects can occur after... effects of weight loss surgery. You still have to take care of your diet. Even
MX Pause Effect in Flex4
MX Pause Effect in Flex4: The Pause effect is useful in sequencing effects. You create a pause between two effects by using Pause effect. The tag of Pause...; horizontalAlign="center"> <s:Label text="Click on image
Image Zoom Behavior in Flex 4
Flex Zoom Image Effects:- In Graphical interface we can make components larger...; for zoom effects for image zoom. Flex Image Zooming Behavior Example:- <... an image component with the help of zoom behavior in flex. In this tutorial we can set
How to save image after edit in php
successfully but i don't know how to replace orignal image with the effects. please...How to save image after edit in php  Hello, I have create a simple image editor with the effected of brightness, contrast, and desaturat etc. I have
Animating 'Div' blocks with different effects simultaneously
Animating 'Div' blocks with different effects simultaneously In this tutorial, we will discuss about how to animate 'Div' blocks with different effects simultaneously using jQuery. In this Example, we have two Div
Developer Open Source Library
is a super lightweight, ultratiny, megasmall JavaScript effects library, written... or other effects libraries. It's just a little alternative for people (like me) that do not need more than just simple, basic effects.    
MX Parallel Effect in Flex4
MX Parallel Effect in Flex4: The parallel Effect plays multiple child effects...:Image id="roseindia" source="@Embed(source='file:/C:/work/bikrant/image/roseindia.gif')" x="99" y
Crop Image using plug-in ,JSP and 'Servlet'
selection' effects are implemented by the jQuery. And the cropping of image...Crop Image using plug-in ,JSP and 'Servlet' In this tutorial, we will crop image using jQuery plug-in & servlet. In this example, a image &
MX Sequence Effect in Flex4
effects one after the other according they are added. The tag of Sequence Effect...="center"> <s:Label text="Click on image and show..."/> </mx:ApplicationControlBar> <mx:Image id
How to make a sharpen image
How to make a sharpen image I am going to make a sharp picture effect, I have here a dog picture to modify. Open Picture: Capture a picture to make sharp effect. Effects: Go to Image Menu
image scrolling
image scrolling  A brief description of scrolling image
Image Steganography
Image Steganography  SOURCE CODE FOR IMAGE STEGANOGRAPHY
jQuery To Slide Effects tabs
jQuery To Slide Effects tabs       In this JQuery tutorial we will develop a program  to make Custom  tabs  Steps to develop the simple tabs . Step 1:      
jQuery To Fade Effects tabs
jQuery To Fade Effects tabs       In this JQuery tutorial we will develop a program  to make Fade Effect  tabs  Steps to develop the simple tabs . Step 1:    
image format
image format  what are the different format available in image
image format
image format  what are the different format available in image
image in database
image in database  how to set image in database and retrieve it using servlet(java)in msaccess
Image_creation
Image_creation  how to create an image from a set of pixel values stored in array - in java
image scrambling
image scrambling  Hi frinds : i want to read image and scrambling it then saved using java any help please
To scan a image encode that image in j2me
To scan a image encode that image in j2me  Hai team i am new man of j2me i have doubt to scan a image and encode the image in j2me... Please clarify that doubt... Thanks in Advance... Kumar
How to make a sharpen image
How to make a sharpen image If you want to write your text in the sky, come to this example because I have made it as real written text in the sky... as looking here. Effects: Choose your "text" layer
Icon image
Icon image  hiii how can we set image on the icon by which we can launch the application???   hello, when you will save a image named icon.png then it is automatically show this image on the icon
image Processing
image Processing   BCIF Image Compresssion Algorithm s alossless image Compression algorithm ,Pleas Help Me weather it can support only 24 bit bmp images
Image processing
Image processing  i want a browsing program in java in which we hv a small img and we hv to browse this img on a big image so that we can find the similar type of image in big img
scrolling image
scrolling image  How create a scrolling image in java
UIButton with image
UIButton with image  Hi, How to create UIButton with image? Thanks
PDF to Image
PDF to Image  Java code to convert PDF to Image
TextField on the Image
TextField on the Image  how we set label or textfield etc. on the Image
update image
update image  sir, I want to do update image into database
image retreival
image retreival  I ve stored the path of image and audio in mysql database. how to retrive it and display... Can u pls help me out
image display
image display  Hai Friends..... Actually I uploaded filepath into database and image into a folder. Now i want to show that image as my profile photo. How it is?...Friends Can you help me? Thanks in advance to take time
image display
image display  Hai Friends..... Actually I uploaded filepath into database and image into a folder. Now i want to show that image as my profile photo. How it is?...Friends Can you help me? Thanks in advance to take time
image Processing
image Processing  Please give Me a JPEG or GIf "LOSS LESS" Image Compression and Decompression Source Code Please Help Me I don't want links Kindly help me Compression ratio not matter
image steganography
image steganography  Hello.could you please tell me how to start developing code for image steganography?could you provide some key points showimg its implementation
background image
background image  how to set background image in jsp using netbeans IDE 6.9
Image in Flex
Image in Flex  Hi..... Can you manipulate images using Flex programs? please give me the example....... Thanks
Image retrieve
Image retrieve  HI.. store image path/data Java Coding. ... It's supposed to take the image, store it in a directory as well as pass the image path to mysql database... Now I want to retrieve the data from directory using path

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.