public FastDisplay() { image = null; frame = null; t = new Timer(); frames = 0; seconds = 0; }
public ImagePanel() { setPreferredSize(new Dimension(640, 480)); image = null; xo = yo = 0; w = h = 0; ScrollZoomListener listener = new ScrollZoomListener(); addMouseListener(listener); addMouseMotionListener(listener); addMouseWheelListener(listener); }
public virtual BufferedImage processImage(BufferedImage image) { width = image.Width; height = image.Height; originalImage = image; filteredImage = new BufferedImage(newWidth, newHeight, image.Type); int startH = createStartH(); int startW = createStartW(); int endH = createEndH(); int endW = createEndW(); fillImage(startH, startW, endH, endW); return(filteredImage); }
/// <summary> /// This method cleans input image by replacing all pixels with RGB values /// from -3092272 (light gray) to -1 (white) with white pixels and from /// -3092272 (light gray) to -16777216 (black) with black pixels /// </summary> /// <param name="image"> - input image that will be cleaned </param> /// <returns> - cleaned input image as BufferedImage </returns> public static BufferedImage blackAndLightGrayCleaning(BufferedImage image) { for (int j = 0; j < image.Height; j++) { for (int i = 0; i < image.Width; i++) { if (image.getRGB(i, j) > -4473925) { image.setRGB(i, j, -1); } else { image.setRGB(i, j, -16777216); } } } return(image); }
/// <summary> /// This method cleans input image by replacing all pixels with RGB values /// from RGBcolor input (the input color) to -1 (white) with white pixels and /// from RGBcolor input (the input color) to -16777216 (black) with black /// pixels /// </summary> /// <param name="image"> - input image that will be cleaned </param> /// <param name="RGBcolor"> - input RGB value of wanted color as reference for /// celaning </param> /// <returns> - cleaned input image as BufferedImage </returns> public static BufferedImage colorCleaning(BufferedImage image, int RGBcolor) { for (int j = 0; j < image.Height; j++) { for (int i = 0; i < image.Width; i++) { if (image.getRGB(i, j) == RGBcolor) { image.setRGB(i, j, -16777216); } else { image.setRGB(i, j, -1); } } } return(image); }
/// <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()); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: public static void resizeImageAndSave(String paramString1, String paramString2, int paramInt1, int paramInt2) throws java.io.IOException public static void resizeImageAndSave(string paramString1, string paramString2, int paramInt1, int paramInt2) { BufferedImage bufferedImage = resizeImage(paramString1, paramInt1, paramInt2); sbyte b = 0; if (paramString1.ToLower().EndsWith(".png", StringComparison.Ordinal)) { b = 1; } else if (paramString1.ToLower().EndsWith(".gif", StringComparison.Ordinal)) { b = 3; } else { b = 0; } saveImage(bufferedImage, paramString2, 1); }
// hitoram from otsu method for grayscae dimage public virtual int[] imageHistogram(BufferedImage image) { int[] histogram = new int[256]; for (int i = 0; i < histogram.Length; i++) { histogram[i] = 0; } for (int i = 0; i < image.Width; i++) { for (int j = 0; j < image.Height; j++) { int gray = (new Color(image.getRGB(i, j))).Red; histogram[gray]++; } } return(histogram); }
public virtual BufferedImage processImage(BufferedImage image) { originalImage = image; width = originalImage.Width; height = originalImage.Height; prepare(); //JAVA TO C# CONVERTER NOTE: The following call to the 'RectangularArrays' helper class reproduces the rectangular array initialization that is automatic in Java: //ORIGINAL LINE: visited = new bool[height][width]; visited = RectangularArrays.ReturnRectangularBoolArray(height, width); int color; int white = 255; for (int line = 0; line < linePositions.Length; line++) { for (int k = -1; k <= 1; k++) { int i = linePositions[line] + k; if (i == -1 || i == height) { continue; } // for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { color = (new Color(originalImage.getRGB(j, i))).Red; if (color == white) { visited[i][j] = true; } else { BFStraverseAndSave(i, j); } } } } return(originalImage); }
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!"); } }
public static BufferedImage binary(string textImageFile) { // load and convert the image into a usable format BufferedImage image = UtilImageIO.loadImage(textImageFile); // convert into a usable format ImageFloat32 input = ConvertBufferedImage.convertFromSingle(image, null, typeof(ImageFloat32)); ImageUInt8 binary = new ImageUInt8(input.width, input.height); ImageSInt32 label = new ImageSInt32(input.width, input.height); // Select a global threshold using Otsu's method. double threshold = GThresholdImageOps.computeOtsu(input, 0, 256); // Apply the threshold to create a binary image ThresholdImageOps.threshold(input, binary, (float)threshold, true); // remove small blobs through erosion and dilation // The null in the input indicates that it should internally declare the work image it needs // this is less efficient, but easier to code. ImageUInt8 filtered = BinaryImageOps.erode8(binary, 1, null); filtered = BinaryImageOps.dilate8(filtered, 1, null); // get the binary image BufferedImage visualFiltered = VisualizeBinaryData.renderBinary(filtered, null); //write the negative image to a file File charFile = new File("whiteandblack.png"); try { ImageIO.write(visualFiltered, "png", charFile); } catch (IOException ex) { //JAVA TO C# CONVERTER WARNING: The .NET Type.FullName property will not always yield results identical to the Java Class.getName method: Logger.getLogger(typeof(BinaryOps).FullName).log(Level.SEVERE, null, ex); } //return the positive image return(invertImage("whiteandblack.png")); }
public virtual BufferedImage processImage(BufferedImage image) { originalImage = image; int width = originalImage.Width; int height = originalImage.Height; filteredImage = new BufferedImage(width, height, originalImage.Type); int[] histogram = imageHistogram(originalImage); int[] histogramCumulative = new int[histogram.Length]; histogramCumulative[0] = histogram[0]; for (int i = 1; i < histogramCumulative.Length; i++) { histogramCumulative[i] = histogramCumulative[i - 1] + histogram[i]; } int G = 256; int gray; int alpha; int newColor; for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { gray = (new Color(originalImage.getRGB(i, j))).Red; alpha = (new Color(originalImage.getRGB(i, j))).Alpha; newColor = (G - 1) * histogramCumulative[gray] / (width * height); //zaokruziti izbeci celobrojno deljenje newColor = ImageUtilities.colorToRGB(alpha, newColor, newColor, newColor); filteredImage.setRGB(i, j, newColor); } } return(filteredImage); }
/// <summary> /// Crop the part of an image with a white rectangle /// </summary> /// <returns> A cropped image File </returns> public virtual File crop(BufferedImage image) { // this will be coordinates of the upper left white pixel int upperLeftCornerx = int.MaxValue; int upperLeftCornery = int.MaxValue; //this will be coordinates of the lower right white pixel int lowerRightCornerx = int.MinValue; int lowerRightCornery = int.MinValue; //find the minimum and maximum white pixel coordinates for (int i = 0; i < image.Width; i++) { for (int j = 0; j < image.Height; j++) { if (image.getRGB(i, j) == WHITE.RGB && (i < upperLeftCornerx && j < upperLeftCornery) || (i <= upperLeftCornerx && j < upperLeftCornery) || (i < upperLeftCornerx && j <= upperLeftCornery)) { upperLeftCornerx = i; upperLeftCornery = j; } if (image.getRGB(i, j) == WHITE.RGB && ((i > lowerRightCornerx && j >= lowerRightCornery) || (i >= lowerRightCornerx && j > lowerRightCornery) || (i > lowerRightCornerx && j >= lowerRightCornery))) { lowerRightCornerx = i; lowerRightCornery = j; } } } //crop the image to the white rectangle size BufferedImage croppedImage = image.getSubimage(upperLeftCornerx, upperLeftCornery, lowerRightCornerx - upperLeftCornerx, lowerRightCornery - upperLeftCornery); //make a file from that cropped image File cropFile = new File("croppedimage.png"); try { ImageIO.write(croppedImage, "png", cropFile); } catch (IOException ex) { //JAVA TO C# CONVERTER WARNING: The .NET Type.FullName property will not always yield results identical to the Java Class.getName method: Logger.getLogger(typeof(OcrDemo).FullName).log(Level.SEVERE, null, ex); } return(cropFile); }
/// <summary> /// Extracts and returns char images to recognize as list of images </summary> /// <returns> </returns> public virtual List <BufferedImage> extractCharImagesToRecognize() { List <BufferedImage> trimedImages = new List <BufferedImage>(); int i = 0; while (endOfImage == false) { endOfRow = false; bool foundTop = findCropTopY(); bool foundBottom = false; if (foundTop == true) { foundBottom = findCropBottomY(); if (foundBottom == true) { while (endOfRow == false) { bool foundLeft = false; bool foundRight = false; foundLeft = findCropLeftX(); if (foundLeft == true) { foundRight = findCropRightX(); if (foundRight == true) { BufferedImage image = ImageUtilities.trimImage(ImageUtilities.cropImage(imageWithChars, cropLeftX, cropTopY, cropRightX, cropBottomY)); trimedImages.Add(image); i++; } } } cropLeftX = 0; cropRightX = 0; } } } cropTopY = 0; cropBottomY = 0; endOfImage = false; return(trimedImages); }
public static BufferedImage getJChart() { BufferedImage bufferedImage = null; try { //string reports_dir = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "reports"); //string fileName = System.IO.Path.Combine(reports_dir, "AreaChart.jpg"); //bufferedImage = ImageIO.read(new File(fileName)); AreaChartProperties areaChartProperties = new AreaChartProperties(); double[][] data = new double[][] { new double[] { 10, 15, 30, 53 }, new double[] { 6, 30, 10, 21 }, new double[] { 20, 25, 20, 8 } }; Paint[] paints = { new Color(0, 255, 0, 100), new Color(255, 0, 0, 100), new Color(0, 0, 255, 100) }; String[] legendLabels = { "Games", "Events", "Players" }; AxisChartDataSet axisChartDataSet = new AxisChartDataSet(data, legendLabels, paints, ChartType.AREA, areaChartProperties); String[] axisLabels = { "January", "March", "May", "June" }; DataSeries dataSeries = new DataSeries(axisLabels, "Months", "People", "Popular Events"); dataSeries.addIAxisPlotDataSet(axisChartDataSet); ChartProperties chartProperties = new ChartProperties(); AxisProperties axisProperties = new AxisProperties(); axisProperties.setYAxisRoundValuesToNearest(0); LegendProperties legendProperties = new LegendProperties(); AxisChart axisChart = new AxisChart(dataSeries, chartProperties, axisProperties, legendProperties, 500, 350); bufferedImage = new BufferedImage(500, 350, BufferedImage.TYPE_INT_RGB); axisChart.setGraphics2D(bufferedImage.createGraphics()); axisChart.render(); } catch (ChartDataException chartDataException) { throw new JRScriptletException(chartDataException); } return(bufferedImage); }
public Picture(int i1, int i2) { this.isOriginUpperLeft = true; if (i1 < 0) { string arg_1D_0 = "width must be nonnegative"; throw new ArgumentException(arg_1D_0); } if (i2 < 0) { string arg_31_0 = "height must be nonnegative"; throw new ArgumentException(arg_31_0); } this.width = i1; this.height = i2; this.image = new BufferedImage(i1, i2, 1); this.filename = new StringBuilder().append(i1).append("-by-").append(i2).toString(); }
public virtual BufferedImage processImage(BufferedImage image) { originalImage = image; int width = originalImage.Width; int height = originalImage.Height; filteredImage = new BufferedImage(width, height, originalImage.Type); OtsuBinarizeFilter obf = new OtsuBinarizeFilter(); BufferedImage tempImage = obf.processImage(originalImage); int gray; int alpha; int discreteColor; int newColor; int white = 255; for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { gray = (new Color(originalImage.getRGB(i, j))).Red; alpha = (new Color(originalImage.getRGB(i, j))).Alpha; discreteColor = (new Color(tempImage.getRGB(i, j))).Red; if (discreteColor == white) { newColor = gray; } else { newColor = white; } newColor = ImageUtilities.colorToRGB(alpha, newColor, newColor, newColor); filteredImage.setRGB(i, j, newColor); } } return(filteredImage); }
public virtual BufferedImage getUnsharpMask(BufferedImage originalImage, BufferedImage bluredImage) { int width = originalImage.Width; int height = originalImage.Height; BufferedImage unsharpMask = new BufferedImage(width, height, originalImage.Type); for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { int originalColor = (new Color(originalImage.getRGB(i, j))).Red; int blurColor = (new Color(bluredImage.getRGB(i, j))).Red; int alpha = (new Color(originalImage.getRGB(i, j))).Alpha; int newColor = originalColor - blurColor; int rgb = ImageUtilities.colorToRGB(alpha, newColor, newColor, newColor); unsharpMask.setRGB(i, j, rgb); } } return(unsharpMask); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: public static String uploadServerIcon(byte[] paramArrayOfByte, String paramString, Class paramClass) throws Exception public static string uploadServerIcon(sbyte[] paramArrayOfByte, string paramString, Type paramClass) { if (paramString.IndexOf(".", StringComparison.Ordinal) == -1) { throw new System.ArgumentException("Invalid image file name: " + paramString); } File file1 = new File(SERVER_ICON_DB_FOLDER + paramClass.Name.ToLower()); if (!file1.exists()) { file1.mkdirs(); } sbyte b = 1; if (paramString.ToLower().EndsWith(".png", StringComparison.Ordinal)) { b = 1; } else if (paramString.ToLower().EndsWith(".gif", StringComparison.Ordinal)) { b = 3; } else { b = 0; } BufferedImage bufferedImage = ImageUtils.imageFromBytes(b, paramArrayOfByte); string str1 = paramString.Substring(0, paramString.LastIndexOf(".", StringComparison.Ordinal)); string str2 = getServerPathOfIcon(str1, paramClass, 16); File file2 = new File(str2); ImageUtils.resizeImageAndSave(bufferedImage, b, file2.AbsolutePath, 16, 16); str2 = getServerPathOfIcon(str1, paramClass, 24); file2 = new File(str2); ImageUtils.resizeImageAndSave(bufferedImage, b, file2.AbsolutePath, 24, 24); str2 = getServerPathOfIcon(str1, paramClass, 32); file2 = new File(str2); ImageUtils.resizeImageAndSave(bufferedImage, b, file2.AbsolutePath, 32, 32); return(str1); }
private static void MPIWorker() { ArrayList <ImageIcon> imageChunksIcon = Communicator.world.Receive <ArrayList <ImageIcon> >(0, 0); int mask = Communicator.world.Receive <int>(0, 0); ArrayList <BufferedImage> imageChunks = new ArrayList <BufferedImage>(); foreach (ImageIcon image in imageChunksIcon) { imageChunks.Add(convertToBufferedImage(image.getImage())); } List <BufferedImage> results = new List <BufferedImage>(20); int k = 0; foreach (BufferedImage imageChunk in imageChunks) { 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); } } results.Add(colorImage); } ArrayList <ImageIcon> resultsIcons = new ArrayList <ImageIcon>(20); for (int i = 0; i < results.Count; i++) { resultsIcons.Add(new ImageIcon(results[i])); } Communicator.world.Send(resultsIcons, 0, 0); }
/// /// <summary> /// Inverts the image colors from negative to positive /// </summary> /// <returns> the image with inverted colors </returns> public static BufferedImage invertImage(string imageName) { // read the image file BufferedImage inputFile = null; try { inputFile = ImageIO.read(new File(imageName)); } catch (IOException e) { Console.WriteLine(e.ToString()); Console.Write(e.StackTrace); } // go through image pixels and reverse their color for (int x = 0; x < inputFile.Width; x++) { for (int y = 0; y < inputFile.Height; y++) { int rgba = inputFile.getRGB(x, y); Color col = new Color(rgba, true); col = new Color(255 - col.Red, 255 - col.Green, 255 - col.Blue); inputFile.setRGB(x, y, col.RGB); } } //write the image to a file blackandwhite.png try { File outputFile = new File("blackandwhite.png"); ImageIO.write(inputFile, "png", outputFile); } catch (IOException e) { Console.WriteLine(e.ToString()); Console.Write(e.StackTrace); } return(inputFile); }
/// <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()); }
private void displayWeight(List <double?> currentKernel) { JFrame frame = new JFrame("Weight Visualiser: "); frame.setSize(400, 400); JLabel label = new JLabel(); Dimension d = new Dimension(kernel.Width * RATIO, kernel.Height * RATIO); label.Size = d; label.PreferredSize = d; frame.ContentPane.add(label, BorderLayout.CENTER); frame.pack(); frame.Visible = true; BufferedImage image = new BufferedImage(kernel.Width, kernel.Height, BufferedImage.TYPE_BYTE_GRAY); int[] rgb = convertWeightToRGB(currentKernel); image.setRGB(0, 0, kernel.Width, kernel.Height, rgb, 0, kernel.Width); label.Icon = new ImageIcon(image.getScaledInstance(kernel.Width * RATIO, kernel.Height * RATIO, Image.SCALE_SMOOTH)); }
public static BufferedImage getJFreeChart() { BufferedImage bufferedImage = null; try { //string reports_dir = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "reports"); //string fileName = System.IO.Path.Combine(reports_dir, "AreaChart.jpg"); //bufferedImage = ImageIO.read(new File(fileName)); DefaultPieDataset dataset = new DefaultPieDataset(); dataset.setValue("Java", 43.2); dataset.setValue("Visual Basic", 10.0); dataset.setValue("C/C++", 17.5); dataset.setValue("PHP", 32.5); dataset.setValue("Perl", 1.0); JFreeChart chart = ChartFactory.createPieChart3D( "Pie Chart 3D Demo 1", dataset, true, true, false ); PiePlot3D plot = (PiePlot3D)chart.getPlot(); plot.setStartAngle(290); plot.setDirection(Rotation.CLOCKWISE); plot.setForegroundAlpha(0.5f); plot.setNoDataMessage("No data to display"); /* */ bufferedImage = chart.createBufferedImage(515, 350); } catch (Exception ex) { throw ex; } return(bufferedImage); }
/// <param name="image"> binarized image, letters are black, background is white </param> /// <returns> array which length is width of image, every element of array /// represent count of black pixels in that column of pixels. </returns> public static int[] widthHistogram(BufferedImage image) { int height = image.Height; int width = image.Width; int[] histogram = new int[width]; int black = 0; int color; for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { color = (new Color(image.getRGB(i, j))).Red; if (color == black) { histogram[i]++; } } } return(histogram); }
/// <summary> /// Creates a graphics context (as a <seealso cref="Graphics2D"/> object) for the splash /// screen overlay image, which allows you to draw over the splash screen. /// Note that you do not draw on the main image but on the image that is /// displayed over the main image using alpha blending. Also note that drawing /// on the overlay image does not necessarily update the contents of splash /// screen window. You should call {@code update()} on the /// <code>SplashScreen</code> when you want the splash screen to be /// updated immediately. /// <para> /// The pixel (0, 0) in the coordinate space of the graphics context /// corresponds to the origin of the splash screen native window bounds (see /// <seealso cref="#getBounds()"/>). /// /// </para> /// </summary> /// <returns> graphics context for the splash screen overlay surface </returns> /// <exception cref="IllegalStateException"> if the splash screen has already been closed </exception> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public Graphics2D createGraphics() throws IllegalStateException public Graphics2D CreateGraphics() { lock (typeof(SplashScreen)) { CheckVisible(); if (Image == null) { // get unscaled splash image size Dimension dim = _getBounds(SplashPtr).Size; Image = new BufferedImage(dim.Width_Renamed, dim.Height_Renamed, BufferedImage.TYPE_INT_ARGB); } float scale = _getScaleFactor(SplashPtr); Graphics2D g = Image.CreateGraphics(); assert(scale > 0); if (scale <= 0) { scale = 1; } g.Scale(scale, scale); return(g); } }
/// <summary> /// Encodes and writes multiple images without colour depth conversion. /// </summary> /// <param name="images"> /// the list of source images to be encoded </param> /// <param name="stream"> /// the output to which the encoded image will be written </param> internal void Write(java.util.List images, System.IO.Stream stream) { writer = new BinaryWriter(stream); int count = images.size(); // file header 6 WriteFileHeader(count, TYPE_ICON); // file offset where images start int fileOffset = 6 + count * 16; // icon entries 16 * count for (int i = 0; i < count; i++) { BufferedImage imgc = (BufferedImage)images.get(i); fileOffset += WriteIconEntry(imgc, fileOffset); } // images for (int i = 0; i < count; i++) { BufferedImage imgc = (BufferedImage)images.get(i); // info header WriteInfoHeader(imgc); // color map if (imgc.getColorModel().getPixelSize() <= 8) { IndexColorModel icm = (IndexColorModel)imgc.getColorModel(); WriteColorMap(icm); } // xor bitmap WriteXorBitmap(imgc); // and bitmap WriteAndBitmap(imgc); } }
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); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: public static void saveCompressedImage(java.awt.image.BufferedImage paramBufferedImage, String paramString, int paramInt) throws java.io.IOException public static void saveCompressedImage(BufferedImage paramBufferedImage, string paramString, int paramInt) { if (paramInt == 1) { throw new System.NotSupportedException("PNG compression not implemented"); } ImageWriter imageWriter = null; System.Collections.IEnumerator iterator = ImageIO.getImageWritersByFormatName("jpg"); //JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops: imageWriter = (ImageWriter)iterator.next(); ImageOutputStream imageOutputStream = ImageIO.createImageOutputStream(new File(paramString)); imageWriter.Output = imageOutputStream; JPEGImageWriteParam jPEGImageWriteParam = new JPEGImageWriteParam(Locale.Default); jPEGImageWriteParam.CompressionMode = 2; jPEGImageWriteParam.CompressionQuality = 0.7F; imageWriter.write(null, new IIOImage(paramBufferedImage, null, null), jPEGImageWriteParam); imageOutputStream.flush(); imageWriter.dispose(); imageOutputStream.close(); }
private void saveToFile(BufferedImage img, string letterName) { File outputfile = new File(location + letterName + ".png"); BufferedImage crop = img; if (cropHeight != 0 || cropWidth != 0) { OCRCropImage ci = new OCRCropImage(); ci.setDimension(cropWidth, cropHeight); crop = ci.processImage(img); } try { ImageIO.write(crop, "png", outputfile); } catch (IOException ex) { Console.WriteLine(ex.ToString()); Console.Write(ex.StackTrace); } }
public static void extractImageFromPDF(string paramString1, string paramString2, string paramString3) { try { if (!Directory.Exists(paramString2) || File.Exists(paramString2)) { Directory.CreateDirectory(paramString2); } Document document = new Document(); document.File = paramString1; System.Collections.IList list = document.getPageImages(0); foreach (Image image in list) { if (image != null) { BufferedImage bufferedImage = (BufferedImage)image; try { File file = new File(paramString2 + File.separator + paramString3 + ".PNG"); ImageIO.write(bufferedImage, "png", file); } catch (IOException iOException) { Console.WriteLine(iOException.ToString()); Console.Write(iOException.StackTrace); } image.flush(); } } document.dispose(); } catch (Exception exception) { Console.WriteLine(exception.ToString()); Console.Write(exception.StackTrace); } }
public static sbyte[] imageToBase64(ImageIcon paramImageIcon, int paramInt) { try { string str = "jpg"; if (paramInt == 1) { str = "png"; } else if (paramInt == 3) { str = "gif"; } BufferedImage bufferedImage = (BufferedImage)paramImageIcon.Image; MemoryStream byteArrayOutputStream = new MemoryStream(); ImageIO.write(bufferedImage, str, byteArrayOutputStream); sbyte[] arrayOfByte = byteArrayOutputStream.toByteArray(); return(Base64.encode(arrayOfByte)); } catch (IOException) { return(null); } }
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(); } }
/** * Renders a <code>BufferedImage</code> that is * filtered with a * {@link BufferedImageOp}. * The rendering attributes applied include the <code>Clip</code>, * <code>Transform</code> * and <code>Composite</code> attributes. This is equivalent to: * <pre> * img1 = op.filter(img, null); * DrawImage(img1, new AffineTransform(1f,0f,0f,1f,x,y), null); * </pre> * @param img the <code>BufferedImage</code> to be rendered * @param op the filter to be applied to the image before rendering * @param x the x coordinate in user space where the image is rendered * @param y the y coordinate in user space where the image is rendered * @see #_transform * @see #setTransform * @see #setComposite * @see #clip * @see #setClip(Shape) */ public void DrawImage(BufferedImage img, BufferedImageOp op, int x, int y){ img = op.filter(img, null); DrawImage(img, x, y, null); }
void setChart( BufferedImage chart ) { this.chart = chart; }
public void DrawImage(BufferedImage bufferedimage, BufferedImageOp op, int x, int y) { BufferedImage img = op.filter(bufferedimage, null); DrawImage(((Image) (img)), new AffineTransform(1.0F, 0.0F, 0.0F, 1.0F, x, y), null); }
public void DrawRenderedImage(RenderedImage renderedimage, AffineTransform affinetransform) { BufferedImage bufferedimage = new BufferedImage(renderedimage.GetColorModel(), renderedimage.GetData().CreateCompatibleWritableRaster(), false, null); bufferedimage.SetData(renderedimage.GetData()); DrawImage(bufferedimage, affinetransform, null); }
public override void DrawLine(Vector2Df Start, Vector2Df End) { if(m_LineImageCache == null) { //m_LineImageCache = new BufferedImage(4, 1, BufferedImage.PixelType.INT_ARGB); //renderer.FillRect(1, 0, 1, 1); m_LineImageCache = new BufferedImage(4, 4, BufferedImage.PixelType.INT_ARGB); Renderer2D renderer = m_LineImageCache.GetRenderer2D; renderer.Color.AlphaI = 0; renderer.FillRect(0, 0, 4, 4); renderer.Color.AlphaI = 255; renderer.FillRect(1, 2, 1, 2); #if false // Fill in the rest of the pixels for testing renderer.Color.RedI = 0; renderer.FillRect(0, 0, 4, 1); renderer.FillRect(3, 0, 1, 4); renderer.Color.BlueI = 0; renderer.FillRect(0, 1, 1, 3); renderer.FillRect(0, 1, 3, 1); renderer.FillRect(2, 1, 1, 3); #endif } ImageGLDisplayListPlugin GLBuffer = ImageGLDisplayListPlugin.GetImageGLDisplayListPlugin(m_LineImageCache); Gl.glEnable(Gl.GL_TEXTURE_2D); Gl.glEnable(Gl.GL_BLEND); Gl.glBlendFunc(Gl.GL_SRC_ALPHA, Gl.GL_ONE_MINUS_SRC_ALPHA); Gl.glColor4f(m_Color.RedF, m_Color.GreenF, m_Color.BlueF, m_Color.AlphaF); Vector2Df Normal = (End - Start); Vector2Df PerpendicularNormal = Normal.GetPerpendicularNormal(); float Width = 1; Vector2Df OffsetPos = PerpendicularNormal * Width; Vector2Df OffsetNeg = PerpendicularNormal * -(Width + 1); PushOrthoProjection(); Gl.glBindTexture(Gl.GL_TEXTURE_2D, GLBuffer.GLTextureHandle); Gl.glBegin(Gl.GL_QUADS); #if true Gl.glTexCoord2d(0, .75); Gl.glVertex2f(Start.x + OffsetPos.x, Start.y + OffsetPos.y); Gl.glTexCoord2d(0, 1); Gl.glVertex2f(End.x + OffsetPos.x, End.y + OffsetPos.y); Gl.glTexCoord2d(.75, 1); Gl.glVertex2f(End.x + OffsetNeg.x, End.y + OffsetNeg.y); Gl.glTexCoord2d(.75, .5); Gl.glVertex2f(Start.x + OffsetNeg.x, Start.y + OffsetNeg.y); #else // draw the main line (without the tips) Gl.glTexCoord2d(0, .75); Gl.glVertex2f(Start.x + OffsetPos.x + Normal.x, Start.y + OffsetPos.y + Normal.y); Gl.glTexCoord2d(0, 1); Gl.glVertex2f(End.x + OffsetPos.x - Normal.x, End.y + OffsetPos.y - Normal.y); Gl.glTexCoord2d(.75, 1); Gl.glVertex2f(End.x + OffsetNeg.x - Normal.x, End.y + OffsetNeg.y - Normal.y); Gl.glTexCoord2d(.75, .5); Gl.glVertex2f(Start.x + OffsetNeg.x + Normal.x, Start.y + OffsetNeg.y + Normal.y); // draw the ending tip anti-aliased Gl.glTexCoord2d(0, 1); Gl.glVertex2f(End.x + OffsetPos.x - Normal.x, End.y + OffsetPos.y - Normal.y); Gl.glTexCoord2d(0, .25); Gl.glVertex2f(End.x + OffsetPos.x, End.y + OffsetPos.y); Gl.glTexCoord2d(.75, .25); Gl.glVertex2f(End.x + OffsetNeg.x, End.y + OffsetNeg.y); Gl.glTexCoord2d(.75, 1); Gl.glVertex2f(End.x + OffsetNeg.x - Normal.x, End.y + OffsetNeg.y - Normal.y); // draw the starting tip anti-aliased Gl.glTexCoord2d(0, .25); Gl.glVertex2f(Start.x + OffsetPos.x, Start.y + OffsetPos.y); Gl.glTexCoord2d(0, 1); Gl.glVertex2f(Start.x + OffsetPos.x + Normal.x, Start.y + OffsetPos.y + Normal.y); Gl.glTexCoord2d(.75, 1); Gl.glVertex2f(Start.x + OffsetNeg.x + Normal.x, Start.y + OffsetNeg.y + Normal.y); Gl.glTexCoord2d(.75, .25); Gl.glVertex2f(Start.x + OffsetNeg.x, Start.y + OffsetNeg.y); #endif Gl.glColor4f(1, 1, 1, 1); Gl.glEnd(); PopOrthoProjection(); }
public void imageBegin(int w, int h, int bucketSize) { lock (lockObj) { if (image != null && w == image.getWidth() && h == image.getHeight()) { // dull image if it has same resolution (75%) for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { int rgb = image.getRGB(x, y); image.setRGB(x, y, ((uint)(rgb & 0x00FEFEFE) >> 1) + ((uint)(rgb & 0x00FCFCFC) >> 2));//>>> } } } else { // allocate new framebuffer image = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); // center this.w = w; this.h = h; xo = yo = 0; } repaintCounter = NanoTime.Now; repaint(); } }