-
Zoom In help!!!
Hi there. I am creating a simple image editor in Netbeans 4.1. I have a Frame which has a panel listing options to the user such as Zoom In, Zoom Out, Set the picture to black and white etc. I then have a panel where images are loaded to and edited. I am in the process of making the Zoom In function work. I have set up the code in the frame and have been given the code for the panel with gaps that we need to fill in. My problem is that I can't get it to work. Below is the code
public void zoomIn() {
int row, column;
int r = 0, g = 1, b = 2; // To access arrays easily
int tLeft = 0, tRight = 4;
int mLeft = 0, mMid = 4, mRight = 8;
int cMod, cTemp;
// The counter for the actual array element, with RGBA as 4 entries
int block;
// One block of pixels to be expanded at a time
int rowTemp, rowModified;
int wmaxT, wmaxM;
if(zoomLevel > rowModified) return; // Cannot zoom any further
gTempBuffer.drawImage(myModifiedBuffer, 0, 0, this);
gModifiedBuffer.setColor(Color.white);
gModifiedBuffer.fillRect(0, 0, dPanel.width, dPanel.height);
hmax = myHeight[zoomLevel + 1]; // The zoomed height
if(hmax > dPanel.height) { // Keep to panel height
hmax = dPanel.height - dPanel.height / 3;
// Keep zoomed image to panel height
} else {
hmax = myHeight[zoomLevel];
}
wmaxT = myWidth[zoomLevel + 1];
if(wmaxT > dPanel.width) {
wmaxT = dPanel.width - dPanel.width/ 3;
} else {
wmaxT = myWidth[zoomLevel];
}
wmaxM = Math.min(myWidth[zoomLevel + 1], dPanel.width);
myTempRaster = myTempBuffer.getRaster();
myModifiedRaster = myModifiedBuffer.getRaster();
for( row = 0; row < (hmax / 2) - 1; row++){ // -1 to keep in range
rowTemp = row * 2; // 2 rows per pass
rowModified = row * 3; // 3 rows per pass
myTempRaster.getPixels(0, rowTemp, wmaxT, 1, myTempRasterArrayTop); // Top row to top array
myTempRaster.getPixels(0, rowTemp + 1, wmaxT, 1, myTempRasterArrayBot); // Bottom row to bot array
myModifiedRaster.getPixels(0, rowModified, wmaxM, 1, myModifiedRasterArrayTop); // Top row to top array
myModifiedRaster.getPixels(0, rowModified + 1, wmaxM, 1, myModifiedRasterArrayMid); // Bottom row to bot array
myModifiedRaster.getPixels(0, rowModified + 2, wmaxM, 1, myModifiedRasterArrayBot);
for(block = 0; block < wmaxT / 2; block++) { // Block is a pair of pixels
cTemp = block * 2 * 4;
// block counts 4 rgba entries to the array and 2 pixels
cMod = block * 3 * 4; // Modified block is 3 pixels * 4(rgba)
for(red = 0; red < 3; red++) {
myModifiedRasterArrayTop[cMod + red + mLeft] // Top left
= myTempRasterArrayTop[cTemp + red + tLeft];
myModifiedRasterArrayTop[cMod + red + mMid] = 0; // top middle
myModifiedRasterArrayTop[cMod + red + mRight] = // top right
myTempRasterArrayTop[cTemp + red + tRight];
myModifiedRasterArrayMid[cMod + red + mLeft] = 0; // middle left
myModifiedRasterArrayMid[cMod + red + mRight] = 0; // middle right
myModifiedRasterArrayBot[cMod + red + mLeft] = // bottom left
myTempRasterArrayBot[cTemp + red + tLeft];
myModifiedRasterArrayBot[cMod + red + mMid] = 0; // bottom middle
myModifiedRasterArrayBot[cMod + red + mRight] = // bottom right
myTempRasterArrayBot[cTemp + red + tRight];
myModifiedRasterArrayMid[cMod + red + mMid] = 0; // middle middle
}
}
myModifiedRaster.setPixels(0, rowModified, wmaxM, 1,
myModifiedRasterArrayTop);
myModifiedRaster.setPixels(0, rowModified + 1, wmaxM, 1,
myModifiedRasterArrayMid);
myModifiedRaster.setPixels(0, rowModified + 2, wmaxM, 1,
myModifiedRasterArrayBot);
}
zoomLevel++;
paintComponent(this.getGraphics());
}
Any Ideas?
Many thanks in advance for any responses i get
Similar Threads
-
Replies: 2
Last Post: 12-08-2005, 05:16 AM
-
Replies: 1
Last Post: 09-20-2005, 03:54 PM
-
By rechmbrs in forum Java
Replies: 0
Last Post: 07-11-2005, 09:41 PM
-
By TWS in forum VB Classic
Replies: 1
Last Post: 11-20-2000, 01:31 AM
-
By Adam Short in forum Java
Replies: 0
Last Post: 05-10-2000, 12:08 PM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks