日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > C# >内容正文

C#

php图片变成代码怎么解决,一段图片处理代码PHP代码转C#代码,该怎么解决

發布時間:2024/4/11 C# 22 豆豆
生活随笔 收集整理的這篇文章主要介紹了 php图片变成代码怎么解决,一段图片处理代码PHP代码转C#代码,该怎么解决 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

一段圖片處理代碼PHP代碼轉C#代碼

把下面代碼轉換成?C#代碼

$res?=?json_decode(stripslashes($_POST['jsondata']),?true);

/*?get?data?*/

$count_images?=?count($res['images']);

/*?the?background?image?is?the?first?one?*/

$background?=?$res['images'][0]['src'];

$photo1?=?imagecreatefromjpeg($background);

$foto1W?=?imagesx($photo1);

$foto1H?=?imagesy($photo1);

$photoFrameW?=?$res['images'][0]['width'];

$photoFrameH?=?$res['images'][0]['height'];

$photoFrame?=?imagecreatetruecolor($photoFrameW,$photoFrameH);

imagecopyresampled($photoFrame,?$photo1,?0,?0,?0,?0,?$photoFrameW,?$photoFrameH,?$foto1W,?$foto1H);

/*?the?other?images?*/

for($i?=?1;?$i?

$insert?=?$res['images'][$i]['src'];

$photoFrame2Rotation?=?(180-$res['images'][$i]['rotation'])?+?180;

$photo2?=?imagecreatefrompng($insert);

$foto2W?=?imagesx($photo2);

$foto2H?=?imagesy($photo2);

$photoFrame2W=?$res['images'][$i]['width'];

$photoFrame2H?=?$res['images'][$i]['height'];

$photoFrame2TOP?=?$res['images'][$i]['top'];

$photoFrame2LEFT=?$res['images'][$i]['left'];

$photoFrame2?=?imagecreatetruecolor($photoFrame2W,$photoFrame2H);

$trans_colour?=?imagecolorallocatealpha($photoFrame2,?0,?0,?0,?127);

imagefill($photoFrame2,?0,?0,?$trans_colour);

imagecopyresampled($photoFrame2,?$photo2,?0,?0,?0,?0,?$photoFrame2W,?$photoFrame2H,?$foto2W,?$foto2H);

$photoFrame2?=?imagerotate($photoFrame2,$photoFrame2Rotation,?-1,0);

/*after?rotating?calculate?the?difference?of?new?height/width?with?the?one?before*/

$extraTop=(imagesy($photoFrame2)-$photoFrame2H)/2;

$extraLeft=(imagesx($photoFrame2)-$photoFrame2W)/2;

imagecopy($photoFrame,?$photoFrame2,$photoFrame2LEFT-$extraLeft,?$photoFrame2TOP-$extraTop,?0,?0,?imagesx($photoFrame2),?imagesy($photoFrame2));

}

//?Set?the?content?type?header?-?in?this?case?image/jpeg

header('Content-type:?image/jpeg');

imagejpeg($photoFrame,?$targetfile);

imagedestroy($photoFrame);

------解決方案--------------------

//使用圖片為水印

public?static?string?ReSizePhoto(string?filePath,?string?LogoPath,?int?width,?int?height)

{

string?fileName?=?System.IO.Path.GetFileName(filePath).ToLower();

string?fileExtension?=?System.IO.Path.GetExtension(filePath).ToLower();

string?document?=?System.IO.Path.GetDirectoryName(filePath)?+?"\\";

bool?check?=?false;

switch?(fileExtension)

{

case?".jpg":?check?=?true;

break;

case?".gif":?check?=?true;

break;

default:?check?=?false;

break;

}

//圖片按比例縮放算法

if?(check)

{

string?saveName?=?Squirrel.Component.doEncrypt.SMD5(Guid.NewGuid().ToString().Replace("-",?"")).Replace("-",?"").ToLower().Substring(8,?16)?+?fileExtension;

System.Drawing.Image?image?=?System.Drawing.Image.FromFile(filePath);

double?h?=?Convert.ToDouble(image.Height.ToString());

double?w?=?Convert.ToDouble(image.Width.ToString());

double?bl?=?h?/?w;

超強干貨來襲 云風專訪:近40年碼齡,通宵達旦的技術人生

總結

以上是生活随笔為你收集整理的php图片变成代码怎么解决,一段图片处理代码PHP代码转C#代码,该怎么解决的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。