//產生圓圖的函數 void toDisk(Bitmap^ im) { int W = im->Width, H = im->Height; if (W!=H) { cout<<"W!=H\n"; return; } Bitmap im2(W, H); double s, t, c = (W -1)/ 2.0 , r=W/2.0; Color Black = Color::FromArgb(0, 0, 0); for (int x = 0; x < W; x++) { s = x - c; for (int y = 0; y < H; y++){ Color pixel = im->GetPixel(x, y); t = y - c; if (s*s + t*t > r*r) pixel = Black; im2.SetPixel(x, y, pixel); } } im2.MakeTransparent(Black); im2.Save("disk.png"); }
herrDeng網內搜尋
自訂搜尋
Ads
2017年12月13日 星期三
ex11 C++/CLI Bitmap圓圖旋轉
訂閱:
張貼留言 (Atom)
熱門文章
-
url="https://www.twse.com.tw/exchangeReport/STOCK_DAY?response=json&date=20220330&stockNo=2330"
-
教育部為提昇全民資安素養與電腦防護能力,本部於101年9月5日至11月5日舉辦「全民資安素養自我評量」活動,請在活動期間內踴躍上網檢測資訊安全素養認知程度,並有機會參與抽獎,詳情請參閱活動網站(網址: https://isafe.moe.edu.tw/event
-
python pandas對黃金、外匯匯率的爬蟲練習,並使用matplotlib.pyplot的函數plot, scatter做資料視覺化處理,採用numpy的統計函數,分析黃金價格波動與歐元走勢的關聯。
-
Python C C++ 2 pointer速解Leetcode 2337 Move Pieces to Obtain a String 多日Leetcode的問題都可用2-pointer法來解,今日2337. Move Pieces to Obtain a String也不例...
-
你會用C的算子sizeof?
32 則留言:
void toDisk(Bitmap^ im) {
int W = im->Width, H = im->Height;
if (W != H) {
cout << "W!=H\n";
return;
}
Bitmap im2(W, H);
double s, t, c = (W - 1) / 2.0, r = W / 2.0;
Color Black = Color::FromArgb(0, 0, 0);
for (int x = 0; x < W; x++) {
s = x - c;
for (int y = 0; y < H; y++) {
Color pixel = im->GetPixel(x, y);
t = y - c;
if (s*s + t*t > r*r)
pixel = Black;
im2.SetPixel(x, y, pixel);
}
}
im2.MakeTransparent(Black);
im2.Save("disk.png");
}
int Clamp(int x, int L, int U) {
if (x < L)return L;
else if (x > U)return U;
else return x;
}
void rotate(Bitmap^ im,int angle) {
int W = im->Width, H = im->Height;
Bitmap im2(W, H);
double s, t, c = (W - 1) / 2.0, r = W / 2.0;
const double PI = 3.1415926535897932384626433832795;
double theta = angle*PI / 180;
double sin_t = sin(theta), cos_t = cos(theta);
Color Black = Color::FromArgb(0, 0, 0);
for (int x = 0; x < W; x++) {
s = x - c;
for (int y = 0; y < H; y++)
{
t = y - c;
int xPrime = (int)round(s*cos_t - t*sin_t + c);
int yPrime = (int)round(s*sin_t + t*cos_t + c);
xPrime = Clamp(xPrime, 0, W - 1);
yPrime = Clamp(yPrime, 0, W - 1);
Color pixel = im->GetPixel(xPrime, yPrime);
if( s*s + t*t > r*r) pixel = Black;
im2.SetPixel(x, y, pixel);
}
}
im2.MakeTransparent(Black);
im2.Save("rotate.png");
}
void toDisk(Bitmap^ im) {
int W = im->Width, H = im->Height;
if (W != H) {
cout << "W!=H\n";
return;
}
Bitmap im2(W, H);
double s, t, c = (W - 1) / 2.0, r = W / 2.0;
Color Black = Color::FromArgb(0, 0, 0);
for (int x = 0; x < W; x++) {
s = x - c;
for (int y = 0; y < H; y++) {
Color pixel = im->GetPixel(x, y);
t = y - c;
if (s*s + t*t > r*r)
pixel = Black;
im2.SetPixel(x, y, pixel);
}
}
im2.MakeTransparent(Black);
im2.Save("disk.png");
}
int Clamp(int x, int L, int U) {
if (x < L)return L;
else if (x > U)return U;
else return x;
}
void rotate(Bitmap^ im,int angle) {
int W = im->Width, H = im->Height;
Bitmap im2(W, H);
double s, t, c = (W - 1) / 2.0, r = W / 2.0;
const double PI = 3.1415926535897932384626433832795;
double theta = angle*PI / 180;
double sin_t = sin(theta), cos_t = cos(theta);
Color Black = Color::FromArgb(0, 0, 0);
for (int x = 0; x < W; x++) {
s = x - c;
for (int y = 0; y < H; y++)
{
t = y - c;
int xPrime = (int)round(s*cos_t - t*sin_t + c);
int yPrime = (int)round(s*sin_t + t*cos_t + c);
xPrime = Clamp(xPrime, 0, W - 1);
yPrime = Clamp(yPrime, 0, W - 1);
Color pixel = im->GetPixel(xPrime, yPrime);
if( s*s + t*t > r*r) pixel = Black;
im2.SetPixel(x, y, pixel);
}
}
im2.MakeTransparent(Black);
im2.Save("rotate.png");
}
void toDisk(Bitmap^ im) {
int W = im->Width, H = im->Height;
if (W != H) {
cout << "W!=H\n";
return;
}
Bitmap im2(W, H);
double s, t, c = (W - 1) / 2.0, r = W / 2.0;
Color Black = Color::FromArgb(0, 0, 0);
for (int x = 0; x < W; x++) {
s = x - c;
for (int y = 0; y < H; y++) {
Color pixel = im->GetPixel(x, y);
t = y - c;
if (s*s + t*t > r*r)
pixel = Black;
im2.SetPixel(x, y, pixel);
}
}
im2.MakeTransparent(Black);
im2.Save("disk.png");
}
int Clamp(int x, int L, int U) {
if (x < L)return L;
else if (x > U)return U;
else return x;
}
void rotate(Bitmap^ im,int angle) {
int W = im->Width, H = im->Height;
Bitmap im2(W, H);
double s, t, c = (W - 1) / 2.0, r = W / 2.0;
const double PI = 3.1415926535897932384626433832795;
double theta = angle*PI / 180;
double sin_t = sin(theta), cos_t = cos(theta);
Color Black = Color::FromArgb(0, 0, 0);
for (int x = 0; x < W; x++) {
s = x - c;
for (int y = 0; y < H; y++)
{
t = y - c;
int xPrime = (int)round(s*cos_t - t*sin_t + c);
int yPrime = (int)round(s*sin_t + t*cos_t + c);
xPrime = Clamp(xPrime, 0, W - 1);
yPrime = Clamp(yPrime, 0, W - 1);
Color pixel = im->GetPixel(xPrime, yPrime);
if( s*s + t*t > r*r) pixel = Black;
im2.SetPixel(x, y, pixel);
}
}
im2.MakeTransparent(Black);
im2.Save("rotate.png");
}
void toDisk(Bitmap^ im) {
int W = im->Width, H = im->Height;
if (W != H) {
cout << "W!=H\n";
return;
}
Bitmap im2(W, H);
double s, t, c = (W - 1) / 2.0, r = W / 2.0;
Color Black = Color::FromArgb(0, 0, 0);
for (int x = 0; x < W; x++) {
s = x - c;
for (int y = 0; y < H; y++) {
Color pixel = im->GetPixel(x, y);
t = y - c;
if (s*s + t*t > r*r)
pixel = Black;
im2.SetPixel(x, y, pixel);
}
}
im2.MakeTransparent(Black);
im2.Save("disk.png");
}
int Clamp(int x, int L, int U) {
if (x < L)return L;
else if (x > U)return U;
else return x;
}
void rotate(Bitmap^ im,int angle) {
int W = im->Width, H = im->Height;
Bitmap im2(W, H);
double s, t, c = (W - 1) / 2.0, r = W / 2.0;
const double PI = 3.1415926535897932384626433832795;
double theta = angle*PI / 180;
double sin_t = sin(theta), cos_t = cos(theta);
Color Black = Color::FromArgb(0, 0, 0);
for (int x = 0; x < W; x++) {
s = x - c;
for (int y = 0; y < H; y++)
{
t = y - c;
int xPrime = (int)round(s*cos_t - t*sin_t + c);
int yPrime = (int)round(s*sin_t + t*cos_t + c);
xPrime = Clamp(xPrime, 0, W - 1);
yPrime = Clamp(yPrime, 0, W - 1);
Color pixel = im->GetPixel(xPrime, yPrime);
if( s*s + t*t > r*r) pixel = Black;
im2.SetPixel(x, y, pixel);
}
}
im2.MakeTransparent(Black);
im2.Save("rotate.png");
}
void toDisk(Bitmap^ im) {
int W = im->Width, H = im->Height;
if (W != H) {
cout << "W!=H\n";
return;
}
Bitmap im2(W, H);
double s, t, c = (W - 1) / 2.0, r = W / 2.0;
Color Black = Color::FromArgb(0, 0, 0);
for (int x = 0; x < W; x++) {
s = x - c;
for (int y = 0; y < H; y++) {
Color pixel = im->GetPixel(x, y);
t = y - c;
if (s*s + t*t > r*r)
pixel = Black;
im2.SetPixel(x, y, pixel);
}
}
im2.MakeTransparent(Black);
im2.Save("disk.png");
}
int Clamp(int x, int L, int U) {
if (x < L)return L;
else if (x > U)return U;
else return x;
}
void rotate(Bitmap^ im,int angle) {
int W = im->Width, H = im->Height;
Bitmap im2(W, H);
double s, t, c = (W - 1) / 2.0, r = W / 2.0;
const double PI = 3.1415926535897932384626433832795;
double theta = angle*PI / 180;
double sin_t = sin(theta), cos_t = cos(theta);
Color Black = Color::FromArgb(0, 0, 0);
for (int x = 0; x < W; x++) {
s = x - c;
for (int y = 0; y < H; y++)
{
t = y - c;
int xPrime = (int)round(s*cos_t - t*sin_t + c);
int yPrime = (int)round(s*sin_t + t*cos_t + c);
xPrime = Clamp(xPrime, 0, W - 1);
yPrime = Clamp(yPrime, 0, W - 1);
Color pixel = im->GetPixel(xPrime, yPrime);
if( s*s + t*t > r*r) pixel = Black;
im2.SetPixel(x, y, pixel);
}
}
im2.MakeTransparent(Black);
im2.Save("rotate.png");
}
void toDisk(Bitmap^ im) {
int W = im->Width, H = im->Height;
if (W != H) {
cout << "W!=H\n";
return;
}
Bitmap im2(W, H);
double s, t, c = (W - 1) / 2.0, r = W / 2.0;
Color Black = Color::FromArgb(0, 0, 0);
for (int x = 0; x < W; x++) {
s = x - c;
for (int y = 0; y < H; y++) {
Color pixel = im->GetPixel(x, y);
t = y - c;
if (s*s + t*t > r*r)
pixel = Black;
im2.SetPixel(x, y, pixel);
}
}
im2.MakeTransparent(Black);
im2.Save("disk.png");
}
int Clamp(int x, int L, int U) {
if (x < L)return L;
else if (x > U)return U;
else return x;
}
void rotate(Bitmap^ im,int angle) {
int W = im->Width, H = im->Height;
Bitmap im2(W, H);
double s, t, c = (W - 1) / 2.0, r = W / 2.0;
const double PI = 3.1415926535897932384626433832795;
double theta = angle*PI / 180;
double sin_t = sin(theta), cos_t = cos(theta);
Color Black = Color::FromArgb(0, 0, 0);
for (int x = 0; x < W; x++) {
s = x - c;
for (int y = 0; y < H; y++)
{
t = y - c;
int xPrime = (int)round(s*cos_t - t*sin_t + c);
int yPrime = (int)round(s*sin_t + t*cos_t + c);
xPrime = Clamp(xPrime, 0, W - 1);
yPrime = Clamp(yPrime, 0, W - 1);
Color pixel = im->GetPixel(xPrime, yPrime);
if( s*s + t*t > r*r) pixel = Black;
im2.SetPixel(x, y, pixel);
}
}
im2.MakeTransparent(Black);
im2.Save("rotate.png");
}
void to_rotate(Bitmap^ im,double angle) {
int W = im->Width, H = im->Height;
Bitmap im2(W, H);
double s, t, c = (W - 1) / 2.0, r = W / 2.0;
Color Black = Color::FromArgb(0, 0, 0);
const double PI = 3.1415926535897932384626433832795;
double theta = angle*PI / 180;
double sin_t = sin(theta), cos_t = cos(theta);
for (int x = 0; x < W; x++) {
t = x - c;
for (int y = 0; y < H; y++) {
t = y - c;
int xPrime = (int)(round(s*cos_t - t*sin_t + c));
int yPrime = (int)(round(s*sin_t + t*cos_t + c));
Color pixel = im->GetPixel(xPrime, yPrime);
if (s*s + t + t > r*r) pixel = Black;
im2.SetPixel(x, y, pixel);
}
}
im2.MakeTransparent(Black);
im2.Save("rotate.png");
}
//將圓圖旋轉
void rotate(Bitmap^ im,double angle) {
int W = im->Width, H = im->Height;
//宣告整數值W、H,將圖片的寬跟長傳到W、H
//宣告浮點數 S、T、C(圓心)、R(半徑)
Bitmap im2(W, H); //宣告物件 im2 (W=寬,H=長)
double s, t, c = (W - 1) / 2.0, r = W / 2.0;
//常數 const double PI 不可變
const double PI = 3.1415926535897932384626433832795;
//
double theta = angle / 180.0*PI;
double sin_t = sin(theta), cos_t = cos(theta);
//
Color Black = Color::FromArgb(0, 0, 0);
for (int x = 0; x < W; x++) {
s = x - c;
for (int y = 0; y < H; y++) {
t = y - c;
//
int xOld = (int)round(s*cos_t - t*sin_t + c);
xOld = Clamp(xOld, 0, W - 1);
int yOld = (int)round(s*sin_t + t*cos_t + c);
yOld = Clamp(yOld, 0, H - 1);
Color pixel = im->GetPixel(xOld, yOld);
//畫圓圈之外變成黑色
if (s*s + t*t > r*r)
pixel = Black;
im2.SetPixel(x, y, pixel);
}
}
//將黑色部分去背
im2.MakeTransparent(Black);
//存為 "Rotate+度數.png"
//im2.Save("Rotate"+angle+"度.png");
//字串串流作法
stringstream ss;
ss << "Rotate" << angle << "度.png";
char ff[200];
ss >> ff;
im2.Save(gcnew System::String(ff));
}
void rotate(Bitmap^ im, double angle) {
int W = im->Width, H = im->Height;
Bitmap im2(W, H);
double s, t, c = (W - 1) / 2.0, r = W / 2.0;
Color Black = Color::FromArgb(0, 0, 0);
const double PI = 3.1415926535897932384626433832795;
double theta = angle*PI / 180;
double sin_t = sin(theta), cos_t = cos(theta);
for (int x = 0; x < W; x++) {
s = x - c;
for (int y = 0; y < H; y++) {
t = y - c;
int xPrime = (int)(round(s*cos_t - t*sin_t + c));
int yPrime = (int)(round(s*sin_t + t*sin_t + c));
xPrime = Clamp(xPrime, 0, W - 1);
yPrime = Clamp(xPrime, 0, W - 1);
Color pixel = im->GetPixel(xPrime, yPrime);
if (s*s + t*t > r*r)pixel = Black;
im2.SetPixel(x, y, pixel);
}
}
im2.MakeTransparent(Black);
im2.Save("rotate" + angle + ".png");
}
void rotate(Bitmap^im, int angle) {
int W = im->Width, H = im->Height;
Bitmap im2(W, H);
double s, t, c = (W - 1) / 2.0, r = w / 2.0;
Color Black = Color::FromArgb(0, 0, 0);
const double PI = 3.1415926535897932384626433832795;
double theta = angle* PI / 180;
double sin_(theat), cos_t = cos(theta);
for (int y = 0; y < H; y++) {
t = y - c;
int xPrime = (int)(round(s*cos_t - t*sin_t + c));
int yPrime = (int)(round(s*sin_t + t*cos_t + c));
xPrime = Clamp(xPrime, 0, w - 1);
yPrime = Clamp(yPrime, 0, w - 1);
Color pixel = im->Getpixel(xprime, yprime);
if (s*s + t*t > r*r) pixel = Black;
im2.setpixel(x, y, pixel);
}
}
im2.MakeTransparent(Black);
im2.save("rotate.png");
}
void rotate(Bitmap^ im, double angle) {
int W = im->Width, H = Height;
Bitmap im2(W, H);
double s, t, c = (W - 1) / 2.0, r = W / 2.0;
Color Black = Color::FormArgb(0, 0, 0);
const double PI = 3.1415926535897932384626433832795;
double theta = angle*PI / 180;
double sin_t = sin(theta), cos_t = cos(theta);
for (int x = 0; x < W; x++) {
s = x - c;
for (int y = 0; y < H; y++) {
t = y - c;
int xPrime = (int)(round(s*cos_t - t*sin_t + c));
int yPrime = (int)(round(s*sin_t - t*cos_t + c));
xPrime = Clamp(xPrime, 0, W - 1);
yPrime = Clamp(yPrime, 0, W - 1);
Color pixel = im->GetPixel(xPrime, yPrime);
if (s*s + t*t > r*r) pixel = Black;
im2.SetPixel(x, y, pixel);
}
}
im2.MakeTransparent(Black);
im2.Save("rotate.png");
}
//將圓圖旋轉
void rotate(Bitmap^ im,double angle) {
int W = im->Width, H = im->Height;
//宣告整數值W、H,將圖片的寬跟長傳到W、H
//宣告浮點數 S、T、C(圓心)、R(半徑)
Bitmap im2(W, H); //宣告物件 im2 (W=寬,H=長)
double s, t, c = (W - 1) / 2.0, r = W / 2.0;
//常數 const double PI 不可變
const double PI = 3.1415926535897932384626433832795;
//
double theta = angle / 180.0*PI;
double sin_t = sin(theta), cos_t = cos(theta);
//
Color Black = Color::FromArgb(0, 0, 0);
for (int x = 0; x < W; x++) {
s = x - c;
for (int y = 0; y < H; y++) {
t = y - c;
//
int xOld = (int)round(s*cos_t - t*sin_t + c);
xOld = Clamp(xOld, 0, W - 1);
int yOld = (int)round(s*sin_t + t*cos_t + c);
yOld = Clamp(yOld, 0, H - 1);
Color pixel = im->GetPixel(xOld, yOld);
//畫圓圈之外變成黑色
if (s*s + t*t > r*r)
pixel = Black;
im2.SetPixel(x, y, pixel);
}
}
//將黑色部分去背
im2.MakeTransparent(Black);
//存為 "Rotate+度數.png"
//im2.Save("Rotate"+angle+"度.png");
//字串串流作法
stringstream ss;
ss << "Rotate" << angle << "度.png";
char ff[200];
ss >> ff;
im2.Save(gcnew System::String(ff));
}
void rotate(Bitmap^ im, double angle) {
int W = im->Width, H = im->Height;
Bitmap im2(W, H);
double s, t, c = (W - 1) / 2.0, r = W / 2.0;
Color Black = Color::FromArgb(0, 0, 0);
const double PI = 3.1415926535897932384626433832795;
double theta = angle*PI / 180;
double sin_t = sin(theta), cos_t = cos(theta);
for (int x = 0; x < W; x++) {
s = x - c;
for (int y = 0; y < H; y++) {
t = y - c;
int xPrime = (int)(round(s*cos_t - t*sin_t + c));
int yPrime = (int)(round(s*sin_t + t*cos_t + c));
xPrime = Clamp(xPrime, 0, W - 1);
yPrime = Clamp(yPrime, 0, W - 1);
Color pixel = im->GetPixel(xPrime, yPrime);
if (s*s + t*t > r*r) pixel = Black;
im2.SetPixel(x, y, pixel);
}
}
im2.MakeTransparent(Black);
im2.Save("rotate"+angle+".png");
}
void rotate(Bitmap^ im, double angle) {
int W = im->Width, H = im->Height;
Bitmap im2(W, H);
double s, t, c = (W - 1) / 2.0, r = W / 2.0;
Color Black = Color::FromArgb(0, 0, 0);
const double PI = 3.1415926535897932384626433832795;
double theta = angle*PI / 180;
double sin_t = sin(theta), cos_t = cos(theta);
for (int x = 0; x < W; x++) {
s = x - c;
for (int y = 0; y < H; y++) {
t = y - c;
int xPrime = (int)(round(s*cos_t - t*sin_t + c));
int yPrime = (int)(round(s*sin_t + t*cos_t + c));
xPrime = Clamp(xPrime, 0, W - 1);
yPrime = Clamp(yPrime, 0, W - 1);
Color pixel = im->GetPixel(xPrime, yPrime);
if (s*s + t*t > r*r) pixel = Black;
im2.SetPixel(x, y, pixel);
}
}
im2.MakeTransparent(Black);
im2.Save("rotate"+angle+".png");
}
void rotate(Bitmap^ im, double angle) {
int W = im->Width, H = im->Height;
Bitmap im2(W, H);
double s, t, c = (W - 1) / 2.0, r = W / 2.0;
Color Black = Color::FromArgb(0, 0, 0);
const double PI = 3.1415926535897932384626433832795;
double theta = angle*PI / 180;
double sin_t = sin(theta), cos_t = cos(theta);
for (int x = 0; x < W; x++) {
s = x - c;
for (int y = 0; y < H; y++) {
t = y - c;
int xPrime = (int)(round(s*cos_t - t*sin_t + c));
int yPrime = (int)(round(s*sin_t + t*sin_t + c));
xPrime = Clamp(xPrime, 0, W - 1);
yPrime = Clamp(xPrime, 0, W - 1);
Color pixel = im->GetPixel(xPrime, yPrime);
if (s*s + t*t > r*r)pixel = Black;
im2.SetPixel(x, y, pixel);
}
}
im2.MakeTransparent(Black);
im2.Save("rotate" + angle + ".png");
}
void rotate(Bitmap^ im, double angle) {
int W = im->Width, H = im->Height;
Bitmap im2(W, H);
double s, t, c = (W - 1) / 2.0, r = W / 2.0;
Color Black = Color::FromArgb(0, 0, 0);
const double PI = 3.1415926535897932384626433832795;
double theta = angle*PI / 180;
double sin_t = sin(theta), cos_t = cos(theta);
for (int x = 0; x < W; x++) {
s = x - c;
for (int y = 0; y < H; y++) {
t = y - c;
int xPrime = (int)(round(s*cos_t - t*sin_t + c));
int yPrime = (int)(round(s*sin_t + t*cos_t + c));
xPrime = Clamp(xPrime, 0, W - 1);
yPrime = Clamp(yPrime, 0, W - 1);
Color pixel = im->GetPixel(xPrime, yPrime);
if (s*s + t*t > r*r) pixel = Black;
im2.SetPixel(x, y, pixel);
}
}
im2.MakeTransparent(Black);
im2.Save("rotate"+angle+".png");
}
void rotate(Bitmap^ im, double angle) {
int W = im->Width, H = im->Height;
Bitmap im2(W, H);
double s, t, c = (W - 1) / 2.0, r = W / 2.0;
Color Black = Color::FromArgb(0, 0, 0);
const double PI = 3.1415926535897932384626433832795;
double theta = angle*PI / 180;
double sin_t = sin(theta), cos_t = cos(theta);
for (int x = 0; x < W; x++) {
s = x - c;
for (int y = 0; y < H; y++) {
t = y - c;
int xPrime = (int)(round(s*cos_t - t*sin_t + c));
int yPrime = (int)(round(s*sin_t + t*cos_t + c));
xPrime = Clamp(xPrime, 0, W - 1);
yPrime = Clamp(yPrime, 0, W - 1);
Color pixel = im->GetPixel(xPrime, yPrime);
if (s*s + t*t > r*r) pixel = Black;
im2.SetPixel(x, y, pixel);
}
}
im2.MakeTransparent(Black);
im2.Save("rotate"+angle+".png");
}
void rotate(Bitmap^ im, double angle) {
int W = im->Width, H = im->Height;
Bitmap im2(W, H);
double s, t, c = (W - 1) / 2.0, r = W / 2.0;
Color Black = Color::FromArgb(0, 0, 0);
const double PI = 3.1415926535897932384626433832795;
double theta = angle*PI / 180;
double sin_t = sin(theta), cos_t = cos(theta);
for (int x = 0; x < W; x++) {
s = x - c;
for (int y = 0; y < H; y++) {
t = y - c;
int xPrime = (int)(round(s*cos_t - t*sin_t + c));
int yPrime = (int)(round(s*sin_t + t*cos_t + c));
xPrime = Clamp(xPrime, 0, W - 1);
yPrime = Clamp(yPrime, 0, W - 1);
Color pixel = im->GetPixel(xPrime, yPrime);
if (s*s + t*t > r*r) pixel = Black;
im2.SetPixel(x, y, pixel);
}
}
im2.MakeTransparent(Black);
im2.Save("rotate"+angle+".png");
}
void rotate(Bitmap^ im, double angle) {
int W = im->Width, H = im->Height;
Bitmap im2(W, H);
double s, t, c = (W - 1) / 2.0, r = W / 2.0;
Color Black = Color::FromArgb(0, 0, 0);
const double PI = 3.1415926535897932384626433832795;
double theta = angle*PI / 180;
double sin_t = sin(theta), cos_t = cos(theta);
for (int x = 0; x < W; x++) {
s = x - c;
for (int y = 0; y < H; y++) {
t = y - c;
int xPrime = (int)(round(s*cos_t - t*sin_t + c));
int yPrime = (int)(round(s*sin_t + t*cos_t + c));
xPrime = Clamp(xPrime, 0, W - 1);
yPrime = Clamp(yPrime, 0, W - 1);
Color pixel = im->GetPixel(xPrime, yPrime);
if (s*s + t*t > r*r) pixel = Black;
im2.SetPixel(x, y, pixel);
}
}
im2.MakeTransparent(Black);
im2.Save("rotate"+angle+".png");
}
#include <iostream>
#include <cstdlib>
#include <cmath>
#include<sstream>
using namespace std;
#using <System.Drawing.dll>
using namespace System::Drawing;
void rotate(Bitmap^ im,int angle) {
int W = im->Width, H = im->Height;
Bitmap im2(W, H);
double s, t, c = (W - 1) / 2.0, r = W / 2.0;
const double PI = 3.1415926535897932384626433832795;
double theta = angle / 180.0*PI;
double sin_t = sin(theta), cos_t = cos(theta);
Color Black = Color::FromArgb(0, 0, 0);
for (int x = 0; x < W; x++) {
s = x - c;
for (int y = 0; y < H; y++) {
t = y - c;
int xPrime = (int)round(s* cos_t - t*sin_t + c);
int yPrime = (int)round(s* sin_t + t*cos_t + c);
xPrime=Clamp(xPrime, 0, W - 1);
yPrime = Clamp(yPrime, 0, W - 1);
Color pixel = im->GetPixel(xPrime, yPrime);
if (s*s + t*t > r*r) pixel = Black;
im2.SetPixel(x, y, pixel);
}
}
im2.MakeTransparent(Black);
stringstream ss;
ss<<"rotate"<<angle<<".png";
char ff[200];
ss >> ff;
im2.Save(gcnew System::String(ff));
}
int main()
{
Bitmap^ im = gcnew Bitmap("2.jpg");
double angle;
cout << "旋轉角度:";
cin >> angle;
angle = fmod(angle, 360);
rotate(im, angle);
cout << "圖檔練習。\n";
system("Pause");
return 0;
}
#include
#include
#include
#include
using namespace std;
#using
using namespace System::Drawing;
void rotate(Bitmap^ im,int angle) {
int W = im->Width, H = im->Height;
Bitmap im2(W, H);
double s, t, c = (W - 1) / 2.0, r = W / 2.0;
const double PI = 3.1415926535897932384626433832795;
double theta = angle / 180.0*PI;
double sin_t = sin(theta), cos_t = cos(theta);
Color Black = Color::FromArgb(0, 0, 0);
for (int x = 0; x < W; x++) {
s = x - c;
for (int y = 0; y < H; y++) {
t = y - c;
int xPrime = (int)round(s* cos_t - t*sin_t + c);
int yPrime = (int)round(s* sin_t + t*cos_t + c);
xPrime=Clamp(xPrime, 0, W - 1);
yPrime = Clamp(yPrime, 0, W - 1);
Color pixel = im->GetPixel(xPrime, yPrime);
if (s*s + t*t > r*r) pixel = Black;
im2.SetPixel(x, y, pixel);
}
}
im2.MakeTransparent(Black);
stringstream ss;
ss<<"rotate"<> ff;
im2.Save(gcnew System::String(ff));
}
int main()
{
Bitmap^ im = gcnew Bitmap("2.jpg");
double angle;
cout << "旋轉角度:";
cin >> angle;
angle = fmod(angle, 360);
rotate(im, angle);
cout << "圖檔練習。\n";
system("Pause");
return 0;
}
#include
#include
#include
#include
using namespace std;
#using
using namespace System::Drawing;
void rotate(Bitmap^ im,int angle) {
int W = im->Width, H = im->Height;
Bitmap im2(W, H);
double s, t, c = (W - 1) / 2.0, r = W / 2.0;
const double PI = 3.1415926535897932384626433832795;
double theta = angle / 180.0*PI;
double sin_t = sin(theta), cos_t = cos(theta);
Color Black = Color::FromArgb(0, 0, 0);
for (int x = 0; x < W; x++) {
s = x - c;
for (int y = 0; y < H; y++) {
t = y - c;
int xPrime = (int)round(s* cos_t - t*sin_t + c);
int yPrime = (int)round(s* sin_t + t*cos_t + c);
xPrime=Clamp(xPrime, 0, W - 1);
yPrime = Clamp(yPrime, 0, W - 1);
Color pixel = im->GetPixel(xPrime, yPrime);
if (s*s + t*t > r*r) pixel = Black;
im2.SetPixel(x, y, pixel);
}
}
im2.MakeTransparent(Black);
stringstream ss;
ss<<"rotate"<> ff;
im2.Save(gcnew System::String(ff));
}
int main()
{
Bitmap^ im = gcnew Bitmap("2.jpg");
double angle;
cout << "旋轉角度:";
cin >> angle;
angle = fmod(angle, 360);
rotate(im, angle);
cout << "圖檔練習。\n";
system("Pause");
return 0;
}
#include
#include
#include
#include
using namespace std;
#using
using namespace System::Drawing;
void rotate(Bitmap^ im,int angle) {
int W = im->Width, H = im->Height;
Bitmap im2(W, H);
double s, t, c = (W - 1) / 2.0, r = W / 2.0;
const double PI = 3.1415926535897932384626433832795;
double theta = angle / 180.0*PI;
double sin_t = sin(theta), cos_t = cos(theta);
Color Black = Color::FromArgb(0, 0, 0);
for (int x = 0; x < W; x++) {
s = x - c;
for (int y = 0; y < H; y++) {
t = y - c;
int xPrime = (int)round(s* cos_t - t*sin_t + c);
int yPrime = (int)round(s* sin_t + t*cos_t + c);
xPrime=Clamp(xPrime, 0, W - 1);
yPrime = Clamp(yPrime, 0, W - 1);
Color pixel = im->GetPixel(xPrime, yPrime);
if (s*s + t*t > r*r) pixel = Black;
im2.SetPixel(x, y, pixel);
}
}
im2.MakeTransparent(Black);
stringstream ss;
ss<<"rotate"<> ff;
im2.Save(gcnew System::String(ff));
}
int main()
{
Bitmap^ im = gcnew Bitmap("2.jpg");
double angle;
cout << "旋轉角度:";
cin >> angle;
angle = fmod(angle, 360);
rotate(im, angle);
cout << "圖檔練習。\n";
system("Pause");
return 0;
}
#include
#include
#include
#include
using namespace std;
#using
using namespace System::Drawing;
void rotate(Bitmap^ im,int angle) {
int W = im->Width, H = im->Height;
Bitmap im2(W, H);
double s, t, c = (W - 1) / 2.0, r = W / 2.0;
const double PI = 3.1415926535897932384626433832795;
double theta = angle / 180.0*PI;
double sin_t = sin(theta), cos_t = cos(theta);
Color Black = Color::FromArgb(0, 0, 0);
for (int x = 0; x < W; x++) {
s = x - c;
for (int y = 0; y < H; y++) {
t = y - c;
int xPrime = (int)round(s* cos_t - t*sin_t + c);
int yPrime = (int)round(s* sin_t + t*cos_t + c);
xPrime=Clamp(xPrime, 0, W - 1);
yPrime = Clamp(yPrime, 0, W - 1);
Color pixel = im->GetPixel(xPrime, yPrime);
if (s*s + t*t > r*r) pixel = Black;
im2.SetPixel(x, y, pixel);
}
}
im2.MakeTransparent(Black);
stringstream ss;
ss<<"rotate"<> ff;
im2.Save(gcnew System::String(ff));
}
int main()
{
Bitmap^ im = gcnew Bitmap("2.jpg");
double angle;
cout << "旋轉角度:";
cin >> angle;
angle = fmod(angle, 360);
rotate(im, angle);
cout << "圖檔練習。\n";
system("Pause");
return 0;
}
#include
#include
#include
#include
using namespace std;
#using
using namespace System::Drawing;
void rotate(Bitmap^ im,int angle) {
int W = im->Width, H = im->Height;
Bitmap im2(W, H);
double s, t, c = (W - 1) / 2.0, r = W / 2.0;
const double PI = 3.1415926535897932384626433832795;
double theta = angle / 180.0*PI;
double sin_t = sin(theta), cos_t = cos(theta);
Color Black = Color::FromArgb(0, 0, 0);
for (int x = 0; x < W; x++) {
s = x - c;
for (int y = 0; y < H; y++) {
t = y - c;
int xPrime = (int)round(s* cos_t - t*sin_t + c);
int yPrime = (int)round(s* sin_t + t*cos_t + c);
xPrime=Clamp(xPrime, 0, W - 1);
yPrime = Clamp(yPrime, 0, W - 1);
Color pixel = im->GetPixel(xPrime, yPrime);
if (s*s + t*t > r*r) pixel = Black;
im2.SetPixel(x, y, pixel);
}
}
im2.MakeTransparent(Black);
stringstream ss;
ss<<"rotate"<> ff;
im2.Save(gcnew System::String(ff));
}
int main()
{
Bitmap^ im = gcnew Bitmap("2.jpg");
double angle;
cout << "旋轉角度:";
cin >> angle;
angle = fmod(angle, 360);
rotate(im, angle);
cout << "圖檔練習。\n";
system("Pause");
return 0;
}
void rotate(Bitmap^ im, double angle) {
int W = im->Width, H = im->Height;
Bitmap im2(W, H);
double s, t, c = (W - 1) / 2.0, r = W / 2.0;
Color Black = Color::FromArgb(0, 0, 0);
const double PI = 3.1415926535897932384626433832795;
double theta = angle*PI / 180;
double sin_t = sin(theta), cos_t = cos(theta);
for (int x = 0; x < W; x++) {
s = x - c;
for (int y = 0; y < H; y++) {
t = y - c;
int xPrime = (int)(round(s*cos_t - t*sin_t + c));
int yPrime = (int)(round(s*sin_t + t*sin_t + c));
xPrime = Clamp(xPrime, 0, W - 1);
yPrime = Clamp(xPrime, 0, W - 1);
Color pixel = im->GetPixel(xPrime, yPrime);
if (s*s + t*t > r*r)pixel = Black;
im2.SetPixel(x, y, pixel);
}
}
im2.MakeTransparent(Black);
im2.Save("rotate" + angle + ".png");
}
void rotate(Bitmap^ im, double angle) {
int W = im->Width, H = im->Height;
Bitmap im2(W, H);
double s, t, c = (W - 1) / 2.0, r = W / 2.0;
Color Black = Color::FromArgb(0, 0, 0);
const double PI = 3.1415926535897932384626433832795;
double theta = angle*PI / 180;
double sin_t = sin(theta), cos_t = cos(theta);
for (int x = 0; x < W; x++) {
s = x - c;
for (int y = 0; y < H; y++) {
t = y - c;
int xPrime = (int)(round(s*cos_t - t*sin_t + c));
int yPrime = (int)(round(s*sin_t + t*sin_t + c));
xPrime = Clamp(xPrime, 0, W - 1);
yPrime = Clamp(xPrime, 0, W - 1);
Color pixel = im->GetPixel(xPrime, yPrime);
if (s*s + t*t > r*r)pixel = Black;
im2.SetPixel(x, y, pixel);
}
}
im2.MakeTransparent(Black);
im2.Save("rotate" + angle + ".png");
}
#include
#include
#include
#include
using namespace std;
#using
using namespace System::Drawing;
void rotate(Bitmap^ im,int angle) {
int W = im->Width, H = im->Height;
Bitmap im2(W, H);
double s, t, c = (W - 1) / 2.0, r = W / 2.0;
const double PI = 3.1415926535897932384626433832795;
double theta = angle / 180.0*PI;
double sin_t = sin(theta), cos_t = cos(theta);
Color Black = Color::FromArgb(0, 0, 0);
for (int x = 0; x < W; x++) {
s = x - c;
for (int y = 0; y < H; y++) {
t = y - c;
int xPrime = (int)round(s* cos_t - t*sin_t + c);
int yPrime = (int)round(s* sin_t + t*cos_t + c);
xPrime=Clamp(xPrime, 0, W - 1);
yPrime = Clamp(yPrime, 0, W - 1);
Color pixel = im->GetPixel(xPrime, yPrime);
if (s*s + t*t > r*r) pixel = Black;
im2.SetPixel(x, y, pixel);
}
}
im2.MakeTransparent(Black);
stringstream ss;
ss<<"rotate"<> ff;
im2.Save(gcnew System::String(ff));
}
int main()
{
Bitmap^ im = gcnew Bitmap("2.jpg");
double angle;
cout << "旋轉角度:";
cin >> angle;
angle = fmod(angle, 360);
rotate(im, angle);
cout << "圖檔練習。\n";
system("Pause");
return 0;
}
#include
#include
#include
#include
using namespace std;
#using
using namespace System::Drawing;
void rotate(Bitmap^ im,int angle) {
int W = im->Width, H = im->Height;
Bitmap im2(W, H);
double s, t, c = (W - 1) / 2.0, r = W / 2.0;
const double PI = 3.1415926535897932384626433832795;
double theta = angle / 180.0*PI;
double sin_t = sin(theta), cos_t = cos(theta);
Color Black = Color::FromArgb(0, 0, 0);
for (int x = 0; x < W; x++) {
s = x - c;
for (int y = 0; y < H; y++) {
t = y - c;
int xPrime = (int)round(s* cos_t - t*sin_t + c);
int yPrime = (int)round(s* sin_t + t*cos_t + c);
xPrime=Clamp(xPrime, 0, W - 1);
yPrime = Clamp(yPrime, 0, W - 1);
Color pixel = im->GetPixel(xPrime, yPrime);
if (s*s + t*t > r*r) pixel = Black;
im2.SetPixel(x, y, pixel);
}
}
im2.MakeTransparent(Black);
stringstream ss;
ss<<"rotate"<> ff;
im2.Save(gcnew System::String(ff));
}
int main()
{
Bitmap^ im = gcnew Bitmap("2.jpg");
double angle;
cout << "旋轉角度:";
cin >> angle;
angle = fmod(angle, 360);
rotate(im, angle);
cout << "圖檔練習。\n";
system("Pause");
return 0;
}
#include
#include
#include
#include
using namespace std;
#using
using namespace System::Drawing;
void rotate(Bitmap^ im,int angle) {
int W = im->Width, H = im->Height;
Bitmap im2(W, H);
double s, t, c = (W - 1) / 2.0, r = W / 2.0;
const double PI = 3.1415926535897932384626433832795;
double theta = angle / 180.0*PI;
double sin_t = sin(theta), cos_t = cos(theta);
Color Black = Color::FromArgb(0, 0, 0);
for (int x = 0; x < W; x++) {
s = x - c;
for (int y = 0; y < H; y++) {
t = y - c;
int xPrime = (int)round(s* cos_t - t*sin_t + c);
int yPrime = (int)round(s* sin_t + t*cos_t + c);
xPrime=Clamp(xPrime, 0, W - 1);
yPrime = Clamp(yPrime, 0, W - 1);
Color pixel = im->GetPixel(xPrime, yPrime);
if (s*s + t*t > r*r) pixel = Black;
im2.SetPixel(x, y, pixel);
}
}
im2.MakeTransparent(Black);
stringstream ss;
ss<<"rotate"<> ff;
im2.Save(gcnew System::String(ff));
}
int main()
{
Bitmap^ im = gcnew Bitmap("2.jpg");
double angle;
cout << "旋轉角度:";
cin >> angle;
angle = fmod(angle, 360);
rotate(im, angle);
cout << "圖檔練習。\n";
system("Pause");
return 0;
}
void toDisk(Bitmap^ im) {
int W = im->Width, H = im->Height;
if (W != H) {
cout << "W!=H\n";
return;
}
Bitmap im2(W, H);
double s, t, c = (W - 1) / 2.0, r = W / 2.0;
Color Black = Color::FromArgb(0, 0, 0);
for (int x = 0; x < W; x++) {
s = x - c;
for (int y = 0; y < H; y++) {
Color pixel = im->GetPixel(x, y);
t = y - c;
if (s*s + t*t > r*r)
pixel = Black;
im2.SetPixel(x, y, pixel);
}
}
im2.MakeTransparent(Black);
im2.Save("disk.png");
}
int Clamp(int x, int L, int U) {
if (x < L)return L;
else if (x > U)return U;
else return x;
}
void rotate(Bitmap^ im,int angle) {
int W = im->Width, H = im->Height;
Bitmap im2(W, H);
double s, t, c = (W - 1) / 2.0, r = W / 2.0;
const double PI = 3.1415926535897932384626433832795;
double theta = angle*PI / 180;
double sin_t = sin(theta), cos_t = cos(theta);
Color Black = Color::FromArgb(0, 0, 0);
for (int x = 0; x < W; x++) {
s = x - c;
for (int y = 0; y < H; y++)
{
t = y - c;
int xPrime = (int)round(s*cos_t - t*sin_t + c);
int yPrime = (int)round(s*sin_t + t*cos_t + c);
xPrime = Clamp(xPrime, 0, W - 1);
yPrime = Clamp(yPrime, 0, W - 1);
Color pixel = im->GetPixel(xPrime, yPrime);
if( s*s + t*t > r*r) pixel = Black;
im2.SetPixel(x, y, pixel);
}
}
im2.MakeTransparent(Black);
im2.Save("rotate.png");
}
#include
#include
#include
#include
using namespace std;
#using
using namespace System::Drawing;
void rotate(Bitmap^ im,int angle) {
int W = im->Width, H = im->Height;
Bitmap im2(W, H);
double s, t, c = (W - 1) / 2.0, r = W / 2.0;
const double PI = 3.1415926535897932384626433832795;
double theta = angle / 180.0*PI;
double sin_t = sin(theta), cos_t = cos(theta);
Color Black = Color::FromArgb(0, 0, 0);
for (int x = 0; x < W; x++) {
s = x - c;
for (int y = 0; y < H; y++) {
t = y - c;
int xPrime = (int)round(s* cos_t - t*sin_t + c);
int yPrime = (int)round(s* sin_t + t*cos_t + c);
xPrime=Clamp(xPrime, 0, W - 1);
yPrime = Clamp(yPrime, 0, W - 1);
Color pixel = im->GetPixel(xPrime, yPrime);
if (s*s + t*t > r*r) pixel = Black;
im2.SetPixel(x, y, pixel);
}
}
im2.MakeTransparent(Black);
stringstream ss;
ss<<"rotate"<> ff;
im2.Save(gcnew System::String(ff));
}
int main()
{
Bitmap^ im = gcnew Bitmap("2.jpg");
double angle;
cout << "旋轉角度:";
cin >> angle;
angle = fmod(angle, 360);
rotate(im, angle);
cout << "圖檔練習。\n";
system("Pause");
return 0;
}
張貼留言