c# image resizing & reduce file size

C# RSS Icon ATOM Icon 2016/03/04 10:58 visualp


public static void SaveJpeg(string path, Image img, int quality)
            if (quality < 0 || quality > 100)
                throw new ArgumentOutOfRangeException("quality must be between 0 and 100.");

            // Encoder parameter for image quality
            EncoderParameter qualityParam = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, quality);
            // JPEG image codec
            ImageCodecInfo jpegCodec = GetEncoderInfo("image/jpeg");
            EncoderParameters encoderParams = new EncoderParameters(1);
            encoderParams.Param[0] = qualityParam;
            img.Save(path, jpegCodec, encoderParams);

        /// <summary>
        /// Returns the image codec with the given mime type
        /// </summary>
        private static ImageCodecInfo GetEncoderInfo(string mimeType)
            // Get image codecs for all image formats
            ImageCodecInfo[] codecs = ImageCodecInfo.GetImageEncoders();

            // Find the correct image codec
            for (int i = 0; i < codecs.Length; i++)
                if (codecs[i].MimeType == mimeType)
                    return codecs[i];

            return null;

2016/03/04 10:58 2016/03/04 10:58
받은 트랙백이 없고, 댓글이 없습니다.

댓글+트랙백 RSS :: http://blog.visualp.com/rss/response/707

댓글+트랙백 ATOM :: http://blog.visualp.com/atom/response/707

다음과 같은 오류가 발생한다면, 버퍼 사이즈를 nginx에 설정 해줘야한다.

20xx/xx/xx xx:xx:xx [warn] ….an upstream response is buffered to a temporary file /var/cache/nginx/proxy_temp/xxxx while readi
ng upstream, client: xxx.xxx.xxx.xxx, server: aaa.aaaa.aaa.com, request: “GET /font/NanumGothic-Regular.woff HTTP/1.1”, upstream: “http:

http, location , server 중 아무데나 아래 값 추가 할 수 있음.
location에 추가함 .

proxy_buffering   on;
proxy_buffer_size    1024k;
proxy_buffers        1024   1024k;
2016/02/24 09:54 2016/02/24 09:54
받은 트랙백이 없고, 댓글이 없습니다.

댓글+트랙백 RSS :: http://blog.visualp.com/rss/response/706

댓글+트랙백 ATOM :: http://blog.visualp.com/atom/response/706

c# var float string to int convert

C# RSS Icon ATOM Icon 2016/02/12 18:38 visualp


a =(int)Convert.ToDouble("1.2");

Note if you're using comma as a number separator in your operating system, you have to use IFormatProvider:

var a =(int)Convert.ToDouble("1.2",CultureInfo.InvariantCulture.NumberFormat);

Another way to accomplish this task:

var a =int.Parse("1.2".Split('.')[0]);

2016/02/12 18:38 2016/02/12 18:38
받은 트랙백이 없고, 댓글이 없습니다.

댓글+트랙백 RSS :: http://blog.visualp.com/rss/response/705

댓글+트랙백 ATOM :: http://blog.visualp.com/atom/response/705

c# 공유폴더 접근

C# RSS Icon ATOM Icon 2016/01/26 10:05 visualp
I found this solution to work for me when trying to access a file share on another computer.  It basically simulates doing a NET USE command where you can specify the credentials to use on the remote end.  The nice part is that you do not have to impersonate the user and it works across domains and workgroup computers.

First, declare these functions and types in your class.

using System.Reflection;
using System.Runtime.InteropServices;
using System.ComponentModel;

public class YourClass {
private static extern int WNetAddConnection2A(ref NetResource pstNetRes, string psPassword, string psUsername, int piFlags);
private static extern int WNetCancelConnection2A(string psName, int piFlags, int pfForce);

private struct NetResource {
    public int iScope;
    public int iType;
    public int iDisplayType;
    public int iUsage;
    public string sLocalName;
    public string sRemoteName;
    public string sComment;
    public string sProvider;

private const int RESOURCETYPE_DISK = 0x1;

Then, add these two methods.
    private void LoginToShare(string serverName, string shareName, string user, string password) {
        string destinationDirectory = string.Format(@"\\{0}\{1}", serverName, shareName);

        NetResource nr = new NetResource();
        nr.iScope = 2;
        nr.iType = RESOURCETYPE_DISK;
        nr.iDisplayType = 3;
        nr.iUsage = 1;
        nr.sRemoteName = destinationDirectory;
        nr.sLocalName = null;

        int flags = 0;
        int rc = WNetAddConnection2A(ref nr, password, user, flags);

        if (rc != 0) throw new Win32Exception(rc);

    private void LogoutFromShare(string serverName, string shareName) {
        string destinationDirectory = string.Format(@"\\{0}\{1}", serverName, shareName);
        int flags = 0;
        int rc = WNetCancelConnection2A(destinationDirectory, flags, Convert.ToInt32(false));

In your code, call the LoginToShare with the server, share, user, and password needed.  Then simply use the standard \\server\share\path conventions for accessing files on remote computers.  Call the LogoutFromShare when you're done.


2016/01/26 10:05 2016/01/26 10:05
받은 트랙백이 없고, 댓글이 없습니다.

댓글+트랙백 RSS :: http://blog.visualp.com/rss/response/704

댓글+트랙백 ATOM :: http://blog.visualp.com/atom/response/704

[출처] :http://stackoverflow.com/questions/16712462/many-commandname-for-one-form-in-spring-mvc
classCombinedCommand(){Activity activity;Etabl etabl;//Getter and setter}


  method="post" commandName="combinedCommand"">...<form:input type="text"path="activity.x"/>...<form:input type="text"path="etabl.y"/>...</form:form>
2015/12/14 11:24 2015/12/14 11:24
받은 트랙백이 없고, 댓글이 없습니다.

댓글+트랙백 RSS :: http://blog.visualp.com/rss/response/703

댓글+트랙백 ATOM :: http://blog.visualp.com/atom/response/703

java 소수점 처리

JSP, JAVA RSS Icon ATOM Icon 2015/12/03 16:14 visualp

자바 Math 클래스에서 실수값 반올림이나 올림, 버림, 절대값을 구해주는 메서드가 있다.

static long Math.round(double a)
static int Math.round(float a)
예) System.out.println(Math.round(100.56)); //결과: 101

static double ceil(double a)

예) System.out.println(Math.ceil(100.56)); //결과: 101.0

static double floor(double a)

예) System.out.println(Math.floor(100.56)); //결과: 100.0

static double abs(double a)
static float abs(float a)
static int abs(int a)
static long abs(long a)

예) System.out.println(Math.abs(-100.56)); //결과: 100.56

참고로 소수 둘째자리에서 반올림을 하고 싶다고 하면 아래와 같이 응용한다.

double a = 100.22516;
double b = Math.round(a*100d) / 100d;
System.out.println(b); //결과: 100.23

원리는 차근차근 따라해 보면 쉽다.
일반 round() 메서드는 소수첫째자리에서 반올림 되기때문에 내가 반올림 하고자하는 자리수가 첫번째 소수점자리가 되도록 10 제곱을 곱해준다.
즉, 소수 2번째 자리까지 구하기 때문에 a에 10^2 하게되면 10022.516이 된다.
여기에서 반올림 한후 다시 나눈만큼 곱해주면 원래 소수 자리로 복원되게 된다.

다른 방법으로는 서식출력이 가능한 표준출력 메서드를 이용한 방법이다.
double a = 100.22516;
System.out.printf("%.2f",a); //결과 100.23

소수 둘째자리 실수로 반올림하여 출력하는 메서드이다.

간단한 내용이면서도 자주 활용되는 메서드에 대해 정리해보았습니다.
2015/12/03 16:14 2015/12/03 16:14
받은 트랙백이 없고, 댓글이 없습니다.

댓글+트랙백 RSS :: http://blog.visualp.com/rss/response/702

댓글+트랙백 ATOM :: http://blog.visualp.com/atom/response/702


 * Pathvariable example
 * @return
public String page(@PathVariable String var){
    String returnUrl = "";
    if(var.equals("one")) {
        returnUrl = "page1";
    } else if(var.equals("two")) {
        returnUrl = "page2";
    return returnUrl;
2015/11/18 17:46 2015/11/18 17:46
받은 트랙백이 없고, 댓글이 없습니다.

댓글+트랙백 RSS :: http://blog.visualp.com/rss/response/701

댓글+트랙백 ATOM :: http://blog.visualp.com/atom/response/701

스프링의 web.xml에 utf-8 filter 를 추가 해주고도  한글이 께진다면 
tomcat 서버의 다음과 같이 설정을 해주면 한글 깨짐을 방지 할 수 있다.


 <Connector port="8080" protocol="HTTP/1.1"
               redirectPort="8443" URIEncoding="UTF-8"  />

2015/11/10 10:03 2015/11/10 10:03
받은 트랙백이 없고, 댓글이 없습니다.

댓글+트랙백 RSS :: http://blog.visualp.com/rss/response/700

댓글+트랙백 ATOM :: http://blog.visualp.com/atom/response/700

php GET , POST 변수 바인딩

PHP RSS Icon ATOM Icon 2015/11/04 18:01 visualp
foreach($_REQUEST as $key => $value ){
  ${"$key"} = $value;
2015/11/04 18:01 2015/11/04 18:01
받은 트랙백이 없고, 댓글이 없습니다.

댓글+트랙백 RSS :: http://blog.visualp.com/rss/response/699

댓글+트랙백 ATOM :: http://blog.visualp.com/atom/response/699

If you receive an error while restarting IPtables on your virtual machine that includes : raw nat mangle filter [FAILED] or similar, this is a known error with CentOS 5 / CentOS 6 on virtual architectures. You simply need to modify the : /etc/init.d/iptables file.


Next, locate the below text, you can search for 'setting chains' Next add the lines labeled with + to the file, after the line with: case "$i"

vi /etc/init.d/iptables

echo -n $"${IPTABLES}: Setting chains to policy $policy: "
    for i in $tables; do
        echo -n "$i "
        case "$i" in

<!-- 추가된 부분 -->
+           security)

+               $IPTABLES -t filter -P INPUT $policy \
+                   && $IPTABLES -t filter -P OUTPUT $policy \
+                   && $IPTABLES -t filter -P FORWARD $policy \
+                   || let ret+=1
+               ;;

                $IPTABLES -t raw -P PREROUTING $policy \
                    && $IPTABLES -t raw -P OUTPUT $policy \
                    || let ret+=1

2015/11/02 16:33 2015/11/02 16:33
받은 트랙백이 없고, 댓글이 없습니다.

댓글+트랙백 RSS :: http://blog.visualp.com/rss/response/698

댓글+트랙백 ATOM :: http://blog.visualp.com/atom/response/698