Sanjeev MutalikDesai

Greenhorn
+ Follow
since Aug 25, 2005
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Sanjeev MutalikDesai

import java.io.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Iterator;

import javax.imageio.IIOImage;
import javax.imageio.ImageIO;
import javax.imageio.ImageTypeSpecifier;
import javax.imageio.ImageWriteParam;
import javax.imageio.ImageWriter;
import javax.imageio.stream.ImageOutputStream;

public class ImageCompression {
public static void main(String[] args) throws IOException {

/*
* if (args.length < 2) { // Exit if both the arguments (Input File and
* Output File) are not provided
* System.err.println("Usage: java TestWriter c:\\in.png c:\\out.png");
* return; }
*/
Iterator writers;
BufferedImage bufferedImage;
ImageOutputStream imageOutputStream;
ImageWriter imageWriter;
ImageWriteParam pngparams;

// Read an image from the disk (First Argument)
// bufferedImage = ImageIO.read(new File(args[0]));
bufferedImage = ImageIO.read(new File("c:\\test.jpg"));
// Get all the PNG writers
writers = ImageIO.getImageWritersByFormatName("jpg");

// Fetch the first writer in the list
imageWriter = (ImageWriter) writers.next();


// Just to confirm that the writer in use is CLibPNGImageWriter
System.out.println("\n Writer used : "
+ imageWriter.getClass().getName() + "\n");

// Specify the parameters according to those the output file will be
// written

// Get Default parameters
pngparams = imageWriter.getDefaultWriteParam();

// Define compression mode
pngparams
.setCompressionMode(javax.imageio.ImageWriteParam.MODE_EXPLICIT);

// Define compression quality
pngparams.setCompressionQuality(0.5F);

// Define progressive mode
pngparams
.setProgressiveMode(javax.imageio.ImageWriteParam.MODE_COPY_FROM_METADATA);

// Deine destination type - used the ColorModel and SampleModel of the
// Input Image
pngparams.setDestinationType(new ImageTypeSpecifier(bufferedImage
.getColorModel(), bufferedImage.getSampleModel()));

// Set the output stream to Second Argument
// imageOutputStream = ImageIO.createImageOutputStream( new
// FileOutputStream(args[1]) );
imageOutputStream = ImageIO
.createImageOutputStream(new FileOutputStream("c:\\new_test.jpg"));
imageWriter.setOutput(imageOutputStream);

// Write the changed Image
imageWriter.write(null, new IIOImage(bufferedImage, null, null),
pngparams);

// Close the streams
imageOutputStream.close();
imageWriter.dispose();
}
}

I picked this code from: https://coderanch.com/t/430762/Java-General-intermediate/java/Help-java-ImageIO-API-PNG#1926836
15 years ago
Thank you for the reply.

I tried following kind of code, and it works:

Gson g = new Gson();
Map<String, Map><String, String>> m4 = g.fromJson(sz,new TypeToken<Map><String, Map><String, String>>>(){}.getType());
Map<String, Map><String, String>> map = g.fromJson(jsonString, m4)

But problem here is, I need to know the entire HashMap depth level. Can I just get a HashMap object without knowing the depth level...something like:

retMap = gson.fromJson(json, Map),

so that I don't know whether its Map<String, Map><String, String>> or just Map<String, String>?


I have a json object in the following format:

{
"v1": {"ids": {"hotels":{"123":"456", "789":"012"}}},
"v2": {"ids": {"hotels":{"981":"123", "5412":"12"}}}
}

This is basically a hash of hash of hash object.

Is there a way to convert this json to java HashMap object i.e. I want the output as Hash of Hash of Hash..?

I tried using the json lib api's (http://json-lib.sourceforge.net/) but couldn't do it.


Can we apply the filtering to html:file element so that when file chooser dialog box appears, the file type displayed should be as specified by me in the accept attribute of html:file.

eg:
<html:file property="file1" accept="image/jpeg"/>

If I use this, then file type shown should only of type *.jpeg .
Hi,
Whether it is possible to test the existence of the file in java script?

Basically I am using <input type="file" > and I enter some characters in the text box which is in front of the Browse button. Now before submitting the form, I want to make the client side validation for existence of the file. So is it possible?

Regards
Sanjeev
Hi,
I am using html:file tag to upload a file. My requirement is to show by default *.csv files as file type when I click on the browse button, but by default it shows *.*, *.html, and *.gif/*.jpg.
So is there any way to set file type by default to *.csv in choose file dialogue box.
18 years ago