图像源文件 [英] Image Source to file

查看:112
本文介绍了图像源文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我想这对WPF编码人员是理所当然的?
下面是一个返回图像源的函数,但是我需要做的是创建一个新的jpg文件,简单的问题是如何将位图图像转换为磁盘上的文件?以下是我用来查看缩略图的基本功能,所以我位于其中一半.
任何想法都会有所帮助.

Hi guys, I presume this is a no-brainer for WPF coders?
Below is a function that returns an image source, but what I need to do is create a new jpg file, simple question is how do I convert a bitmap image to a file on disk? below is a basic func that I use to view thumbnails so I''m half way there.
any ideas would be helpful thanks.

Public Function ScaleImageToFit(ByVal sourceImg As String, ByVal pbWidth As Integer, ByVal pbHeight As Integer) As BitmapImage

        Dim sourceImage As New BitmapImage()
        sourceImage.BeginInit()
        sourceImage.UriSource = New Uri(sourceImg, UriKind.Relative)
        sourceImage.EndInit()

        Dim scale_factor As Single = 0

        ' determine scale_factor based on source image size.
        Dim srcWidth As Integer = sourceImage.Width
        Dim srcHeight As Integer = sourceImage.Height
        Dim myImage As New Image

        If srcWidth > srcHeight Then  ' landscape
            scale_factor = pbWidth / srcWidth
            myImage.Width = pbWidth * scale_factor
            sourceImage.DecodePixelWidth = myImage.Width
        Else    ' portrait

            scale_factor = pbHeight / srcHeight  ' make it fit to pb height
            myImage.Height = pbWidth * scale_factor
            sourceImage.DecodePixelHeight = myImage.Height
        End If

        myImage.Source = sourceImage

        Return myImage.Source

    End Function

推荐答案

我不知道这对"WPF编码人员"是否理智(可能我从未见过),但对Google用户却毫不费力:
http://stackoverflow.com/questions/4161359/save-bitmapimage-to-file [ ^ ].

祝你好运,
—SA
I don''t know if this is a no-brainer for "WPF coders" (probably I never met one), but it is a no-brainer for a Google user:
http://stackoverflow.com/questions/4161359/save-bitmapimage-to-file[^].

Good luck,
—SA


这篇关于图像源文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆