본문 바로가기
VB.NET&MSSQL

[vb.net] 이미지 파일 형식

by TobeDalin 2020. 4. 25.
반응형

vb.net 이미지 파일 형식

 

BMP 
BMP is a standard format used by Windows to store device-independent and application-independent images. The number of bits per pixel (1, 4, 8, 15, 24, 32, or 64) for a given BMP file is specified in a file header. BMP files with 24 bits per pixel are common. BMP files are usually not compressed and, therefore, are not well suited for transfer across the Internet. 
Graphics Interchange Format (GIF) 
GIF is a common format for images that appear on Web pages. GIFs work well for line drawings, pictures with blocks of solid color, and pictures with sharp boundaries between colors. GIFs are compressed, but no information is lost in the compression process; a decompressed image is exactly the same as the original. One color in a GIF can be designated as transparent, so that the image will have the background color of any Web page that displays it. A sequence of GIF images can be stored in a single file to form an animated GIF. GIFs store at most 8 bits per pixel, so they are limited to 256 colors. 
Joint Photographic Experts Group (JPEG) 
JPEG is a compression scheme that works well for natural scenes such as scanned photographs. Some information is lost in the compression process, but often the loss is imperceptible to the human eye. JPEGs store 24 bits per pixel, so they are capable of displaying more than 16 million colors. JPEGs do not support transparency or animation. 
The level of compression in JPEG images is configurable, but higher compression levels (smaller files) result in more loss of information. A 20:1 compression ratio often produces an image that the human eye finds difficult to distinguish from the original. The following illustration shows a BMP image and two JPEG images that were compressed from that BMP image. The first JPEG has a compression ratio of 4:1 and the second JPEG has a compression ratio of about 8:1. 
JPEG는 스캔 한 사진과 같은 자연스러운 장면에 적합한 압축 방식입니다. 일부 정보는 압축 과정에서 손실되지만, 종종 손실은 육안으로 인식되지 않습니다. JPEG는 픽셀 당 24 비트를 저장하므로 1600 만 개 이상의 색상을 표시 할 수 있습니다. JPEG는 투명도 나 애니메이션을 지원하지 않습니다. 

JPEG 이미지의 압축 수준을 구성 할 수 있지만 압축 수준이 높을수록 (파일이 작을수록) 정보가 더 많이 손실됩니다. 20 : 1 압축 비율은 종종 사람의 눈이 원본과 구별하기 어려운 이미지를 생성합니다. 다음 그림은 BMP 이미지와 해당 BMP 이미지에서 압축 된 두 개의 JPEG 이미지를 보여줍니다. 첫 번째 JPEG의 압축 비율은 4 : 1이고 두 번째 JPEG의 압축 비율은 약 8 : 1입니다. 
 


JPEG compression does not work well for line drawings, blocks of solid color, and sharp boundaries. The following illustration shows a BMP along with two JPEGs and a GIF. The JPEGs and the GIF were compressed from the BMP. The compression ratio is 4:1 for the GIF, 4:1 for the smaller JPEG, and 8:3 for the larger JPEG. Note that the GIF maintains the sharp boundaries along the lines, but the JPEGs tend to blur the boundaries. 
JPEG 압축은 선 그리기, 단색 블록 및 선명한 경계에는 적합하지 않습니다. 다음 그림은 2 개의 JPEG 및 GIF와 함께 BMP를 보여줍니다. JPEG와 GIF는 BMP에서 압축되었습니다. 압축 비율은 GIF의 경우 4 : 1, 작은 JPEG의 경우 4 : 1, 큰 JPEG의 경우 8 : 3입니다. GIF는 선을 따라 선명한 경계를 유지하지만 JPEG는 경계를 흐리게하는 경향이 있습니다. 
  
캐드 도면이나 패턴 이미지등 선을 강조해야 하는 경우는 gif로 해야 합니다.

화면 캡쳐를 선과, 글위주로 화면 캡쳐하고 gif 로 저장한 경우 4~50 kb (아래 좌측 이미지) 

                                                    jpg로 저장한 경우 115~120 kb(아래 우측 이미지)

 gif의 사이즈가 작고, 손실은 거의 유사한 것을 알수 있습니다.                          

https://developers.google.com/web/fundamentals/performance/optimizing-content-efficiency/automating-image-optimization?hl=ko#do-my-images-need-optimization

 

이미지 최적화 자동화하기  |  Web Fundamentals  |  Google Developers

이미지 형식!

developers.google.com

이미지 고품질 조절방법

클립보드로 저장된 이미지의 해상도가 erp에 저장되고 나면 해상도가 떨어지는 이유.
삽입된 이미지의 해상도가 떨어지는 것은 캡쳐한 프로그램과 관련 없이 Office 2007파일 형식의 특징입니다.
2003이하 파일 형식이 바이너리 형식이기 때문에 삽입된 그림이 파일 저장 시 압축되어 저장되므로 파일 크기는 작아지지만 이미지 해상도는 떨어집니다.
2007이상 파일 형식은 zip기반의 형식이기 때문에 삽입된 그림이 그대로 저장이 되어 파일 크기는 커지지만 이미지 해상도는 그대로 유지합니다.
 
how to paste image as original resolution in vb.net
https://stackoverflow.com/questions/249587/high-quality-image-scaling-library   
 
 Dim ms As MemoryStream = New MemoryStream() 
 Dim img As Image = C1LIST1(C1LIST1.RowSel, 1)
 img.Save(ms, Imaging.ImageFormat.Jpeg) 
 PIC_PATTERN.Image = Image.FromStream(ms)   
 
 
https://www.csharpcodi.com/csharp-examples/System.Drawing.Image.Save(System.IO.Stream,%20System.Drawing.Imaging.ImageCodecInfo,%20System.Drawing.Imaging.EncoderParameters)/  
 
You can configure around with Encoder.Quality from my sample. Following piece of code in a sample set maximum quality of the image (100). 
new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 100L) 

You can set different values to find the best quality value (50L, 75L ...)
내 샘플에서 Encoder.Quality로 놀 수 있습니다. 샘플의 다음 코드는 이미지의 최대 품질을 설정합니다 (100). 
새로운 EncoderParameter (System.Drawing.Imaging.Encoder.Quality, 100L) 
최고의 품질 값을 찾기 위해 다른 값을 설정할 수 있습니다 (50L, 75L ...)
 
Dim img As Image = Me.PIC_PATTERN.Image 
Dim imageStream As System.IO.MemoryStream = New System.IO.MemoryStream() 
Dim qualityParam As EncoderParameter = New EncoderParameter(Encoder.Quality, 100L) 
'''Dim jpegCodec As ImageCodecInfo = ImageCodecInfo.GetImageEncoders("image/jpeg") //오류발생
Dim jpegCodec As ImageCodecInfo = GetEncoderInfo("image/jpeg")
Dim encoderParams As EncoderParameters = New EncoderParameters(1) 
encoderParams.Param(0) = qualityParam 
img.Save(imageStream, jpegCodec, encoderParams) 
''' img.Save(imageStream, System.Drawing.Imaging.ImageFormat.Jpeg) 
file2 = imageStream.GetBuffer()
 
GetEncoderInfo 함수 추가
 Private Function GetEncoderInfo(ByVal mimeType As String) _
    As ImageCodecInfo
        Dim j As Integer
        Dim encoders As ImageCodecInfo()
        encoders = ImageCodecInfo.GetImageEncoders()
        For j = 0 To encoders.Length
            If encoders(j).MimeType = mimeType Then
                Return encoders(j)
            End If
        Next j
        Return Nothing
    End Function
 
해상도의 조절은...resize에서 결정되는 듯.
 'IMAGE 크리를 조정한다.
    Public Function iReSizeImage(ByVal imgPhoto As Image, ByVal Size As Size)
        '//이미지 넓이와 높이  
        Dim OriginalWidth As Integer = imgPhoto.Width
        Dim OriginalHeight As Integer = imgPhoto.Height

        '//이미지를 적용할 객체의 넓이와 높이  
        'Dim adjustWidth As Integer = Size.Width
        'Dim adjustHeight As Integer = Size.Height

        Dim adjustWidth As Integer = 80
        Dim adjustHeight As Integer = 78

        '//소스의 처음 위치  
        Dim OriginalX As Integer = 0
        Dim OriginalY As Integer = 0

        '//움직일 위치  
        Dim adjustX As Integer = 0
        Dim adjustY As Integer = 0

        '//비어있는 비트맵 객체 생성  
        Dim bmPhoto As Bitmap = New Bitmap(adjustWidth, adjustHeight, Imaging.PixelFormat.Format48bppRgb) 'Imaging.PixelFormat.Format24bppRgb)

        '//이미지를 그래픽 객체로 만든다.  
        Dim grPhoto As Graphics = Graphics.FromImage(bmPhoto)

        ' //사각형을 그린다.  

        '//그릴 이미지객체 크기, 그려질 이미지객체 크기  
        grPhoto.DrawImage(imgPhoto,
        New Rectangle(adjustX, adjustY, adjustWidth, adjustHeight),
        New Rectangle(OriginalX, OriginalY, OriginalWidth, OriginalHeight),
        GraphicsUnit.Pixel)
        grPhoto.Dispose()

        Return bmPhoto
    End Function
 
 

 

반응형

댓글