마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

안드로이드 이미지 사이즈 조절

0 추천

Uri를 가지고 비트맵으로 변경후 사이즈 조절 후 

다시 Uri 받아오고 싶은 어떻게 해야 할지 잘모르겠네요. 

해볼려고 했는데 ... 계속 에러가

	public Uri iamgeSizeChange(Uri selPhtoUri, String imageName){
		
		String path = null;
		
		try {
			Bitmap bm = Images.Media.getBitmap(getContentResolver(), selPhtoUri);
			bm = Bitmap.createScaledBitmap(bm, 90, 90, true);

			ByteArrayOutputStream bytes = new ByteArrayOutputStream();
			bm.compress(CompressFormat.JPEG, 100, bytes);
			path = Images.Media.insertImage(getContentResolver(), bm, imageName, null);
			
			
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return Uri.parse(path);

	}

 

최종 목적은 파일서버에 저장 하는 것입니다. 

 

 private class back extends AsyncTask<String, String, String>{
	        
	        @Override
	        protected String doInBackground(String... urls) {
	            // TODO Auto-generated method stub
	            try{
	            	FileInputStream mFileInputStream = new FileInputStream(urls[2]);

	    			
	    			URL connectUrl = new URL(urls[0]);
	    			
	    			System.out.println("mFileInputStream is " + mFileInputStream);

	    			
	    			//open connection
	    			System.out.println("open connection");
	    			HttpURLConnection conn = (HttpURLConnection)connectUrl.openConnection();
	    			
	    			conn.setDoInput(true);
	    			conn.setDoOutput(true);
	    			conn.setUseCaches(false);
	    			conn.setRequestMethod("POST");
	    			conn.setRequestProperty("Connection", "Keep-Alive");
	    			conn.setRequestProperty("Content-Type", "multipart/form-data;boundary=" + boundary);
	    			
	    			//write data
	    			System.out.println("write data");
	    			DataOutputStream dos = new DataOutputStream(conn.getOutputStream());

	    			dos.writeBytes(towHyphens + boundary + lindEnd);
	    			dos.writeBytes("Content-Disposition: form-data; name=\"uploadedfile\";filename=\"" + urls[1]+".jpg"+"\""+lindEnd);
	    			dos.writeBytes(lindEnd);
	    			
	    			int bytesAvailable = mFileInputStream.available();
	    			int maxBufferSize = 1024;
	    			int bufferSize = Math.min(bytesAvailable, maxBufferSize);

	    			byte[] buffer = new byte[bufferSize];
	    			int bytesRead = mFileInputStream.read(buffer, 0, bufferSize);
	    			
	    			System.out.println("image byte is "+ bytesRead);
	    			
	    			//read image
	    			System.out.println("read image");
	    			while(bytesRead > 0){
	    				dos.write(buffer, 0, bufferSize);
	    				bytesAvailable = mFileInputStream.available();
	    				bufferSize = Math.min(bytesAvailable, maxBufferSize);
	    				bytesRead = mFileInputStream.read(buffer, 0, bufferSize);
	    			}
	    			
	    			dos.writeBytes(lindEnd);
	    			dos.writeBytes(towHyphens + boundary + towHyphens + lindEnd);
	    			
	    			
	    			//close streams
	    			System.out.println("File is written");
	    			mFileInputStream.close();
	    			dos.flush();  //finish upload...
	    			
	    			//get response
	    			int ch;
	    			InputStream is = conn.getInputStream();
	    			StringBuffer b = new StringBuffer();
	    			while((ch = is.read() ) != -1){
	    				b.append((char)ch);
	    			}
	    			
	    			String s = b.toString();
	    			System.out.println("result ="+s);
	    			dos.close();
	                
	                
	            }catch(Exception e){
	                System.out.println("error : " + e.getMessage());
	            	e.printStackTrace();
	            }
	            return null;
	        }
	    }
	 

 

kdi0373 (470 포인트) 님이 2014년 7월 3일 질문

답변 달기

· 글에 소스 코드 보기 좋게 넣는 법
· 질문에 대해 추가적인 질문이나 의견이 있으면 답변이 아니라 댓글로 달아주시기 바랍니다.
표시할 이름 (옵션):
개인정보: 당신의 이메일은 이 알림을 보내는데만 사용됩니다.
스팸 차단 검사:
스팸 검사를 다시 받지 않으려면 로그인하거나 혹은 가입 하세요.
...