MCPcopy Create free account
hub / github.com/AstroImageJ/astroimagej / setImage

Method setImage

ij/src/main/java/ij/ImagePlus.java:730–780  ·  view source on GitHub ↗

Replaces the image, if any, with the one specified. Throws an IllegalStateException if an error occurs while loading the image.

(Image image)

Source from the content-addressed store, hash-verified

728 * while loading the image.
729 */
730 public void setImage(Image image) {
731 if (image instanceof BufferedImage) {
732 BufferedImage bi = (BufferedImage)image;
733 int nBands = bi.getSampleModel().getNumBands();
734 int type = bi.getType();
735 boolean rgb = type==BufferedImage.TYPE_3BYTE_BGR||type==BufferedImage.TYPE_INT_RGB
736 ||type==BufferedImage.TYPE_4BYTE_ABGR||type==BufferedImage.TYPE_BYTE_INDEXED
737 ||type==BufferedImage.TYPE_INT_ARGB||type==BufferedImage.TYPE_INT_BGR;
738 int dataType = bi.getSampleModel().getDataType();
739 if (IJ.debugMode) IJ.log("setImage: type="+type+", bands="+nBands+", rgb="+rgb+", datatype="+dataType);
740 if (nBands>1 && !rgb) {
741 ImageStack biStack = new ImageStack(bi.getWidth(), bi.getHeight());
742 for (int b=0; b<nBands; b++)
743 biStack.addSlice(convertToImageProcessor(bi, b));
744 setImage(new ImagePlus(getTitle(), biStack));
745 return;
746 }
747 if (bi.getType()==BufferedImage.TYPE_USHORT_GRAY) {
748 setProcessor(null, new ShortProcessor(bi));
749 return;
750 } else if (bi.getType()==BufferedImage.TYPE_BYTE_GRAY) {
751 setProcessor(null, new ByteProcessor(bi));
752 return;
753 }
754 }
755 roi = null;
756 errorLoadingImage = false;
757 waitForImage(image);
758 if (errorLoadingImage)
759 throw new IllegalStateException ("Error loading image");
760 int newWidth = image.getWidth(ij);
761 int newHeight = image.getHeight(ij);
762 boolean dimensionsChanged = newWidth!=width || newHeight!=height;
763 width = newWidth;
764 height = newHeight;
765 setStackNull();
766 LookUpTable lut = new LookUpTable(image);
767 int type = lut.getMapSize()>0?GRAY8:COLOR_RGB;
768 if (image!=null && type==COLOR_RGB)
769 ip = new ColorProcessor(image);
770 if (ip==null && image!=null)
771 ip = new ByteProcessor(image);
772 setType(type);
773 this.img = ip.createImage();
774 if (win!=null) {
775 if (dimensionsChanged)
776 win = new ImageWindow(this);
777 else
778 repaintWindow();
779 }
780 }
781
782 /**
783 * Extract pixels as an ImageProcessor from a single band of a BufferedImage.

Callers 9

ImagePlusMethod · 0.95
doForwardTransformMethod · 0.95
showMethod · 0.45
setWindowMethod · 0.45
setTypeMethod · 0.45
setRoiMethod · 0.45
restoreRoiMethod · 0.45
flushMethod · 0.45
setCalibrationMethod · 0.45

Calls 15

logMethod · 0.95
addSliceMethod · 0.95
getTitleMethod · 0.95
setProcessorMethod · 0.95
waitForImageMethod · 0.95
setStackNullMethod · 0.95
getMapSizeMethod · 0.95
setTypeMethod · 0.95
repaintWindowMethod · 0.95
setOpenAsHyperStackMethod · 0.95
getProcessorMethod · 0.95

Tested by

no test coverage detected