java to php

Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.

Moderator: General Moderators

Post Reply
ashwin_nath_m
Forum Newbie
Posts: 2
Joined: Wed Feb 24, 2010 10:30 am

java to php

Post by ashwin_nath_m »

Please help me convert this function to php

Code: Select all

 
public static byte[] imageToBytes(Image img) {
        //scaled image to bytes
        int width = img.getWidth();
        int height = img.getHeight();
        try {
            int[] argb = new int[width * height];
            ByteArrayOutputStream bout = new ByteArrayOutputStream();
            DataOutputStream dout = new DataOutputStream(bout);
            try {
                img.getRGB(argb, 0, width, 0, 0, width, height);
 
 
                dout.writeInt(width);
                dout.writeInt(height);
                for (int i = 0; i < argb.length; i++) {
                    dout.writeInt(argb[i]);
                }
                return bout.toByteArray();
            } catch (OutOfMemoryError ex) {
                System.gc();
                return "".getBytes();
            }
        } catch (Exception e) {
            // this won't happen, because we're writing to a ByteArrayOutputStream
            return "".getBytes();
        }
    }
 
Thanks in advance ;-)
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: java to php

Post by pickle »

"Help" means you've tried it yourself and are struggling with a particular part.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
ashwin_nath_m
Forum Newbie
Posts: 2
Joined: Wed Feb 24, 2010 10:30 am

Re: java to php

Post by ashwin_nath_m »

i'm strugglibg with whole part donno wer 2 begin :(
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Post by Jonah Bron »

You should start by learning the basics of PHP. Here's a good place to start:

http://w3schools.com/php/
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Re: java to php

Post by alex.barylski »

Heres how to start :)

Code: Select all

 
 
class Image{
  // TODO: Implement image class
}
 
public static imageToBytes(Image $img)
{
 // Implement method
}
 
Cheers,
Alex
Post Reply