How do I know whether an area of selection has pixels or not?

Hi all

I want to know how find out whether an area of selection has pixels (empty) using javascript.

can someone help me?

With the help of Mike function you can do...

main();
function main(){
var doc = activeDocument;
if(hasSelection (doc)){
var result = interscetTransparency();
if(result && !hasSelection (doc)){
    alert("No pixels exist");
    }else{
        alert("Pixels exist");
        }
    }
}

function interscetTransparency() {
    var desc = new ActionDescriptor();
        var channelRef = new ActionReference();
        channelRef.putEnumerated( charIDToTypeID('Chnl'), charIDToTypeID('Chnl'), charIDToTypeID('Trsp') );
    desc.putReference( charIDToTypeID('null'), channelRef );
        var selectionRef = new ActionReference();
        selectionRef.putProperty( charIDToTypeID('Chnl'), charIDToTypeID('fsel') );
    desc.putReference( charIDToTypeID('With'), selectionRef );
    try{
    executeAction( charIDToTypeID('Intr'), desc, DialogModes.NO );
    return true;
    }catch(e){return false;}
};
function hasSelection (doc) {
  var res = false;
  var as = doc.activeHistoryState;
  doc.selection.deselect();
  if (as != doc.activeHistoryState) {
    res = true;
    doc.activeHistoryState = as;
  }
  return res;
};

Tags: Photoshop

Similar Questions

Maybe you are looking for