Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Java in General
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Java in General
Converting image to gray scale.
faisal hameed
Ranch Hand
Posts: 48
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
I have to do assignment which convert image to gray scale.But I have no idea that how I can do that.Please help me to do this assignment.
import java.io.*; import javax.swing.*; class BMPImage{ int width; int height; int size; int red[][]; int green[][]; int blue[][]; byte bf[], bi[]; BMPImage(){ } BMPImage(byte []header1, byte []header2){ set(header1, header2); } public void set(byte []header1, byte header2[]){ this.bf=header1; this.bi=header2; int bflen = 14; int bilen = 40; width = (((int) bi[7] & 0xff) << 24) | (((int) bi[6] & 0xff) << 16) | (((int) bi[5] & 0xff) << 8) | (int) bi[4] & 0xff; height = (((int) bi[11] & 0xff) << 24) | (((int) bi[10] & 0xff) << 16) | (((int) bi[9] & 0xff) << 8) | (int) bi[8] & 0xff; size=width*height; red = new int[this.width][this.height]; green = new int[this.width][this.height]; blue = new int[this.width][this.height]; } //to convert current image to grayscale public BMPImage convertToGray(){ BMPImage temp=new BMPImage(bf, bi); //write code here to convert image "temp" to grayscale //formula is Y = 0.3*R + 0.59*G + 0.11*B //for grayscale red, green, blue will contain same values return temp; } public BMPImage reverse(){ BMPImage temp=new BMPImage(bf, bi); //write code here to reverse current image //simply last row will become first, second last will become second and so on return temp; } public BMPImage xor(BMPImage second){ BMPImage temp=new BMPImage(bf, bi); //write code here to xor current image with second image //xor operator is ^ return temp; } public void animate(BMPImage second){ BMPImage temp=new BMPImage(bf, bi); //create object of BMPImageViewer //take a loop for animation //run loop on ratio from 0 to 100 //write code here to xor current image with second image by ratio //show the result by calling view() of BMPImageViewer } public static void main(String []args) throws Exception{ //BMPImage image1=BMPReader.readBMPImage("ImageName.bmp");//Any image name //BMPImageViewer viewer1=new BMPImageViewer(image1); //BMPImage grayImage=image1.convertToGray(); //viewer.view(grayImage); //BMPImage reverseImage=reverse(); //viewer.view(grayImage); //BMPImage image2=BMPReader.readBMPImage("Bird.bmp"); //BMPImageViewer viewer2=new BMPImageViewer(image2); //BMPImage grayImage=image.xor(image2); //viewer.view(grayImage); //image.animate(image2); } }
Regards, M Faisal Hameed
PUCIT, Pakistan
Ulf Dittmer
Rancher
Posts: 43081
77
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
I take it you're not supposed to use the built-in
Java
APIs? We were
talking about that
just yesterday.
Naeem Arshad
Greenhorn
Posts: 12
I like...
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Dont Cheat with Sir Abdul Mateen
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Structure Size
Getting the size for an img tag dynamically with struts
Play video file frame by frame
Help!Help!
problems while converting
More...