100分,把这段代码翻译成c#的

potato__ 2004-12-30 04:36:43
This function creates the Thumbnail image and returns the
image created in Byte() format
Private Function createThumnail()Function createThumnail(ByVal ImageStream As Stream,
ByVal tWidth As Double, ByVal tHeight As Double) As Byte()
Dim g As System.Drawing.Image =System.Drawing.Image.FromStream(ImageStream)
Dim thumbSize As New Size()
thumbSize =NewthumbSize(g.Width, g.Height, tWidth, tHeight)
Dim imgOutput As New Bitmap(g, thumbSize.Width, thumbSize.Height)
Dim imgStream As New MemoryStream()
Dim thisFormat = g.RawFormat
imgOutput.Save(imgStream, thisFormat)
Dim imgbin(imgStream.Length) As Byte
imgStream.Position = 0
Dim n As Int32 = imgStream.Read(imgbin, 0, imgbin.Length)
g.Dispose()
imgOutput.Dispose()
Return imgbin
End Function

Function NewthumbSize()Function NewthumbSize(ByVal currentwidth As Double, ByVal
currentheight As Double, ByVal newWidth As Double, ByVal newHeight As Double)
' Calculate the Size of the New image
Dim tempMultiplier As Double

If currentheight > currentwidth Then ' portrait
tempMultiplier = newHeight / currentheight
Else
tempMultiplier = newWidth / currentwidth
End If

Dim NewSize As New Size(CInt(currentwidth * tempMultiplier),
CInt(currentheight * tempMultiplier))
Return NewSize
End Function
...全文
119 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
webserv2 2004-12-30
  • 打赏
  • 举报
回复
工具转的
private byte[] createThumnail(Stream ImageStream,Double tWidth,Double tHeight)
{
System.Drawing.Image g = System.Drawing.Image.FromStream(ImageStream);
System.Drawing.Size thumbSize = new Size(g.Width, g.Height, tWidth, tHeight);
System.Drawing.Bitmap imgOutput = new Bitmap(g,thumSize.Width,thumSize.Height);
System.IO.MemoryStream imgStream = new MemoryStream();
System.Drawing.Imaging.ImageFormat thisFormat = g.RawFormat;
imgOutput.Save(imgStream, thisFormat);
byte[] imgbin = new byte[imgStream.Length];
imgStream.Position = 0;
int n = imgStream.Read(imgbin,0,imgbin.Length);
g.Dispose();
imgOutput.Dispose();
return imgbin;
}

public int NewthumbSize(Double currentwidth,Double currentheight,Double newWidth, Double newHeight)
{
Double tempMultiplier;
if(currentheight > currentwidth)
tempMultiplier = newHeight / currentheight;
else
tempMultiplier = newWidth / currentwidth;
System.Drawing.Size NewSize = new Size(Convert.ToInt32(currentwidth * tempMultiplier),Convert.ToInt32(currentheight * tempMultiplier));
return NewSize;
}
slhuang 2004-12-30
  • 打赏
  • 举报
回复
这样试一下。只保证在C#的转换正确。不保证你的函数是否正确。
private byte[] createThumnail(Stream ImageStream,Double tWidth,Double tHeight)
{
System.Drawing.Image g = System.Drawing.Image.FromStream(ImageStream);
System.Drawing.Size thumbSize = new Size(g.Width, g.Height, tWidth, tHeight);
System.Drawing.Bitmap imgOutput = new Bitmap(g,thumSize.Width,thumSize.Height);
System.IO.MemoryStream imgStream = new MemoryStream();
System.Drawing.Imaging.ImageFormat thisFormat = g.RawFormat;
imgOutput.Save(imgStream, thisFormat);
byte[] imgbin = new byte[imgStream.Length];
imgStream.Position = 0;
int n = imgStream.Read(imgbin,0,imgbin.Length);
g.Dispose();
imgOutput.Dispose();
return imgbin;
}

public int NewthumbSize(Double currentwidth,Double currentheight,Double newWidth, Double newHeight)
{
Double tempMultiplier;
if(currentheight > currentwidth)
tempMultiplier = newHeight / currentheight;
else
tempMultiplier = newWidth / currentwidth;
System.Drawing.Size NewSize = new Size(Convert.ToInt32(currentwidth * tempMultiplier),Convert.ToInt32(currentheight * tempMultiplier));
return NewSize;
}
孟子E章 2004-12-30
  • 打赏
  • 举报
回复
private byte[] createThumnail(Stream ImageStream, double tWidth, double tHeight)
{
System.Drawing.Image g = System.Drawing.Image.FromStream(ImageStream);
Size thumbSize = new Size();
thumbSize = NewthumbSize(g.Width, g.Height, tWidth, tHeight);
Bitmap imgOutput = new Bitmap(g, thumbSize.Width, thumbSize.Height);
MemoryStream imgStream = new MemoryStream();
object thisFormat = g.RawFormat;
imgOutput.Save(imgStream, thisFormat);
byte[imgStream.Length] imgbin;
imgStream.Position = 0;
Int32 n = imgStream.Read(imgbin, 0, imgbin.Length);
g.Dispose();
imgOutput.Dispose();
return imgbin;
}

object NewthumbSize(double currentwidth, double currentheight, double newWidth, double newHeight)
{
double tempMultiplier;
if (currentheight > currentwidth) {
tempMultiplier = newHeight / currentheight;
} else {
tempMultiplier = newWidth / currentwidth;
}
Size NewSize = new Size(System.Convert.ToInt32(currentwidth * tempMultiplier), System.Convert.ToInt32(currentheight * tempMultiplier));
return NewSize;
}
孟子E章 2004-12-30
  • 打赏
  • 举报
回复
http://dotnet.aspx.cc/ShowDetail.aspx?id=45E7E33C-F149-450E-B5D5-832958C20538

在ASP.NET里轻松实现缩略图vb.net c#版

http://dotnet.aspx.cc/Exam/Thumbnail.aspx
孟子E章 2004-12-30
  • 打赏
  • 举报
回复
VB.net -> C# 工具

http://www.developerfusion.com/utilities/convertvbtocsharp.aspx

softchao 2004-12-30
  • 打赏
  • 举报
回复
xxwnet 2004-12-30
  • 打赏
  • 举报
回复
UP
potato__ 2004-12-30
  • 打赏
  • 举报
回复
你能不能帮忙该一下呀
源码在http://www.cnblogs.com/rippleyong/archive/2004/08/10/31977.aspx
我只要改变图片的大小的一些函数
sukaru 2004-12-30
  • 打赏
  • 举报
回复
楼主这段vb代码本身就有问题吧?本身错误怎么翻译啊?

62,041

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧