Please help me merge two images
I've been reading tutorials for hours, and trying everything I can think of, but I just can't figure this out.
I have two BufferedImages (TYPE_INT_RGB), and I want to be able to create an alpha channel "mask" that lets me punch "holes" (antialiased) in the top one to have the bottom one show through. I can draw white circles (Ellipse2D.Double) to my heart's content on the top or bottom image, but I can't figure out how to use this as a alpha channel mask or how to use AlphaComposite to put it all together. Can someone please offer help?
I merged the top 2 responses together to get an antialiased version. Then I saw the post below. Can anyone comment on which version is more efficient? Thanks for all your help.
import java.awt.AlphaComposite;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.Rectangle;
import java.awt.RenderingHints;
import java.awt.Transparency;
import java.awt.geom.Area;
import java.awt.geom.Ellipse2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
public class ImageHoles extends JPanel {
BufferedImage[] images;
Area mask;
ImageHoles(BufferedImage[] images) {
this.images = images;
// Set the mask = null and call repaint
// inside componentResized method of a
// ComponentListener added to this.
protected void paintComponent(Graphics g) {
super.paintComponent(g);
int w = getWidth();
int h = getHeight();
int x = (w - images[0].getWidth())/2;
int y = (h - images[0].getHeight())/2;
// draw bottom image
g.drawImage(images[0], x, y, this);
x = (w - images[1].getWidth())/2;
y = (h - images[1].getHeight())/2;
if(mask == null) {
createMask(x, y);
// from Chris Campbell's Blog (see above)
// Create a translucent intermediate image in which we can perform
// the soft clipping
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice gs = ge.getDefaultScreenDevice();
GraphicsConfiguration gc = gs.getDefaultConfiguration();
BufferedImage img = gc.createCompatibleImage(w, h, Transparency.TRANSLUCENT);
Graphics2D g2 = img.createGraphics();
// Clear the image so all pixels have zero alpha
g2.setComposite(AlphaComposite.Clear);
g2.fillRect(0, 0, w, h);
g2.setComposite(AlphaComposite.Src);
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2.setClip(mask);
g2.setColor(Color.WHITE);
g2.fill(mask);
BufferedImage hi = images[1];
g2.setComposite(AlphaComposite.SrcAtop);
g2.drawImage(hi, 0,0,hi.getWidth(), hi.getHeight(), this);
g2.dispose();
// from Chris Campbell's Blog (see above)
// draw masked antialias layer
g.drawImage(img, x, y, this);
private void createMask(int x, int y) {
int w = images[1].getWidth();
int h = images[1].getHeight();
Rectangle r = new Rectangle(x, y, w, h);
Ellipse2D e1 = new Ellipse2D.Double(x+20, y+75, 25, 25);
int cx = x + w/2;
int cy = y + h/2;
Ellipse2D e2 = new Ellipse2D.Double(cx-30, cy-30, 60, 60);
Ellipse2D e3 = new Ellipse2D.Double(x+w-60, y+h-60, 40, 40);
mask = new Area(r);
mask.subtract(new Area(e1));
mask.subtract(new Area(e2));
mask.subtract(new Area(e3));
public static void main(String[] args) throws IOException {
String[] ids = { "polarBear", "hawk" };
BufferedImage[] images = new BufferedImage[ids.length];
for(int j = 0; j < images.length; j++) {
String path = "images/" + ids[j] + ".jpg";
images[j] = ImageIO.read(new File(path));
ImageHoles test = new ImageHoles(images);
test.setPreferredSize(new Dimension(images[0].getWidth(),images[0].getHeight()));
JOptionPane.showMessageDialog(null, test, "", -1);
}
Similar Messages
-
Here is the message I got from the red "i" message... please help.The backup disk image “/Volumes/Data/Lisa’s MacBook Pro.sparsebundle” is already in use.
http://pondini.org/TM/C12.html
-
please help i have two ipods but i can use any as i can download the newer version of Itunes as i have the older version of Bonjour on my laptop
I just cannot remove this!!!!!!!!!!!!i am no shure but go on Itunes store in shortcuts and try to find 'purchasse'
good luck -
I can't find the movie I downloaded on my iPad...please help! Downloaded two days ago.
If it's been successfully downloaded then it should be in the Videos app :
If you can't find it in there then have you got a film age rating set in Settings > General > Restrictions that is hiding it ? -
Need help in merging two database
Dear All,
Can any one please let me know the methodology/Best practices for merging two databases.
We are having two oracle Database A and B, the data from
Database A has to be migrated to Database B using PL/SQL scripting.
it will be a great help,Thanks in advance!Hi,
Use the DB Links and try to use the "MERGE" that is better.
you can clone it right, almost you are getting the same data from A to B and then you are going to Update is I am correct. Does the "B" consist the data, If yes then you can't clone on exiting DB, As i said above go for DB links and write custom scripts as per your requirement.
Refer for DB links
http://download.oracle.com/docs/cd/B19306_01/server.102/b14231/ds_admin.htm#sthref4108
- Pavan Kumar N -
How to merge two images together
hi,
I sell mobile phone cases and want to produce my own images. I have taken images of the case and have taken the background off. I have found an image on the internet of the phone and want the phone to be merged into the case.
could someone please help me to do this.
thanksIn Editor, go to the expert tab.
Open picture B, the one you wish to select something from to add to another picture.
Use one of the selection tools, e.g. selection brush, lasso tool, to select the object. You will see an outline ("marching ants") once the selection is complete
Go to Edit menu>copy to copy the selection to the clipboard
Open picture A, then go to Edit>paste
Use the move tool to position object from picture B.
In the layers palette you should see picture A as the background layer, and object B on a separate layer. -
Merging two images....
Here's one for you guys....
I have a bunch on JPG images (50+) that I've taken that I want to add a "copyright" to.
I use photoshop, and the copyright is just text created in PS and saved as a PS file (IIRC I'm at work ATM).
What I would like to know is....
Can you merge the two images putting the copyright in a set location over the JPG and saving the file. (and then deleting the original).
Is photoshop the best thing to use is possibly another question.....
Thank in advanceAutomator is not the answer. You need an image editor like Adobe Photoshop Elements or maybe GraphicConverter
It would also help if you gave a bit more detail-preferably in a new thread-of exactly what you were trying to do and why you cannot do it. -
Please help! Elements 11 image quality poor compared to LR
Hello, I just started using elements and am very irritated because the image quality is very poor compared to when i am viewing in LR. Its not the conversion - i have tried pulling directly from the camear. It looks great in Camera Raw 7.1 but the second i pull it into editor, it lines get jagged. Adobe help is telling me this is normal. Surely not?? Something about a halo around pixels? Image on left is Elements 11, right is Lightroom and Zoomed in so you can see how sharp it is. PLEASE help. im so frustrated!
In the pse 11 editor are you looking at the image at 100% view (actual pixels)?
(Other viewing percents can be misleading in the pse 11 editor)
Double click on the zoom tool in the tol box to get 100% view.
Also you should be on camera raw 7.4 available from Help>Updates within the pse 11 editor.
Is that lightroom 4.4? -
Please Help Nested Editable Region Image & Spry
Please Help Me.
New to Dreamweaver. I've been given a "grandchild" nested temple with only one editable region to alter. I've read and Googled since Saturday. My brain actually hurts.
Goal
- Insert my background image into region
- Add Spry accordion to mid left
- Add Spry collapsible to bottom right
How can 3 things be so hard? Please, can someone walk me through this? Thank youI've been given a "grandchild" nested template with only one editable region to alter.
Nested templates. Aaaaaak! There's no advantage in nested templates, ever. They're so problematic it makes my head hurt just thinking about them.
If you have the parent and grandparent template.dwt files to work with, you'll need to insert Editable Regions to hold your scripts and other supporting widget code.
If you don't have those files and you can't edit the <head>, you can't insert widgets into Template child or grandchild pages. You'll need to detach the page from Templates.
Nancy O. -
Please help with combining two java packages into one iteration
Hello, I work for a pharmaceutical company and run reports for credits that we have received. Currently the packages are reported seperately from the credit reports and my job is to combine them. There are two models that handle these and I need to link the second to the first with some common entities. Please help me figure out what I need to do in order to add a credit column to the report. I have a sample of the code below and would appreciate any help you can offer.
First, the info pulled about the boxes:
rm = (ReportManager) ManagerFactory.getManager(ManagerFactory.REPORTS);
items = rm.getRVSSearchResults(hvstoresid,
hvstoregroupsid,
String.valueOf(request.getParameter("price_type")).trim(),
String.valueOf(report_by).trim(),
vendor_type,
String.valueOf(request.getParameter("vendor")).trim(),
from_date,
until_date,
debitNum,
processing_type,
sort_field,
sort_direction,
includeAll222s).iterator();
Second, the page that has the data i need to transpose to the first:
PackoutModel pm = null;
int iter = searchpageposition*resultPageSize;
while (iter < packouts.size() && iter<(searchpageposition*resultPageSize)+resultPageSize)
{ pm = (PackoutModel) packouts.get(iter);
BigDecimal invoiceAmt = DataConverter.parseBigDecimalWithAlternateWhenNull(pm.getInvoiceAmt(),"0.00");
BigDecimal creditRec = DataConverter.parseBigDecimalWithAlternateWhenNull(pm.getAmtReceived(),"0.00");
BigDecimal processingFee = DataConverter.parseBigDecimalWithAlternateWhenNull(pm.getProcessFeeTotal(),"0.00");
BigDecimal shippingFee = DataConverter.parseBigDecimalWithAlternateWhenNull(pm.getShippingHandlingFeeTotal(),"0.00");
BigDecimal balanceDue =(invoiceAmt.add(processingFee.add(shippingFee))).subtract(creditRec);
All that I need from the second page is to get a value for:
DataConverter.parseBigDecimalWithAlternateWhenNull(pm.getAmtReceived(),"0.00");
which I believe must first have the store id, etc equal to the first model. So there is the existing rvs.FOO and the needed pm.BAR but since it is in an iter loop, I can't seem to figure out how to join the two.
Any ideas?could you explain your problem with a simplified schema or a more
understandable code.
(don't bother to write the details of your project plz) -
Please help, how to reposition image?
Hi,
I am using JWindow instead of JFrame to paint the window border and
have a problem that I could not paint the image in my designed
position.
I have the border from the designer and divided the border in 8 parts,
4 corners and 4 borders(top, bottom, left, right). Whatever the size
is, I keep the corner size and using Graphics2D, and AffineTransfrom
to transfrom the border.
Here is the code in the paint(g) method.
tx = new AffineTransform();
scalex = (double)dw/TOP_BORDER.getWidth(this);
scaley = (double)TOP_BORDER_HEIGHT/TOP_BORDER.getHeight(this);
System.out.println("happy, scalex is " + scalex );
System.out.println("happy, scaley is " + scaley );
tx.scale(scalex, scaley);
tx.translate(VERTICAL_BORDER_WIDTH, 0);
g2d.drawImage(TOP_BORDER, tx, this);
The problem is he TOP_BORDER image always start painted at 0,0 (the
VERTICAL_BORDER_WIDTH is definitely not 0). I presume the translate is
the same as setLocation of normal JComponent.
Please help.
Thanks in advance for any ideas and input.
Winghi,
what about Toolkit.getDefaultToolkit().getImage(String)regards -
Help with Merging Two Accounts....
Hi,
We ended up with two my Best Buy accounts.
I called up and talked with someone, who said they would merge the accounts....
A few hours later, when I logged in, the website said I had two accounts and to choose one to view.
That lasted for about 4 days,
Then, the website didn't ask anymore and just logged into one account ... which I thought meant the merge had occured.
HOWEVER, none of the purchases on the"other" account are on the primary account, which was the point of teHi scXenon,
I used the email address you registered with the forum to review your information, and I do see that you currently have two active My Best Buy™ accounts. If the primary information shared between the two accounts matches, then we should have no problem merging them. That process would involve closing one account, and then moving any unused points/certificates from the closed account to the active primary account.
I do see that you have an open case with our Account Maintenance department and I trust that they will be able to help successfully merge your accounts; however, I am going to send you a private message to see if there is anything I can help with. To check your private messages, you would want to login to the forum and click on the yellow envelope icon located at the top of the page.
Merging My Best Buy™ Accounts
Thank you for posting!
Derek|Social Media Specialist | Best Buy® Corporate
Private Message -
Please help... overlaying images and tables
Hello.. i'm relatively new to Dreamweaver so excuse me if
this is a "duh" question.
Ok.. so i am redesigning my website, before i used Microsoft
Word. So trying to learn Dreamweaver and its tables and everything
has been very confusing, however i am coming along. So here is my
problem.. i have a Nav bar going down the left side of my page, and
in my old website i used an image for the border... the image would
go behind and i would place the buttons on top of the image..
It doesn't look like things work that easily in dreamweaver,
so i was hoping someone could point me in the right direction.
Here is a screenshot of my workspace--
http://www.danwayfilms.com/help.JPG
Here is the look i want to achieve.. www.danwayfilms.com ...
as you can see, the images jumping around is 1 reason why i
switched to dreamweaver...
thanks.. please reply ASAP!!
DanHere's an opening salvo. If your previous experience with web
pages was
with Microsoft Word, then you essentially have NO experience
with web pages.
That being the case, you face a LONG and tedious uphill climb
with DW.
Without knowing anything about HTML and CSS, you will
transition from one
mysterious problem to another, all the while thinking with a
"click and
drag" mindset, and most likely eventually give up in
frustration.
The truth is that working with HTML is definitely NOT like
working with
Microsoft Word. The sooner you learn that, the better off you
will be.
Please do yourself a favor and take a week or two to just
read about HTML -
so you'll know some of the language. You can start at
http://www.w3schools.com with
their excellent tutorials.
Also, images of pages do no good. To get definitive help, we
need to see
the code on the page, since it's always the code that
determined how the
page will look in any browser....
Murray --- ICQ 71997575
Adobe Community Expert
(If you *MUST* email me, don't LAUGH when you do so!)
==================
http://www.dreamweavermx-templates.com
- Template Triage!
http://www.projectseven.com/go
- DW FAQs, Tutorials & Resources
http://www.dwfaq.com - DW FAQs,
Tutorials & Resources
http://www.macromedia.com/support/search/
- Macromedia (MM) Technotes
==================
"Fxmaker" <[email protected]> wrote in
message
news:[email protected]...
> Hello.. i'm relatively new to Dreamweaver so excuse me
if this is a "duh"
> question.
>
> Ok.. so i am redesigning my website, before i used
Microsoft Word. So
> trying
> to learn Dreamweaver and its tables and everything has
been very
> confusing,
> however i am coming along. So here is my problem.. i
have a Nav bar going
> down
> the left side of my page, and in my old website i used
an image for the
> border... the image would go behind and i would place
the buttons on top
> of the
> image..
> It doesn't look like things work that easily in
dreamweaver, so i was
> hoping
> someone could point me in the right direction.
>
> Here is a screenshot of my workspace--
>
http://www.danwayfilms.com/help.JPG
>
> Here is the look i want to achieve.. www.danwayfilms.com
... as you can
> see,
> the images jumping around is 1 reason why i switched to
dreamweaver...
>
> thanks.. please reply ASAP!!
>
> Dan
> -
I have two java.awt.Image objects that need to be shown one over the other (one contains transparency information). Right now, they are placed in seperate labels and placed one over the other. Obviously, I would much rather have a single Image object containing both images merged together.
I've looked through the Image class and could not find a simple "add" or "blend" function. Does anyone have any quick solutions, or do I have to write my own code?
Thanks in advance!
JNRead up on java.awt.AlphaComposite
http://java.sun.com/j2se/1.4.1/docs/api/java/awt/AlphaComposite.html -
URGENT : Please HELP : Loading a first image too slow
Hello,
I want to load an image to save it just before in a JPG format so as to obtain finally a byte[] array of this JPG image result.
So, to do it, I tried to load my Image from different ways but I have always a strange comportement... My problem come from the reading :
First, I use the imageio classes...
FileImageInputStream fiis = new FileImageInputStream(file);
BufferedImage input = ImageIO.read(fiis);
And then, I use the oldest method :
Image image = new ImageIcon(file.getAbsolutePath()).getImage();
BufferedImage input = new BufferedImage(image.getWidth(panel), image.getHeight(panel),BufferedImage.TYPE_INT_RGB);
and also :
Image image = new ImageIcon(file.getAbsolutePath()).getImage();
BufferedImage input = toBufferedImage(picture);
But finally, I understood my problem is that the first time I load an image (no matter the format, JPG, BMP, TIFF... or other) the loading phase is very slow and lasts at least 30 sec. But then, every loading that I do will gonna be really fast. (No more than 1 sec.) It's look like if the first time there was a kind of dinamical alocation or something like that.... but I tried to find some configuration parameters to set it... But without success. :-(
If someone could have an idea to suggest me... it would help me very much.
Thanks in advance for your help,
AnthonyPlease someone can help me ?!? A suggestion ?
I have tried today one more time to resolve this issue... but without success... Anything I do with the loading of an image... by imageio or other ways... it's still the same problem... the first time I load an image, it takes me 40 - 50 sec to load it and after this first load, it is very fast with others... and with every formats. It's not a question of format but of memory allocation, I think... but I'm not sure...
PRECISION : I work with an applet, is there something to configurate to allocate some memories or another thing ?!?
Thanks in advance for your help, I really need it just right now... I have to finish this job extremly fast !!!
Regards,
Anthony
Maybe you are looking for
-
Call functions in parent(?) from popup window(?)
I'm not sure the terms parent or window in flex 4. I want to call functions in parent from parent window. it seems to be hard. Help me please. Thanks in advance. ========================== index.mxml ========================== (root element : <mx:App
-
Imported rolls from iPhoto end up as separate projects
Is there any way to handle this? I imported some iPhoto libraries into Aperture and even though I have the photos in iPhoto organized by album etc., they all came in as separate rolls - I don't want them separate, I want to have them all together =-
-
Is it possible to import existing tables dump into another tables.
Hi, i have a schema called "xyz". in that i have a,b,c tables. i took a,b,c tables backup using normal export. and also i have e,f,g tables in same schema ("xyz"). i want to import a,b,c data into e,f,g tables. can anyone please let me know what is t
-
Disply Popup Message in Dashboard Prompts...
Hi, I Created Dashboard Prompt with 2column Like Year and Month.when User Select above year like 2013 Then showing msg or popup your select wrong value.At Same Time Month Also When select december(2012) Disply the message. Please Any Help....
-
Our network is a Small Business Windows 2003 network. After the Windows Updates this month both of our HP8000 (C4086A) networked printers truncate several characters left margin; and it doesn't make a difference what the OS is, Windows XP Pro or Wind