예제 #1
0
 [java.attr.RetainName] public void componentResized(ComponentEvent e)
 {
     if (canvas == null ||
         canvas.getWidth() != getWidth() ||
         canvas.getHeight() != getHeight())
     {
         canvas = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_ARGB);
     }
 }
예제 #2
0
 public void reset()
 {
     lock (lockObj)
     {
         xo = yo = 0;
         if (image != null)
         {
             w = image.getWidth();
             h = image.getHeight();
         }
         repaint();
     }
 }
예제 #3
0
        /// <summary>
        /// Метод, предназначенный для замены яркости определенного кол-ва пикселей
        /// </summary>
        /// <param name="bitmap"></param>
        /// <param name="percent"></param>
        /// <returns></returns>
        public static Bitmap RandomReplacePixel(Bitmap bitmap, int percent)
        {
            BufferedImage img = new BufferedImage(bitmap);
            int           n = img.getHeight() * img.getWidth() * percent / 100;
            int           maxWidth = img.getWidth(), maxHeight = img.getHeight();
            Random        random = new Random();

            for (int i = 0; i < n / 2; i++)
            {
                img.setRGB((int)((double)random.Next(0, 100) / 100 * maxWidth), (int)((double)random.Next(0, 100) / 100 * maxHeight), new Color(0, 0, 0).getRGB());
                img.setRGB((int)((double)random.Next(0, 100) / 100 * maxWidth), (int)((double)random.Next(0, 100) / 100 * maxHeight), new Color(255, 255, 255).getRGB());
            }
            return(img.getBitmap());
        }
예제 #4
0
        private void createColorImageThreadTask(BufferedImage imageChunk, int mask, ArrayList <BufferedImage> resultList, int index)
        {
            BufferedImage colorImage = new BufferedImage(imageChunk.getWidth(),
                                                         imageChunk.getHeight(), imageChunk.getType());

            for (int x = 0; x < imageChunk.getWidth(); x++)
            {
                for (int y = 0; y < imageChunk.getHeight(); y++)
                {
                    int pixel = imageChunk.getRGB(x, y) & mask;
                    colorImage.setRGB(x, y, pixel);
                }
            }
            resultList.Add(colorImage);
        }
예제 #5
0
        /// <summary>
        /// Writes the <tt>IconEntry</tt> structure to output
        /// </summary>
        private int WriteIconEntry(BufferedImage img, int fileOffset)
        {
            // Width 1 byte Cursor Width (16, 32 or 64)
            int width = img.getWidth();

            writer.Write((byte)(width == 256 ? 0 : width));
            // Height 1 byte Cursor Height (16, 32 or 64 , most commonly = Width)
            int height = img.getHeight();

            writer.Write((byte)(height == 256 ? 0 : height));
            // ColorCount 1 byte Number of Colors (2,16, 0=256)
            short BitCount   = (short)img.getColorModel().getPixelSize();
            int   NumColors  = 1 << (BitCount == 32 ? 24 : (int)BitCount);
            byte  ColorCount = (byte)(NumColors >= 256 ? 0 : NumColors);

            writer.Write((byte)ColorCount);
            // Reserved 1 byte =0
            writer.Write((byte)0);
            // Planes 2 byte =1
            writer.Write((short)1);
            // BitCount 2 byte bits per pixel (1, 4, 8)
            writer.Write((short)BitCount);
            // SizeInBytes 4 byte Size of (InfoHeader + ANDbitmap + XORbitmap)
            int cmapSize = GetColorMapSize(BitCount);
            int xorSize  = GetBitmapSize(width, height, BitCount);
            int andSize  = GetBitmapSize(width, height, 1);
            int size     = 40 + cmapSize + xorSize + andSize;

            writer.Write(size);
            // FileOffset 4 byte FilePos, where InfoHeader starts
            writer.Write(fileOffset);
            return(size);
        }
예제 #6
0
 /// <summary>
 /// Writes the <tt>InfoHeader</tt> structure to output
 ///
 /// </summary>
 private void WriteInfoHeader(BufferedImage img)
 {
     // Size of InfoHeader structure = 40
     writer.Write(40);
     // Width
     writer.Write(img.getWidth());
     // Height
     writer.Write(img.getHeight() * 2);
     // Planes (=1)
     writer.Write((short)1);
     // Bit count
     writer.Write((short)img.getColorModel().getPixelSize());
     // Compression
     writer.Write(0);
     // Image size - compressed size of image or 0 if Compression = 0
     writer.Write(0);
     // horizontal resolution pixels/meter
     writer.Write(0);
     // vertical resolution pixels/meter
     writer.Write(0);
     // Colors used - number of colors actually used
     writer.Write(0);
     // Colors important - number of important colors 0 = all
     writer.Write(0);
 }
예제 #7
0
        /// <summary>
        /// Метод, предназначенный для квантования изображения
        /// </summary>
        /// <param name="bitmap"></param>
        /// <param name="n"></param>
        /// <returns></returns>
        public static Bitmap Quantization(Bitmap bitmap, int n)
        {
            BufferedImage img = new BufferedImage(bitmap);
            Color         color;

            for (int i = 0; i < img.getWidth(); i++)
            {
                for (int j = 0; j < img.getHeight(); j++)
                {
                    color = new Color(img.getRGB(i, j));
                    if (color.getRed() % n != 0 && color.getRed() != 0)
                    {
                        img.setRGB(i, j, new Color(newColor(color.getRed(), n), color.getGreen(), color.getBlue()).getRGB());
                    }
                    if (color.getBlue() % n != 0 && color.getBlue() != 0)
                    {
                        img.setRGB(i, j, new Color(color.getRed(), color.getGreen(), newColor(color.getBlue(), n)).getRGB());
                    }
                    if (color.getGreen() % n != 0 && color.getGreen() != 0)
                    {
                        img.setRGB(i, j, new Color(color.getRed(), newColor(color.getGreen(), n), color.getBlue()).getRGB());
                    }
                }
            }
            return(img.getBitmap());
        }
예제 #8
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public static java.awt.image.BufferedImage imageFromBytes(int paramInt, byte[] paramArrayOfByte) throws Exception
        public static BufferedImage imageFromBytes(int paramInt, sbyte[] paramArrayOfByte)
        {
            string str = "jpg";

            if (paramInt == 1)
            {
                str = "png";
            }
            else if (paramInt == 3)
            {
                str = "gif";
            }
            MemoryStream byteArrayInputStream1 = new MemoryStream(paramArrayOfByte);

            System.Collections.IEnumerator iterator = ImageIO.getImageReadersByFormatName(str);
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
            ImageReader      imageReader           = (ImageReader)iterator.next();
            MemoryStream     byteArrayInputStream2 = byteArrayInputStream1;
            ImageInputStream imageInputStream      = ImageIO.createImageInputStream(byteArrayInputStream2);

            imageReader.setInput(imageInputStream, true);
            ImageReadParam imageReadParam = imageReader.DefaultReadParam;
            BufferedImage  bufferedImage  = imageReader.read(0, imageReadParam);

            return(createBufferedImage(bufferedImage, paramInt, bufferedImage.getWidth(null), bufferedImage.getHeight(null)));
        }
예제 #9
0
        public void fillBackground(BufferedImage dest)
        {
            Graphics g = dest.getGraphics();

            g.setColor(colorFactory.getColor(0));
            g.fillRect(0, 0, dest.getWidth(), dest.getHeight());
        }
예제 #10
0
        private bool parseImage()

        {
            _image = ImageIO.read(_is);

            _width  = _image.getWidth();
            _height = _image.getHeight();

            TempStream  ts = new TempStream();
            WriteStream os = new WriteStream(ts);

            try {
                ImageIO.write(_image, "jpeg", os);
            } finally {
                os.close();
            }

            /*
             * os = Vfs.openWrite("file:/tmp/caucho/qa/test.jpg");
             * try {
             * ImageIO.write(_image, "jpeg", os);
             * } finally {
             * os.close();
             * }
             *
             * os = Vfs.openWrite("file:/tmp/caucho/qa/test.png");
             * try {
             * ImageIO.write(_image, "png", os);
             * } finally {
             * os.close();
             * }
             */

            return(parseImageJpeg(ts.openRead()));
        }
        public static DataRaster wrap(BufferedImage image, AVList parameters)
        {
            if (null == image)
            {
                String message = Logging.getMessage("nullValue.ImageIsNull");
                Logging.logger().severe(message);
                throw new ArgumentException(message);
            }

            if (null == parameters)
            {
                String msg = Logging.getMessage("nullValue.AVListIsNull");
                Logging.logger().finest(msg);
                throw new ArgumentException(msg);
            }

            if (params.hasKey(AVKey.WIDTH))
            {
                int width = (Integer)parameters.getValue(AVKey.WIDTH);
                if (width != image.getWidth())
                {
                    String msg = Logging.getMessage("generic.InvalidWidth", "" + width + "!=" + image.getWidth());
                    Logging.logger().finest(msg);
                    throw new ArgumentException(msg);
                }
            }
예제 #12
0
        public virtual BufferedImage applyFilters(BufferedImage source)
        {
            BufferedImage dest = source;

            foreach (BufferedImageOp filter in Filters)
            {
                //if (filter.GetType().Equals(typeof(CurvesImageOp)))
                //	continue;
                dest = filter.filter(dest, null);
            }
            int x = (source.getWidth() - dest.getWidth()) / 2;
            int y = (source.getHeight() - dest.getHeight()) / 2;

            source = new BufferedImage(source.getWidth(), source.getHeight(), source.getType());
            source.getGraphics().drawImage(dest, x, y, null);
            return(source);
        }
예제 #13
0
        /// <summary>
        ///     Sets the frame with the specified id.
        /// </summary>
        /// <param name="id"> The id. </param>
        /// <param name="frame"> The frame. </param>
        public void SetFrame(int id, BufferedImage frame)
        {
            if (frame.getWidth() != width || frame.getHeight() != height)
            {
                throw new ArgumentException("The frame's dimensions do not match with the sprite's dimensions.");
            }

            frames[id] = frame;
        }
예제 #14
0
 public BufferedImage createCompatibleDestImage(BufferedImage src, ColorModel destCM)
 {
     if (destCM == null)
     {
         destCM = src.getColorModel();
         if (destCM is IndexColorModel)
         {
             destCM = ColorModel.getRGBdefault();
         }
     }
     return(new BufferedImage(destCM, destCM.createCompatibleWritableRaster(src.getWidth(), src.getHeight()), destCM.isAlphaPremultiplied(), null));
 }
예제 #15
0
 private void setPaint(Paint paint, boolean invert, double xoffset, double yoffset)
 {
     this.paint = paint;
     if (paint is Color)
     {
         cb.setColorFill((Color)paint);
     }
     else if (paint is GradientPaint)
     {
         GradientPaint gp = (GradientPaint)paint;
         Point2D       p1 = gp.getPoint1();
         transform.transform(p1, p1);
         Point2D p2 = gp.getPoint2();
         transform.transform(p2, p2);
         Color             c1      = gp.getColor1();
         Color             c2      = gp.getColor2();
         PdfShading        shading = PdfShading.simpleAxial(cb.getPdfWriter(), (float)p1.getX(), (float)p1.getY(), (float)p2.getX(), (float)p2.getY(), c1, c2);
         PdfShadingPattern pat     = new PdfShadingPattern(shading);
         cb.setShadingFill(pat);
     }
     else
     {
         try {
             BufferedImage img  = null;
             int           type = BufferedImage.TYPE_4BYTE_ABGR;
             if (paint.getTransparency() == Transparency.OPAQUE)
             {
                 type = BufferedImage.TYPE_3BYTE_BGR;
             }
             img = new BufferedImage((int)width, (int)height, type);
             Graphics2D g        = (Graphics2D)img.getGraphics();
             Shape      fillRect = new Rectangle2D.Double(0, 0, img.getWidth(),
                                                          img.getHeight());
             g.setPaint(paint);
             g.fill(fillRect);
             if (invert)
             {
                 AffineTransform tx = new AffineTransform();
                 tx.scale(1, -1);
                 tx.translate(-xoffset, -yoffset);
                 g.drawImage(img, tx, null);
             }
             com.lowagie.text.Image image   = com.lowagie.text.Image.getInstance(img, null);
             PdfPatternPainter      pattern = cb.createPattern(width, height);
             image.setAbsolutePosition(0, 0);
             pattern.addImage(image);
             cb.setPatternFill(pattern);
         } catch (Exception ex) {
             cb.setColorFill(Color.gray);
         }
     }
 }
예제 #16
0
        public ArrayList <BufferedImage> splitImage(BufferedImage originalImage, int size)
        {
            ArrayList <BufferedImage> imgArray = new ArrayList <BufferedImage>();

            for (int x = 0; x < originalImage.getWidth(); x += size)
            {
                for (int y = 0; y < originalImage.getHeight(); y += size)
                {
                    imgArray.Add(originalImage.getSubimage(x, y, size, size));
                }
            }
            return(imgArray);
        }
예제 #17
0
 private boolean initFlags(BufferedImage image, byte flag)
 {
     if (flag == Sprite.CENTERED)
     {
         this.spriteOffsetX = -image.getWidth() / 2;
         this.spriteOffsetY = -image.getHeight() / 2;
     }
     else if (flag == Sprite.CENTERED_BOTTOM)
     {
         this.spriteOffsetX = -image.getWidth() / 2;
         this.spriteOffsetY = -image.getHeight();
     }
     else if (flag == Sprite.CENTERED_TOP)
     {
         this.spriteOffsetX = -image.getWidth() / 2;
         this.spriteOffsetY = 0;
     }
     else
     {
         return(false);
     }
     return(true);
 }
예제 #18
0
        public override BufferedImage filter(BufferedImage src, BufferedImage dest)
        {
            if (dest == null)
            {
                dest = createCompatibleDestImage(src, null);
            }
            double     width  = dest.getWidth();
            double     height = dest.getHeight();
            Graphics2D g2     = (Graphics2D)src.getGraphics();

            g2.setRenderingHints(new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON));
            Random r  = new Random();
            int    cp = 4 + r.Next(3);

            int[] xPoints = new int[cp];
            int[] yPoints = new int[cp];
            width -= 10;
            for (int i = 0; i < cp; i++)
            {
                xPoints[i] = (int)((int)5 + (i * width) / (cp - 1));
                yPoints[i] = (int)(height * (r.NextDouble() * 0.5 + 0.2));
            }
            int subsections = 6;

            int[] xPointsSpline = new int[(cp - 1) * subsections];
            int[] yPointsSpline = new int[(cp - 1) * subsections];
            for (int i = 0; i < cp - 1; i++)
            {
                double x0 = i > 0 ? xPoints[i - 1] : 2 * xPoints[i] - xPoints[i + 1];
                double x1 = xPoints[i];
                double x2 = xPoints[i + 1];
                double x3 = (i + 2 < cp) ? xPoints[i + 2] : 2 * xPoints[i + 1] - xPoints[i];
                double y0 = i > 0 ? yPoints[i - 1] : 2 * yPoints[i] - yPoints[i + 1];
                double y1 = yPoints[i];
                double y2 = yPoints[i + 1];
                double y3 = (i + 2 < cp) ? yPoints[i + 2] : 2 * yPoints[i + 1] - yPoints[i];
                for (int j = 0; j < subsections; j++)
                {
                    xPointsSpline[i * subsections + j] = (int)catmullRomSpline(x0, x1, x2, x3, 1.0 / subsections * j);
                    yPointsSpline[i * subsections + j] = (int)catmullRomSpline(y0, y1, y2, y3, 1.0 / subsections * j);
                }
            }
            for (int i = 0; i < xPointsSpline.Length - 1; i++)
            {
                g2.setColor(colorFactory.getColor(i));
                g2.setStroke(new BasicStroke(2 + 2 * r.nextFloat()));
                g2.drawLine(xPointsSpline[i], yPointsSpline[i], xPointsSpline[i + 1], yPointsSpline[i + 1]);
            }
            return(src);
        }
예제 #19
0
        private void resampleFrameFile(Sector sector, BufferedImage srcImage, BufferedImage destImage, int frameNumber,
                                       PixelTransformer pt)
        {
            int frameULX = pixelColumn(0, frameNumber, this.frameStructure.getPixelRowsPerFrame(),
                                       this.frameStructure.getPolarFrames());
            int frameULY = pixelRow(0, frameNumber, this.frameStructure.getPixelRowsPerFrame(),
                                    this.frameStructure.getPolarFrames());

            int width  = destImage.getWidth();
            int height = destImage.getHeight();

            double deltaLon = (sector.getMaxLongitude().degrees - sector.getMinLongitude().degrees) / width;
            double deltaLat = (sector.getMaxLatitude().degrees - sector.getMinLatitude().degrees) / height;

            // unbundle these values that are used in the nested loop below -- its compute intensive enough...
            double minLon        = sector.getMinLongitude().degrees;
            double minLat        = sector.getMinLatitude().degrees;
            double polarConstant = this.frameStructure.getPolarPixelConstant();
            int    srcWidth      = srcImage.getWidth();
            int    srcHeight     = srcImage.getHeight();

            for (int y = 0; y < height; y++)
            {
                double lat = minLat + y * deltaLat;
                for (int x = 0; x < width; x++)
                {
                    double lon = minLon + x * deltaLon;

                    int pixelX = pt.latLon2X(lat, lon, polarConstant);
                    int pixelY = pt.latLon2Y(lat, lon, polarConstant);
                    int i      = pixelX - frameULX;
                    int j      = frameULY - pixelY;

                    if (i < 0 || i >= srcWidth || j < 0 || j >= srcHeight)
                    {
                        continue;
                    }

                    int color = srcImage.getRGB(i, j);

                    // Remove black trim known to be present in these maps....
                    if ((color & 0x00FFFFFF) == 0)
                    {
                        color = 0;
                    }
                    destImage.setRGB(x, height - 1 - y, color);
                }
            }
        }
예제 #20
0
        /// <summary>
        /// Изменение размера изображения
        /// </summary>
        /// <param name="bitmap"></param>
        /// <param name="n"></param>
        /// <returns></returns>
        public static Bitmap DecreaseImageResolution(Bitmap bitmap, int n)
        {
            BufferedImage img    = new BufferedImage(bitmap);
            BufferedImage newImg = new BufferedImage(bitmap.Width / n, bitmap.Height / n, BufferedImage.TYPE_INT_RGB);

            for (int i = 0, ik = 0; ik < img.getWidth(null); i++, ik += n)
            {
                for (int j = 0, jk = 0; jk < img.getHeight(null); j++, jk += n)
                {
                    Color color = new Color(img.getRGB(ik, jk));
                    newImg.setRGB(i, j, color.getRGB());
                }
            }
            return(newImg.getBitmap());
        }
        public void draw(string text, BufferedImage canvas, FontFactory fontFactory, ColorFactory colorFactory)
        {
            Graphics2D g  = (Graphics2D)canvas.getGraphics();
            TextString ts = convertToCharacters(text, g, fontFactory, colorFactory);

            arrangeCharacters(canvas.getWidth(), canvas.getHeight(), ts);
            g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
            g.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);
            g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
            foreach (TextCharacter tc in ts.Characters)
            {
                g.setColor(tc.Color);
                g.drawString(tc.iterator(), (float)tc.X, (float)tc.Y);
            }
        }
예제 #22
0
 public void imageBegin(int w, int h, int bucketSize)
 {
     lock (lockObj)
     {
         if (frame != null && image != null && w == image.getWidth() && h == image.getHeight())
         {
             // nothing to do
         }
         else
         {
             // allocate new framebuffer
             pixels = new int[w * h];
             image  = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
             // prepare frame
             if (frame == null)
             {
                 setPreferredSize(new Dimension(w, h));
                 frame = new JFrame("Sunflow v" + SunflowAPI.VERSION);
                 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//fixme: change to WinForms
                 //frame.addKeyListener(new KeyAdapter() {
                 //    @Override
                 //    public void keyPressed(KeyEvent e) {
                 //        if (e.getKeyCode() == KeyEvent.VK_ESCAPE)
                 //            System.exit(0);
                 //    }
                 //});
                 frame.setContentPane(this);
                 frame.pack();
                 frame.setLocationRelativeTo(null);
                 frame.setVisible(true);
             }
         }
         // start counter
         t.start();
     }
 }
예제 #23
0
        public virtual BufferedImage filter(BufferedImage src, BufferedImage dest)
        {
            if (dest == null)
            {
                dest = createCompatibleDestImage(src, null);
            }
            int width  = src.getWidth();
            int height = src.getHeight();

            int[] inPixels  = new int[width * height];
            int[] outPixels = new int[width * height];
            src.getRaster().getDataElements(0, 0, width, height, inPixels);
            filter(inPixels, outPixels, width, height);
            dest.getRaster().setDataElements(0, 0, width, height, outPixels);
            return(dest);
        }
예제 #24
0
        public void paint(Graphics g1)
        {
            Graphics2D g = (Graphics2D)g1;

            g.clipRect(0, 0, this.Width, m_height);
            g.clearRect(0, 0, this.Width, this.Height);
            if (m_credit_mode)
            {
                float times = (float)(((DateTime.Now).Subtract(m_scroll_started)).TotalSeconds) - 3f;
                float speed = (float)((2.0 - cadencii.math.erfc(times * 0.8)) / 2.0) * m_speed;
                float dt    = times - m_last_t;
                m_shift     += (speed + m_last_speed) * dt / 2f;
                m_last_t     = times;
                m_last_speed = speed;
                float dx = (this.Width - m_scroll.getWidth(null)) * 0.5f;
                if (m_scroll != null)
                {
                    g.drawImage(m_scroll, (int)dx, (int)(90f - m_shift), null);
                    if (90f - m_shift + m_scroll.getHeight(null) < 0)
                    {
                        m_shift = -m_height * 1.5f;
                    }
                }
                int       grad_height = 60;
                Rectangle top         = new Rectangle(0, 0, this.Width, grad_height);

                /*using ( LinearGradientBrush lgb = new LinearGradientBrush( top, Color.White, Color.Transparent, LinearGradientMode.Vertical ) ) {
                 *  g.FillRectangle( lgb, top );
                 * }*/
                Rectangle bottom = new Rectangle(0, m_height - grad_height, this.Width, grad_height);
                g.clipRect(0, m_height - grad_height + 1, this.Width, grad_height - 1);

                /*using ( LinearGradientBrush lgb = new LinearGradientBrush( bottom, Color.Transparent, Color.White, LinearGradientMode.Vertical ) ) {
                 *  g.FillRectangle( lgb, bottom );
                 * }*/
                g.setClip(null);
            }
            else
            {
                g.setFont(new Font("Century Gorhic", java.awt.Font.BOLD, 24));
                g.setColor(m_app_name_color);
                g.drawString(m_app_name, 20, 110);
                g.setFont(new Font("Arial", 0, 10));
                g.drawString("version " + m_version, 25, 150);
            }
        }
예제 #25
0
        private BufferedImage createColorImage(BufferedImage originalImage, int mask)
        {
            //BufferedImage colorImage = new BufferedImage(originalImage.getWidth(),
            //    originalImage.getHeight(), originalImage.getType());

            //for (int x = 0; x < originalImage.getWidth(); x++)
            //{
            //    for (int y = 0; y < originalImage.getHeight(); y++)
            //    {
            //        int pixel = originalImage.getRGB(x, y) & mask;
            //        colorImage.setRGB(x, y, pixel);
            //    }
            //}

            //return colorImage;


            ArrayList <BufferedImage> resultList = new ArrayList <BufferedImage>();
            List <CreateImageThread>  threads    = new List <CreateImageThread>();

            int imgChunkSize = 100;
            ArrayList <BufferedImage> images = this.splitImage(originalImage, imgChunkSize);

            for (int i = 0; i < images.ToList().Count; i++)
            {
                CreateImageThread thread = new CreateImageThread();
                thread.run(images.ElementAt(i), mask, resultList, i);
                threads.Add(thread);
            }
            foreach (CreateImageThread thread in threads)
            {
                thread.ToString();
            }

            BufferedImage resultImage   = new BufferedImage(originalImage.getWidth(), originalImage.getHeight(), originalImage.getType());
            int           howManyOnLine = (int)Math.Sqrt(resultList.ToList().Count);

            for (int i = 0; i < howManyOnLine; i++)
            {
                for (int j = 0; j < howManyOnLine; j++)
                {
                    resultImage.createGraphics().drawImage(resultList.ElementAt(i * howManyOnLine + j), imgChunkSize * i, imgChunkSize * j, null);
                }
            }
            return(resultImage);
        }
예제 #26
0
        /// <summary>
        /// Выполняет линейное контрастирование изображения
        /// </summary>
        /// <param name="bitmap">Передаваемое изображение</param>
        /// <returns></returns>
        public static Bitmap SetsContrans(Bitmap bitmap)
        {
            BufferedImage img = new BufferedImage(bitmap);
            Color         color;

            for (int i = 0; i < img.getWidth(); i++)
            {
                for (int j = 0; j < img.getHeight(); j++)
                {
                    color = new Color(img.getRGB(i, j));
                    int r = color.getRed();
                    int g = color.getGreen();
                    int b = color.getBlue();

                    if (r > 94)
                    {
                        r = 94;
                    }
                    else if (r < 28)
                    {
                        r = 28;
                    }
                    if (g > 94)
                    {
                        g = 94;
                    }
                    else if (g < 28)
                    {
                        g = 28;
                    }
                    if (b > 94)
                    {
                        b = 94;
                    }
                    else if (b < 28)
                    {
                        b = 28;
                    }

                    img.setRGB(i, j, new Color(r, g, b).getRGB());
                }
            }
            return(img.getBitmap());
        }
예제 #27
0
        public Benchmark(int resolution, bool showOutput, bool showBenchmarkOutput, bool saveOutput, int threads)
        {
            UI.set(this);
            this.resolution          = resolution;
            this.showOutput          = showOutput;
            this.showBenchmarkOutput = showBenchmarkOutput;
            this.saveOutput          = saveOutput;
            this.threads             = threads;
            errorThreshold           = 6;
            // fetch reference image from resources (jar file or classpath)
            if (saveOutput)
            {
                return;
            }
            URL imageURL = getResource(string.Format("/resources/golden_{0}.png", resolution));//fixme: add padding zeros

            if (imageURL == null)
            {
                UI.printError(UI.Module.BENCH, "Unable to find reference frame!");
            }
            UI.printInfo(UI.Module.BENCH, "Loading reference image from: {0}", imageURL);
            try
            {
                BufferedImage bi = ImageIO.read(imageURL);
                if (bi.getWidth() != resolution || bi.getHeight() != resolution)
                {
                    UI.printError(UI.Module.BENCH, "Reference image has invalid resolution! Expected {0}x{1} found {2}x{3}", resolution, resolution, bi.getWidth(), bi.getHeight());
                }
                referenceImage = new int[resolution * resolution];
                for (int y = 0, i = 0; y < resolution; y++)
                {
                    for (int x = 0; x < resolution; x++, i++)
                    {
                        referenceImage[i] = bi.getRGB(x, resolution - 1 - y); // flip
                    }
                }
            }
            catch (Exception e)
            {
                UI.printError(UI.Module.BENCH, "Unable to load reference frame!");
            }
        }
예제 #28
0
        /// <summary>
        /// Метод, для пороговой обработки изображения
        /// </summary>
        /// <param name="bitmap">позволяет считывать и сохранять файлы различных графических форматов</param>
        /// <param name="rRed"></param>
        /// <param name="rGreen"></param>
        /// <param name="rBlue"></param>
        /// <returns></returns>
        public static Bitmap ThresholdProcessing(Bitmap bitmap, int rRed, int rGreen, int rBlue)
        {
            BufferedImage img = new BufferedImage(bitmap);

            for (int i = 0; i < img.getWidth(); i++)
            {
                for (int j = 0; j < img.getHeight(); j++)
                {
                    Color color = new Color(img.getRGB(i, j));
                    int   red   = color.getRed();
                    int   green = color.getGreen();
                    int   blue  = color.getBlue();

                    red   = red <= rRed ? red : 0;
                    green = green <= rGreen ? green : 0;
                    blue  = blue <= rBlue ? blue : 0;

                    img.setRGB(i, j, new Color(red, green, blue).getRGB());
                }
            }
            return(img.getBitmap());
        }
예제 #29
0
        public RPFImage[] deproject(int frameNumber, BufferedImage frame)
        {
            if (frame == null)
            {
                String message = Logging.getMessage("nullValue.ImageSource");
                Logging.logger().severe(message);
                throw new ArgumentException(message);
            }

            PixelTransformer pt = (this.zoneCode == '9') ? northernPixels : southernPixels;

            RPFImage[] images;
            if (isDatelineSpanningFrame(frameNumber, pt))
            {
                if (pt == northernPixels)
                {
                    images = deprojectNorthernDatelineFrames(frameNumber, frame, pt);
                }
                else
                {
                    images = deprojectSouthernDatelineFrames(frameNumber, frame, pt);
                }
            }
            else
            {
                // non-dateline spanning frames are more straightforward...
                Sector        sector    = computeFrameCoverage(frameNumber);
                BufferedImage destImage = new BufferedImage(frame.getWidth(), frame.getHeight(),
                                                            BufferedImage.TYPE_4BYTE_ABGR);
                resampleFrameFile(sector, frame, destImage, frameNumber, pt);
                images    = new RPFImage[1];
                images[0] = new RPFImage(sector, destImage);
            }

            return(images);
        }
예제 #30
0
        public static string makeGraphicHTML(string paramString1, string paramString2)
        {
            string str = "http://www.costdatabase.eu/rsmeans/as/graphics/" + paramString1 + ".PNG";
            int    i   = 0;
            int    j   = 0;
            char   c1  = 'Ȯ';
            char   c2  = 'Ǵ';
            char   c3  = (char)(c1 / '\x0002' - '2');

            try
            {
                BufferedImage bufferedImage = ImageIO.read(new URL(str));
                Dimension     dimension     = new Dimension(c1, c2);
                i = bufferedImage.getWidth(null);
                j = bufferedImage.getHeight(null);
                float f = i / j;
                if ((char)i > c1 || (char)j > c2)
                {
                    if (dimension.width / dimension.height > f)
                    {
                        dimension.width = (int)Math.Ceiling((dimension.height * f));
                    }
                    else
                    {
                        dimension.height = (int)Math.Ceiling((dimension.width / f));
                    }
                    i = dimension.width;
                    j = dimension.height;
                }
            }
            catch (Exception)
            {
                i = 0;
                j = 0;
            }
            StringBuilder stringBuffer = new StringBuilder();

            if (i == 0 || (char)i > c3)
            {
                stringBuffer.Append("<html>");
                if (i != 0)
                {
                    stringBuffer.Append("<div>");
                    stringBuffer.Append("<a href=\"http://www.costdatabase.eu/rsmeans/as/graphics/" + paramString1 + ".PDF\"><img src=\"" + str + "\" width=\"" + i + "\" height=\"" + j + "\"  border=\"0\"></a>");
                    stringBuffer.Append("</div>");
                }
                if (!StringUtils.isNullOrBlank(paramString2))
                {
                    stringBuffer.Append("<div width=\"400px\">");
                    stringBuffer.Append("<font color=\"black\" face=\"Arial\" size=\"2\">");
                    stringBuffer.Append("<br/>");
                    stringBuffer.Append(paramString2);
                    stringBuffer.Append("</font>");
                    stringBuffer.Append("</div>");
                }
                stringBuffer.Append("</html>");
            }
            else
            {
                stringBuffer.Append("<html>");
                stringBuffer.Append("<table border=0 width=\"558\">");
                stringBuffer.Append("<tr><td>");
                stringBuffer.Append("<a href=\"http://www.costdatabase.eu/rsmeans/as/graphics/" + paramString1 + ".PDF\"><img src=\"" + str + "\" width=\"" + i + "\" height=\"" + j + "\"  border=\"0\"></a>");
                stringBuffer.Append("</td><td valign=\"top\">");
                stringBuffer.Append("<font face=\"Arial\" size=\"2\">");
                stringBuffer.Append(paramString2);
                stringBuffer.Append("</font></td></tr></table>");
                stringBuffer.Append("</html>");
            }
            return(stringBuffer.ToString());
        }