My Life/version 23 (2023)2023. 11. 9. 00:57
Posted by chobocho
Tip/Windows2023. 9. 22. 01:02

 C#을 배우면서 간단한 이미지 뷰어를 만들어 보았다.

기능:

 Drag & Drop 

R / L  키로 이미지 회전

Left, Right 화살표 키로 이미지 전환 (같은 폴더내)

Up 화살표키: 첫번째 이미지 (알파벳 순)

Down 화살표키: 마지막 이미지 (알파벳 순)

 

전체 소스코드:

https://github.com/chobocho/choboImageViewer

 

GitHub - chobocho/choboImageViewer: Simple image view by c#

Simple image view by c#. Contribute to chobocho/choboImageViewer development by creating an account on GitHub.

github.com

 

실행파일:

- 경고: 사용시 발생하는 어떤 이슈도 책임 지지 않습니다.

ImageViewer_32bit.zip
0.16MB

구현 관련

1. 메모리릭 이슈

-  PictureBox 에 이미지를 바꿀 때에는 반드시, dispose() 메서드 호출 후 null을 대입해야 한다.

            if (pictureBox.BackgroundImage != null)
            {
                pictureBox.BackgroundImage.Dispose();
                pictureBox.BackgroundImage = null;
            }

2. 파일을 읽어서, 파일이 위치한 폴더의 모든 이미지 파일 읽기. (Chat GPT 형님의 도움을 받았다)

    public void setFileName(string? filename)
    {
        if (filename == null || !File.Exists(filename)) return;
        string[] imageExtensions = { ".jpg", ".jpeg", ".png", ".gif", ".bmp", "ico" }; 
        
        // 이 부분 입니다.
        _filesList = Directory.GetFiles(Path.GetDirectoryName(@filename) ?? string.Empty)
            .Where(file => imageExtensions.Contains(Path.GetExtension(file).ToLower()))
            .Select(Path.GetFullPath).ToArray();

        Array.Sort(_filesList);
        _index = Array.IndexOf(_filesList, filename);
    }

3. 이미지 회전

- 여기서는 dispose() 메서드 호출 하지 않는다. 호출 하면 이미지 객체가 삭제된다.

- 마지막에 pictureBox.Refresh() 메소드를 꼭 호출해 주어야 회전한 이미지로 업데이트 된다.

        void rotateImage(System.Drawing.RotateFlipType angle)
        {
            var LoadedImage = pictureBox.BackgroundImage;
            LoadedImage.RotateFlip(angle);

            pictureBox.BackgroundImage = LoadedImage;

            var width = LoadedImage.Width > minimumSize ? LoadedImage.Width : minimumSize;
            width = LoadedImage.Width > maximumSize ? maximumSize : width;

            var height = LoadedImage.Height > minimumSize ? LoadedImage.Height : minimumSize;
            height = LoadedImage.Height > maximumSize ? maximumSize : height;

            this.Width = width;
            this.Height = height;

            pictureBox.Refresh();
        }
Posted by chobocho
Coding/Tip2023. 9. 19. 23:37

1. 파일 인코딩 변경 하기

우측 하단의 UTF-8 과 같은 파일 인코딩 부분을 클릭하면 바꿀수 있다.

 

2. 줄 구분 기호 변경 하기

우측 하단의 CRLF와 같은 줄 구분 기호 부분을 클릭하면 바꿀수 있다.

Posted by chobocho
Coding/Python 삽질기2023. 9. 15. 00:48

오래 전, 라떼 시절 만들었던 파이썬 코드를  Chat GPT를 이용하여 개선해 보았다.

Python 2.X 시절 만든 코드를 3.X로 바꾸면서 저장 기능 까지 추가 하였다.

[원본 코드]

https://chobocho.tistory.com/2460823

 

Fractal Tree

#-*- coding: cp949 -*- from Tkinter import * import math import random RADIAN = math.pi / 180 aColor = [ "brown", "red", "blue", "green", "orange", "black" ] def DrawTree( startX, startY, angle, length, depth ): if depth == 0: return rand=random.random; en

chobocho.tistory.com

 

[개선 코드]

 

from tkinter import *
import math
import random
from PIL import Image, ImageDraw

RADIAN = math.pi / 180


def random_color():
    r = random.randint(0, 255)
    g = random.randint(0, 255)
    b = random.randint(0, 255)
    return r, g, b


def draw_tree(start_x, start_y, angle, length, depth, image_draw=None):
    if depth == 0:
        return

    scale = int(depth/12) + 1
    end_x = start_x + length * scale * math.cos(angle * RADIAN)
    end_y = start_y - length * scale * math.sin(angle * RADIAN)

    image_draw.line([start_x, start_y, end_x, end_y], width=depth, fill=random_color())

    draw_tree(end_x, end_y, angle + random.randint(10, 30), length * random.uniform(0.8, 0.9), depth - 1, image_draw)
    draw_tree(end_x, end_y, angle - random.randint(10, 30), length * random.uniform(0.8, 0.9), depth - 1, image_draw)


def draw_new_tree():
    myCanvas.delete("all")  # Clear the canvas

    image = Image.new("RGB", (800, 600), "white")
    image_draw = ImageDraw.Draw(image)
    draw_tree(400, 550, 90, 70, 12, image_draw)
    image.save("fractal_tree.png", "PNG")  # Save the image as PNG

    photo = PhotoImage(file="fractal_tree.png")
    myCanvas.create_image(0, 0, image=photo, anchor=NW)
    myCanvas.photo = photo


if __name__ == "__main__":
    root = Tk()
    root.title("프랙탈 나무")
    root.geometry("800x600")

    myCanvas = Canvas(width=800, height=600)

    draw_button = Button(text="새로운 나무 그리기", command=draw_new_tree)
    draw_button.pack()

    myCanvas.pack()
    root.mainloop()

 

'Coding > Python 삽질기' 카테고리의 다른 글

[Python] PNG to ICO 변환 하기  (0) 2024.01.04
[Python] Python 소스 코드 빌드 해보기  (1) 2023.09.06
HTTP Protocol  (0) 2023.08.18
Posted by chobocho
Coding/Script2023. 9. 7. 00:00
echo [TEST]
echo main x0 %~x0
echo main n0 %~n0
echo main nx0 %~nx0
echo main p0 %~p0
echo main pnx0 %~pnx0
echo main d0 %~d0 
echo main dpnx0 %~dpnx0
echo main f0 %~f0

실행 결과

C:\github>test

C:\github>echo [TEST]
[TEST]

C:\github>echo main x0 .bat
main x0 .bat

C:\github>echo main n0 test
main n0 test

C:\github>echo main nx0 test.bat
main nx0 test.bat

C:\github>echo main p0 \github\
main p0 \github\

C:\github>echo main pnx0 \github\test.bat
main pnx0 \github\test.bat

C:\github>echo main d0 C:
main d0 C:

C:\github>echo main dpnx0 C:\github\test.bat
main dpnx0 C:\github\test.bat

C:\github>echo main f0 C:\github\test.bat
main f0 C:\github\test.bat

C:\github>
Posted by chobocho
Coding/Python 삽질기2023. 9. 6. 23:44

파이썬 소스 코드를 빌드해서 python.exe  를 만들어 보자

1. 빌드 환경 구성

  • Visusal Studio를 설치한다
  • Python 3.10버전을 설치한다

 

2. 파이썬 소스를 다운 받는다 (우리는 3.11을 사용한다)

https://www.python.org/ftp/python/3.11.5/Python-3.11.5.tgz

 

3. 적당한 폴더에 압축을 푼다

4. 설치경로\PCbuild\build.bat 를 실행한다

5. 잠시 뒤 

설치경로\PCbuild\amd64\python.exe 가 생성 됨을 볼수있다.

'Coding > Python 삽질기' 카테고리의 다른 글

[Python] 프랙탈 나무 만들기  (0) 2023.09.15
HTTP Protocol  (0) 2023.08.18
[AI] Stable Diffusion 설치 하기  (0) 2023.06.09
Posted by chobocho
Tip/Android2023. 8. 30. 23:03

Hexa Game 앱은 어떠한 개인 정보도 수집하지 않습니다.

Hexa Game does not collect any personal information.

Posted by chobocho
Tip/Android2023. 8. 30. 01:30

직각 삼각형 대각선 길이 구하기 앱은 어떠한 개인 정보도 수집하지 않습니다.

Triangle application does not collect any personal information.

Posted by chobocho
Tip/Android2023. 8. 30. 00:47

제비뽑기 앱은 어떠한 개인 정보도 수집하지 않습니다.

ChooseOne application does not collect any personal information.

Posted by chobocho
Tip/Android2023. 8. 30. 00:25

솔리테어 게임은 어떠한 개인 정보도 수집하지 않습니다.

Solitaire Card Game does not collect any personal information.

 

Posted by chobocho