Posts

Program to convert base64 to Image and vice versa

Code snippet: This method decodes the base64 string into the bytes and converts it into an image .      * Note: this method expects input to be an encoded Image in base64 format. It can't work with other other files encoded in base64 format ByteArrayInputStream bis = new ByteArrayInputStream(Base64.getDecoder().decode(base64data)); BufferedImage img = ImageIO.read(bis); bis.close(); This method encodes the PNG image to base64 format ByteArrayOutputStream output = new ByteArrayOutputStream(); ImageIO.write(image, "PNG", output); String encodedString = Base64.getEncoder().encodeToString(output.toByteArray()); output.close();

Program to convert image byte array to PDF

Simple sample program to convert image byte array to PDF         //input path. path where byte array is saved         String pathOfByteArrayFile = "/home/inputByteArray.txt";         //output path. path where rendered you need to save . Output PDF should render properly         String outputPDFPath = "/home/output.pdf";         try         {             File file = new File(pathOfByteArrayFile);             FileOutputStream fout = new FileOutputStream(outputPDFPath);             byte[] bArray = Base64.decode(FileUtils.readFileToByteArray(file));             fout.write(bArray);             fout.close();             assertFalse(false);         }         catch (Exception e)         {             //your logic for failure         }

Image Management in Cloud

Folks, I came across a nice website where image management and manipulation is very easy. (http://cloudinary.com/) Please take time to explore this with free account. You can resize image just by specifying the image URL with size. Similarly many other features it support. Please explore this and let me know if any clarifications needed. Meanwhile you can reply me through comments if you know better image management sites in cloud. Thanks folks!!!

Vector Graphics - Part 3

To recap, lets see the difference between vector graphics and Bitmaps. As vectors are defined through mathematical equations, its graphical file too is constructed from mathematical equations. Greatest advantage of this is that they can be refined to any level without losing clarity. Some of the Vector files prevalent in market : PDF,SVG, Adope Illustrator, PostScript etc. Bitmap is something which is purely constructed from pixels. Advantage of this is since pixels are used here, we can use these files in photoshop and edit. But obviously loses clarity. Some of the bitmap files prevalent in market : JPEG,PNG,GIF etc.

Vector Graphics - Part 2

Vector graphics is normally used in context of 2D rather than 3D. In this blog, we will see how vector graphics is used in devices such as printers to print an image or a PDF. We will take the example of PS(Post Script) printer. Right now in market there are many varieties of printers are available. Example: dot-matrix printers, laser printers. In this case, we will take the example of post script PDF printers. Firstly, what is a post script printer? It is a driver needs to be installed in the printer to recognize PDF. Once the driver installed, the bit stream which application(Java here), will be rendered by printers using vector graphics and print the page. PDF is an example of vector graphics. You can scale it to whatever size and it will remain as it is. In next blog, we will see what is difference between vectors and bitmaps and types of files printers render using these complex features.

Vector Graphics - Basic 1

Use of geometrical primitives such as lines, curves, points, polygons etc. (which can be mathematically derived) to represent image constitute Vector graphics. As name suggests Vector Graphics constitute of Vectors(location points) and graphics(images). Reader must know vectors before he understands this implementation. (Vector represented by V with an arrow mark at the top.). Each of these vectors has a definite position on the multidimensional plane and determines the direction of the path. Also each path may be assigned a colour, texture, shape, contrast or thickness. Right now, the standard followed is Scalable Vector Graphics (SVG), recommended by The World Wide Web Consortium (W3C).

Vectorization

Conversion of raster graphics into vector graphics is known as Vectorization  or Image tracing. Classic example is when satellite captures images, they cectorize it to create maps. There are many algorithms for Vectorization. There is no single defined clear cut algorithm for this. Some of them are 1) Sobel 2) Canny Edge 3) Roberts Cross 4) Sparse Pixel 5) MaxDistanceVectorizer 6) LineVectorizer 7) DirectionBasedVectorizer