Resized images with .NET vs PDFs

First, just to say, I know there are a ton of questions and answers here about image resizing in .NET, and believe me I have spent hours looking into this. I find it intriguing, and still feel I must be missing something, that somehow a simple PDF file can display an image at any size it wants and retain a far higher image quality than can be obtained using .NET.

I have an PNG image at 1000x1000px. It has some embedded text.

Using the iTextSharp PDF libray, I save it in a PDF file at 300×300:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>.ScaleAbsolute(300, 300)
</code>
<code>.ScaleAbsolute(300, 300) </code>
.ScaleAbsolute(300, 300)

The result is very good – a nice high quality image, showing clear text.

Then, to try and reduce the file size, I use .NET to first reduce the image size – pretty standard .NET stuff – using a graphics object g:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code> g.InterpolationMode = InterpolationMode.HighQualityBicubic
g.CompositingQuality = CompositingQuality.HighQuality
g.SmoothingMode = SmoothingMode.HighQuality
g.PixelOffsetMode = PixelOffsetMode.HighQuality
</code>
<code> g.InterpolationMode = InterpolationMode.HighQualityBicubic g.CompositingQuality = CompositingQuality.HighQuality g.SmoothingMode = SmoothingMode.HighQuality g.PixelOffsetMode = PixelOffsetMode.HighQuality </code>
  g.InterpolationMode = InterpolationMode.HighQualityBicubic
  g.CompositingQuality = CompositingQuality.HighQuality
  g.SmoothingMode = SmoothingMode.HighQuality
  g.PixelOffsetMode = PixelOffsetMode.HighQuality

Save this, and again create my PDF.

The resulting image, viewed in the PDF or even directly in an image viewer, is of a far lower quality, particularly noticeable around the text.

My question is: if a PDF can resize an image on the fly and retain its high quality, why can’t .NET create one to begin with? Or can it? Is there some method other than the standard .NET code that can achieve this?

After some Googling, I did try an alternative method, using a helper function

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code> Friend 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
'adp.WriteLog("", "got it " & mimeType, True)
Return encoders(j)
End If
Next j
Return Nothing
End Function
</code>
<code> Friend 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 'adp.WriteLog("", "got it " & mimeType, True) Return encoders(j) End If Next j Return Nothing End Function </code>
   Friend 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
            'adp.WriteLog("", "got it " & mimeType, True)
            Return encoders(j)
        End If
      Next j
      Return Nothing
   End Function

and then in the main routine:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>Dim compression As Long = 255 ' lower value is poor quality, high is better.
Dim myImageCodecInfo As ImageCodecInfo
Dim myEncoder As Encoder
Dim myEncoderParameter As EncoderParameter
Dim myEncoderParameters As EncoderParameters
myImageCodecInfo = GetEncoderInfo("image/png")
myEncoder = Encoder.Quality
myEncoderParameters = New EncoderParameters(1)
myEncoderParameter = New EncoderParameter(myEncoder, compression)
myEncoderParameters.Param(0) = myEncoderParameter
</code>
<code>Dim compression As Long = 255 ' lower value is poor quality, high is better. Dim myImageCodecInfo As ImageCodecInfo Dim myEncoder As Encoder Dim myEncoderParameter As EncoderParameter Dim myEncoderParameters As EncoderParameters myImageCodecInfo = GetEncoderInfo("image/png") myEncoder = Encoder.Quality myEncoderParameters = New EncoderParameters(1) myEncoderParameter = New EncoderParameter(myEncoder, compression) myEncoderParameters.Param(0) = myEncoderParameter </code>
Dim compression As Long = 255 ' lower value is poor quality, high is better.
Dim myImageCodecInfo As ImageCodecInfo
Dim myEncoder As Encoder
Dim myEncoderParameter As EncoderParameter
Dim myEncoderParameters As EncoderParameters
myImageCodecInfo = GetEncoderInfo("image/png")
myEncoder = Encoder.Quality
myEncoderParameters = New EncoderParameters(1)
myEncoderParameter = New EncoderParameter(myEncoder, compression)
myEncoderParameters.Param(0) = myEncoderParameter

then the standard graphics code, and then saving it with

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>Save([path], myImageCodecInfo, myEncoderParameters)
</code>
<code>Save([path], myImageCodecInfo, myEncoderParameters) </code>
Save([path], myImageCodecInfo, myEncoderParameters)

but tbh I couldn’t see any difference in the resulting image to the original straightforward method. (I’m not really sure it’s nothing more than a fancy way of simply asking for it be saved in PNG Format anyway, but IDK.)

I have different InterpolationMode settings.

Anyway, back to my question: is there a better way of saving a resized image in HQ? PDF’s manage it easily enough, so can’t .NET? What’s a PDF doing that .NET isn’t? In theory, I’d get a better result from taking a screenshot of the original image resized in the PDF!

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật