Scale transform in AffineTransformOp produces row/column of dead pixels

Hello,
On JDK 1.4.1, both Windoze and Linux, the following code:
double aScaleFactor = ((double) finalSize) / aSourceSize;
AffineTransform aScaleTransform =
AffineTransform.getScaleInstance(aScaleFactor, aScaleFactor);
AffineTransformOp aScaleOp = new AffineTransformOp(aScaleTransform, anInterpolationType);
Rectangle aDestinationRegion =
aScaleOp.getBounds2D(sourceImage).getBounds();
aScaleOp.filter(sourceImage, destinationBuffer);
scaleIntoSubimage = destinationBuffer.getSubimage( aDestinationRegion.x, aDestinationRegion.y, aDestinationRegion.width, aDestinationRegion.height);
... works as expected, except that sometimes the last row (row of largest y) or last column (column of greatest x) does not get written into so the pixels are all 0.
Exactly when this happens depends on the precise size of the source image , and size of destination image. Usually, increasing the size of the destination image by just one pixel causes the aberration to disappear.
Is this a bug in the JDK? Some type of rounding error?
thanks for any pointers.
joe

I find the following code creates excellent quality thumbnails on Windows and Linux - and no X server required! Hope it helps - if there is a better way of getting rid of that line let me know!
import java.io.*;
import javax.imageio.*;
import java.awt.image.*;
import java.awt.geom.*;
public class Main
public Main(String srcFileName,String destFileName,int thumbNailSize) throws Exception
// Read in original image to create thumbnail from
File inFile = new File(srcFileName);
BufferedImage bufferedImage = ImageIO.read(inFile);
// Calculate scale so image fits in a square area of thumbNailSize - e.g. 160
int imageWidth = bufferedImage.getWidth();
int imageHeight = bufferedImage.getHeight();
int componentWidth = thumbNailSize;
int componentHeight = thumbNailSize;
double scale = -1;
if ( imageWidth == componentWidth && imageHeight == componentHeight)
scale = 1;
else if ( imageWidth <= componentWidth && imageHeight <= componentHeight)
// set scale to 1 if we don't want to scale up - otherwise use code below...
scale = 1;
// double heightScale = ((double)componentWidth) / ((double)imageWidth);
// double widthScale = ((double)componentHeight) / ((double)imageHeight);
// if ( heightScale < widthScale ) scale = heightScale;
// else scale = widthScale;
else if ( imageWidth > componentWidth && imageHeight <= componentHeight)
double heightScale = ((double)componentWidth) / ((double)imageWidth);
scale = heightScale;
else if ( imageWidth <= componentWidth && imageHeight > componentHeight)
double widthScale = ((double)componentHeight) / ((double)imageHeight);
scale = widthScale;
else
double heightScale = ((double)componentWidth) / ((double)imageWidth);
int scaledHeight = (int)(((double)imageHeight) * heightScale);
double widthScale = ((double)componentHeight) / ((double)imageHeight);
int scaledWidth = (int)(((double)imageWidth) * widthScale);
if ( scaledWidth <= componentWidth ) scale = widthScale;
else scale = heightScale;
// Now create thumbnail
AffineTransform affineTransform = AffineTransform.getScaleInstance(scale,scale);
AffineTransformOp affineTransformOp = new AffineTransformOp(affineTransform,null);
BufferedImage scaledBufferedImage = affineTransformOp.filter(bufferedImage,null);
// Now do fix to get rid of silly spurious line
int scaledWidth = (int)(Math.round(scale*bufferedImage.getWidth()));
int scaledHeight = (int)(Math.round(scale*bufferedImage.getHeight()));
int expectedWidth = (int)(imageWidth * scale);
int expectedHeight = (int)(imageHeight * scale);
if ( scaledWidth > expectedWidth || scaledHeight > expectedHeight )
scaledBufferedImage = scaledBufferedImage.getSubimage(
0,0,expectedWidth,expectedHeight);
// Now write out scaled image to file
ImageIO.write(scaledBufferedImage,"JPG",new File(destFileName));
public static void main(String[] args)
if ( args.length < 3 )
System.err.println("Usage: imageTest srcFile DestFile size");
System.exit(-1);
try
int size = 160;
try
size = Integer.parseInt(args[2]);
catch (NumberFormatException numberFormatException) {}
Main main1 = new Main(args[0],args[1],size);
catch (Exception exception)
System.out.println(exception);
exception.printStackTrace();
}

Similar Messages

  • Right way to change datagrid row, column, cells background colors in code-behind?

    Hi all,
    I have a winform program that I'm upgrading to wpf (I'm new to wpf). The wpf code for the function (SetdataGridBackgroundColors()) is below with the winform code commented out so I can fix it.  I have a datagrid with a Cornsilk background color alteranating
    with LightGreen depending on the content of datetime  cell. If the day portion of the datetime is different then the color changes from one to the other. I used a colorIndex variable because at the end of the month it could go from 31 to 1 and that would
    not work if I use the day directly.
    I tried this line to change the background color:
    optionsDataDatagrid.RowBackground = new SolidColorBrush(Colors.Cornsilk);
    this works but it changes every row. I found this other stuff:
    DataGridRow currentRowColor = optionsDataDatagrid.ItemContainerGenerator.ContainerFromIndex(i) as DataGridRow;
    //DataGridRow currentRowColor = optionsDataDatagrid.ItemContainerGenerator.ContainerFromItem(optionsDataDatagrid.Items[i]) as DataGridRow;
    currentRowColor.Background = new SolidColorBrush(Colors.Cornsilk);
    Either ContainerFromIndex or ContainerFromItem throw an exception because currentRowColor is null. I looked at optionsDataDatagrid.Items[i] and is not null. Then I read that using ItemContainerGenerator is not a good idea.
    BTW I'm calling SetdataGridBackgroundColors() after datagrid is been filled with data.
    So... what is the proper way to set each row, column or cell background color in wpf?
    Thanks
    private void SetdataGridBackgroundColors()
    optionRowData rowData = new optionRowData();
    if (optionsDataDatagrid.Items.Count == 0)
    return;
    int colorIndex = 1;
    DateTime savedDate, currentRowDate;
    rowData = optionsDataDatagrid.Items[0] as optionRowData;
    savedDate = rowData.col_datetime.Date; //only compare the date not the time
    for (int i = 0; i < optionsDataDatagrid.Items.Count; i++)
    //currentRowDate = Convert.ToDateTime(optionsDataDatagrid.Rows[i].Cells[3].Value); //winform code
    //currentRowDate = currentRowDate.Date; //winform code
    rowData = optionsDataDatagrid.Items[i] as optionRowData;
    currentRowDate = rowData.col_datetime.Date;
    if (currentRowDate != savedDate)
    colorIndex++;
    savedDate = currentRowDate;
    if (colorIndex % 2 == 0)
    //optionsDataDatagrid.Rows[i].DefaultCellStyle.BackColor = Color.Cornsilk;
    //------------------- testing new code --------------begin
    optionsDataDatagrid.RowBackground = new SolidColorBrush(Colors.Cornsilk); //this changes all rows
    //DataGridRow currentRowColor = optionsDataDatagrid.ItemContainerGenerator.ContainerFromIndex(i) as DataGridRow;
    //DataGridRow currentRowColor = optionsDataDatagrid.ItemContainerGenerator.ContainerFromItem(optionsDataDatagrid.Items[i]) as DataGridRow;
    //currentRowColor.Background = new SolidColorBrush(Colors.Cornsilk);
    //------------------- testing new code --------------end
    //optionsDataDatagrid.Columns[4].DefaultCellStyle.BackColor = Color.DarkSalmon;
    //optionsDataDatagrid.Columns[5].DefaultCellStyle.BackColor = Color.Aquamarine;
    //optionsDataDatagrid.Rows[i].Cells[4].Style.ApplyStyle(optionsDataDataGridView.Columns[4].DefaultCellStyle);
    //optionsDataDatagrid.Rows[i].Cells[5].Style.ApplyStyle(optionsDataDataGridView.Columns[5].DefaultCellStyle);
    else
    //optionsDataDatagrid.Rows[i].DefaultCellStyle.BackColor = Color.LightGreen;
    //------------------- testing new code --------------begin
    optionsDataDatagrid.RowBackground = new SolidColorBrush(Colors.LightGreen); //this has no effect
    //------------------- testing new code --------------end
    //optionsDataDatagrid.Columns[4].DefaultCellStyle.BackColor = Color.Coral;
    //optionsDataDatagrid.Columns[5].DefaultCellStyle.BackColor = Color.LimeGreen;
    //optionsDataDatagrid.Rows[i].Cells[4].Style.ApplyStyle(optionsDataDataGridView.Columns[4].DefaultCellStyle);
    //optionsDataDatagrid.Rows[i].Cells[5].Style.ApplyStyle(optionsDataDataGridView.Columns[5].DefaultCellStyle);

    I (also) strongly recommend mvvm.
    Setting values is a particularly bad idea in this case.
    I don't mean to be rude but your explanation of the requirement is kind of vague.
    I would bind solidcolourbrushes.
    Set the properties based on whatever your logic is within the viewmodel.
    You can switch out what each of the brushes holds when the user clicks wherever.
    So you use a highlightbrush when something or other is true.
    That highlightbrush is set to a blue brush when the user clicks left and a red brush when they click right.
    Please don't forget to upvote posts which you like and mark those which answer your question.
    My latest Technet article - Dynamic XAML

  • How to get a single row column from a viewobject in java?

    I have a class file that goes out and gets a viewobject and sets its where clause
    this is it:
    vcRow = vc.createViewCriteriaRow();
    vcRow.setAttribute("LogonId", "='" + strPcis_Login.toUpperCase() + "'");
    vc.addElement(vcRow);
    vo.applyViewCriteria(vc);
    vo.executeQuery();
    I know this working cause I can watch it in debug..
    but now the problem.
    I've looked in the docs and don't see how one can pull the value of the row it found and place it in a uix page in a textinput area
    how can I get a single row column, in this case the UserName that is in the view object to a string and then place it into my
    uix page? I've looked and looked and don't see a method for this.
    is there a way to take the oracle.cabo.servlet.Page and set a textinput with a viewobject get method?
    what way do you do this and where is it documented?

    is there a way to take the oracle.cabo.servlet.Page and set a textinput with a viewobject get method?
    what way do you do this and where is it documented? What you can do is get the value from your VO and set it somewhere that UIX can data bind to -- as a Page proprety, on HttpSession, etc. This is documented in Chapters 4 (Data Binding) and 5 (Controller) of the UIX Developer's Guide.
    To set a property, you use Page.setProperty(String key, String value). Then, in your UIX file, to make a textInput that has the value pulled from a given page property, use:
    <textInput data:text="key@ctrl:page" />
    -brian
    Team UIX

  • How to get the selected rows & columns in the table?

    hi everybody,
                         In my application the table is kept inside the event structure.I select the cells  in the table (using mouse) on running time.How to get the selected number of rows & columns in that table?

    Hello,
    You can fill selected values of the table by writing to it or the corresponding property using a property node - the table is just a 2D array of strings.  I think for your "disable" question you are referring to the shortcut menu (when you right click).  If you are using LabVIEW 8.x, you can edit or disable that shortcut menu - just right click on your table at edit time and choose Advanced >> Run-Time Shortcut Menu.
    Best Regards,
    JLS
    Best,
    JLS
    Sixclear

  • Where can I find the function "mark a line" in a table (not a row but the line in-between the rows/columns)

    In the old version of Numbers (09) as well as in the same Pages version I could choose to allow to mark single lines inbetween rows/columns in order to choose to create different types of lines to mark separations in different sections or just single cells within a table, how do I do that in the recent upgrade?!!! I´m going mad over here!!!!!

    Hi A-S,
    Do you mean Cell Borders in the Format Panel?
    To create this?
    Or if you want borders under only A5 and C5 (but not B5) command click on those cells to select them before applying the borders in Format Panel
    Regards,
    Ian.

  • How to print the row  ,column,and particular cell in separate color

    how to print the row  ,column,and particular cell in separate color IN ALV GRID

    HI,
    Here you go good program links
    <a href="http://www.sapfans.com/forums/viewtopic.php?t=52107">How to Set Color to a Cell in AVL</a>
    <a href="http://www.sapdevelopment.co.uk/reporting/alv/alvgrid_color.htm">ALV Grid Coloring</a>
    Thanks
    Mahesh

  • How can I write into a table cell (row, column are given) in a databae?

    How can I write into a table cell (row, column are given) in a database using LabVIEW Database Toolkit? I am using Ms Access. Suppose I have three columns in a table, I write 1st row of 1st column, then 1st row of 3rd column. The problem I am having is after writing the 1st row 1st column, the reference goes to second row and if I write into 3rd column, it goes to 2nd row 3rd column. Any suggestion? 
    Solved!
    Go to Solution.

    When you do a SQL INSERT command, you create a new row. If you want to change an existing row, you have to use the UPDATE command (i.e. UPDATE tablename SET column = value WHERE some_column=some_value). The some_column could be the unique ID of each row, a date/time, etc.
    I have no idea what function to use in the toolkit to execute a SQL command since I don't use the toolkit. I also don't understand why you just don't do a single INSERT. It would be much faster.

  • Issue with row/column text lengths in report painter

    Hi Gurus,
    I have created a report painter report with formatting of the row/column length text as medium, but for one FS item/GL Account the report when executed still picks up only the short text length. I am not sure how this can be resolved.
    Any ideas is appreciated.
    Regards
    Satish

    Applied OSS Note 360096 and it worked. Thanks for all your help.

  • How do i set the background of the table( not of cell / row / column).

    How do i set the background of the table( not of cell / row / column).
    What happens when i load the applet the table is blank and displays the background color is gray which we want to be white.
    We tried using the setBackGround but it is not working maybe we are not using it properly. Any help would be gr8.
    Thanks in advance.

    I don't understand very well, but i guess that the background is gray when the table content's empty, isn't it?
    When the table model is empty, the JTable doesn't paint, so its container displays its background (often gray).
    In this case, what you must do is force the table to paint, even if the model is empty. So, you have to create your own table and override three methods :
    public class MyTable extends JTable
    //specify the preferred and minum size when empty
    myPreferredWidth = 200;
    myPreferredHeigth =200;
    myMinimunWidth = ...;
    myMinimunHeigth = ...;
    public Dimension getPreferredSize()
    if(getModel().getRowCount() < 1)
    return new Dimension(myPreferredWidth, myPreferredHeigth);
    else
    return super.getPreferredSize();
    public Dimension getMinimumSize()
    if( getModel().getRowCount() > 0)
    return new Dimension(myMinimunWidth, myMinimunHeigth);
    else
    return super.getMinimumSize();
    protected void paintComponent(Graphics g)
    if (getModel().getRowCount<1 && isOpaque()) { //paint background
    g.setColor(Color.white);
    g.fillRect(0, 0, getWidth(), getHeight());
    else super.paintComponent(g);
    }

  • Duplicating MovieClips into Rows & Columns

    Hi People,
    I am creating a project, which is a dynamic image gallery,
    wherein the images are loaded from an XML file. I am looking to
    create the thumbnails as rows & columns, based on the total
    number of images.
    I am able to duplicate the movieclips in rows & columns,
    if I define the number of rows & columns, but don't know how to
    do this at runtime, depending on the total number of images.
    Let's say I have 12 images, so the resulting grid should be
    like the one shown below:
    Can anybody please help, this is really urgent, and I losing
    my head over this
    Thanks to all in advance.
    Cheers,
    Husain

    //upper left corner of image grid
    var colStart = 30;
    var rowStart = 30;
    var imagesPerColumn = 5;
    var colCount = 0;
    //width and height of thumbs plus any buffer space between
    them
    var colWide = 50;
    var rowHigh = 50;
    //starting depth of new clips
    var deep = 5;
    for (var i = 0; i < 12; i++) {
    thisImage = this.attachMovie("thumb", "thumb" + i, deep + i,
    {_x:colStart +
    (colCount * colWidth), _y:rowStart});
    colCount++;
    if (colCount + 1 > imagesPerColumn) {
    colCount = 0;
    rowStart += rowHigh;
    This should get you going - just replace the 12 in the for
    loop with your
    array length. I used attachMovie to attach a thumb clip from
    the library but
    you can duplicate instead.
    HTH, let me know if you need more explanation.
    Dave -
    Adobe Community Expert
    www.blurredistinction.com
    www.macromedia.com/support/forums/team_macromedia/

  • Variables in Rows/Columns in the BEX BI7.0

    Hi Experts,
    In BI 7.0, two tabs are there to drag and drop infoobjects/Key figures into them: One is "FILTER" and other is "Rows/Columns".
    We can see the created variables can be dregged and dropped into both pan (FILTER and Rows/Columns). What is the diff when Variables dragged into FILTER and Row/Columns.
    Where is the correct way to use created variables either in the tab "FILTER" or "Rows/Columns" or both??
    <removed by moderator>
    Thanks!
    Sapna
    Edited by: Siegfried Szameitat on Jan 19, 2009 2:27 PM

    Hi Sapna,
    if you drag a characteristic to default values of the filter, you have to restrict it: doppelclick on characteristic and after that please choose some values to restrict the characteristic. After that you will see the difference.
    Regards
    Erwin

  • ADF 11g Partial Triggers Row Column Update By Column in the Same Row

    Hi.
    I have a situation whereby I have a checkbox in a table row, which has an eventchangelistener, which upon activation, trys to update another column in the same row. I can not get this to work through partial triggers, even though I have set up my ids up correctly. The row though can be updated by a command button outside of the table using the same coding techniques, but I need it updated via the checkbox.
    Is there a limitation in updating a column within a row, from another row column's event change listener.
    Thanks.

    Updating the other rows from the checkbox works fine for me. Here is what I did.
    I DnD Emp table with a new column that says if the emp is new hire. If the checkbox is checked, I set Firstname and Lastname for that row as NewHire. I have partial triggers on Firstname and Lastname columns to update whenever checkbox is checked/unchecked and autosubmit on checkbox to true. Hope this helps.
    Try adding column selection property to single and see if it helps.
    Edited by: asatyana on Jan 16, 2012 12:48 AM
    Edited by: asatyana on Jan 16, 2012 12:49 AM

  • Formatting the total row column for a OATableBean

    Hi,
    I have an OATableBean with total row column.
    I need to format one column and it's total value as 28,861.972528.
    I used both codes below:
    1-
    Formatter formatter = new OADecimalValidater("###,###,##0.00000;-###,###,##0.00000", "###,###,##0.00000;-###,###,##0.00000");
    OAMessageStyledTextBean unitBean = (OAMessageStyledTextBean)webBean.findChildRecursive("UnitLandedCost");
    if(unitBean != null)
    unitBean.setAttributeValue(ON_SUBMIT_VALIDATER_ATTR, formatter);
    2-
    DictionaryData unitBeanFormat = (oracle.cabo.ui.data.DictionaryData)tableColumnFormats.getItem(pageContext.findChildIndex(tableBean, "UnitLandedCost"));
    f(unitBeanFormat != null)
    unitBeanFormat.put(ON_SUBMIT_VALIDATER_ATTR, formatter);
    Both codes worked for the values, but the total value was not formatted in both cases. I tried to use the code below to get the column Footer, but the tableFooterBean is null:
    OATableFooterBean tableFooterBean = (OATableFooterBean)tableBean.getColumnFooter();
    Is there anything else that should be done to format the total value?
    Thanks and Regards,
    Andrea

    As Tapash mentioned getTotalValues method will work. Another option can be to calculate the total value based on the rows of VO but that won't be required unless you are looking for Grand Total functionality.
    --Shiv                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Can I create a generic Point to Row Column function?

    I have a VI with multiple MultiColumn Listboxes in it.  One way I've seen to make the entries writeable is as follows:
    This works fine.  The only issue is that to get the 'Point to Row Column' (PtRC) method requires (as I understand it) right-clicking on the MCL and selecting that method.
    I have multiple MCLs, and I wanted to create an event structure that was generic and could process any of them the same way.  But the problem with that is that I don't know a way to get access to the PtRC method for each one.  The only way I know to do it would be to use VI Scripting to create the reference on the fly (not sure if that would even work), but even if that works for me, I don't think it will work with the free LV RunTime Engine (my experience is that you can't use the RTE to execute any VIs that utilize VI Scripting).
    So my question is, is there a way to get a reference to the PtRC method - generically - without using VI Scripting, and/or is there a different way to do what I'm trying to do here (i.e. make the MCL writeable by the user and have it retain the values the user writes to it during VI execution).
    thanks
    Solved!
    Go to Solution.

    Not generic enough for you (not sure why it wouldn't be) here we can have code that finds the Multicolumn Listboxes and registers for all of them.
    Edit: As I feared the snippet isn't exactly what I made.  The "This VI" control on the left should be the "This VI" constant.
    Unofficial Forum Rules and Guidelines - Hooovahh - LabVIEW Overlord
    If 10 out of 10 experts in any field say something is bad, you should probably take their opinion seriously.

  • How to create variables for Characteristic Info-objects in Rows / Columns

    I want to create variables in abovementioned manner for COPA retraction in BPS, as COPA retraction does not recognise variables created in "filter" section of Bex. Can sumone advise , as I have tried all the possibilities of creating but failed to do so?

    Hi Ravi/All,
    Actually my problem will be solved if I am able to create variables in either Rows/Columns area of BeX.
    Variables are getting created easily in Filter section of BeX (but in COPA , it will not serve any purpose COPA retraction does not recognise contents of Filter/variables contained in the filter).
    In fact variables are getting created in Rows/Colums of Bex, but they are in the form of structures. (Again multiple structures (more than 1)  are not recognised in COPA retraction.

Maybe you are looking for

  • Archived log missed in standby database

    Hi, OS; Windows 2003 server Oracle: 10.2.0.4 Data Guard: Max Performance Dataguard missed some of the archivelog files and but latest log files are applying. standby database is not in sync with primary. SELECT LOCAL.THREAD#, LOCAL.SEQUENCE# FROM (SE

  • How can I delete multiple emails in the mailbox in one time?

    How can I delete multiple emails in one time in the mailbox?

  • Weak connection/Freezing with the new Plantronics Discovery 975

    After talking to other Plantronic Disc. 975 users with Palm Pres, I would like to reach out further! The head set for $130.00 has static and popping with the head set and phone within arms reach. Also, when hanging up on a call with the ear piece, th

  • Is it possible to customize audit summary view - CRM 2011

    Hi, Is it possible to modify or customize the default "Audit summary view" of Auditing in crm 2011? Apart from enabling or disabling filters, i don't see any options to modify the view so that i can add more columns or remove few columns from the def

  • Apps issue after OS upgrade BB 9800 Torch

    Hi, I upgraded today OS of my Blackberry Torch 9800 to v. 6.0 subv. 9249. Unfortunately right now two apps disappeared from MyWorld - Fuel Economy Calculator and Quick Slide. Both were purchased by me in 2011. Could you explain why were these apps re