imgur과 this question을 간단히 살펴 보았습니다. 다음과 같이 작성했습니다. 작동하지 않는지 알려주세요.
Bitmap bitmap = yourBitmapHere;
// Creates Byte Array from picture
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 100, baos); // Not sure whether this should be jpeg or png, try both and see which works best
URL url = new URL("http://api.imgur.com/2/upload");
//encodes picture with Base64 and inserts api key
String data = URLEncoder.encode("image", "UTF-8") + "=" + URLEncoder.encode(Base64.encode(baos.toByteArray(), Base64.DEFAULT).toString(), "UTF-8");
data += "&" + URLEncoder.encode("key", "UTF-8") + "=" + URLEncoder.encode(YOUR_API_KEY, "UTF-8");
// opens connection and sends data
URLConnection conn = url.openConnection();
conn.setDoOutput(true);
OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
wr.write(data);
wr.flush();
편집 : Base64.encode의 두 번째 옵션으로 Base64.DEFAULT를 전달해야합니다. 위의 예제를 업데이트했습니다.
편집 2 : 당신은 the oracle site에 따라 다음과 같은 코드를 사용하고 출력하는 것을 다시보고 수 :
BufferedReader in = new BufferedReader(
new InputStreamReader(
conn.getInputStream()));
String inputLine;
while ((inputLine = ic.readLine()) != null)
System.out.println(inputLine);
in.close();
imgur 웹 사이트의 자바 예를보고 시도 - HTTP : //api.imgur. co.kr/examples # uploading_java – hrickards
IMAGE.IO는 안드로이드에 존재하지 않으므로 어떻게 되나요? – asd2005
비트 맵을 사용하여 이미지를 저장한다고 가정하면 http://stackoverflow.com/questions/6344694/get-foreground-application-icon-convert-to-base64 – hrickards