網頁

2017年12月13日 星期三

ex11 C++/CLI Bitmap圓圖旋轉




//產生圓圖的函數
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");
} 

32 則留言:

  1. b10533006 劉純賓2017年12月13日 下午3:13


    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");
    }

    回覆刪除
  2. b10533007 魏辰熾2017年12月13日 下午3:14

    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");
    }

    回覆刪除
  3. b10533008 張士晟2017年12月13日 下午3:14

    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");
    }

    回覆刪除
  4. b10533009 張仲崴2017年12月13日 下午3:14

    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");
    }

    回覆刪除
  5. b10533011 江道逸2017年12月13日 下午3:15

    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");
    }

    回覆刪除
  6. b10533018 陳郁傑2017年12月13日 下午3:16

    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");
    }

    回覆刪除
  7. b10533062 洪尚郁2017年12月13日 下午3:36

    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");
    }

    回覆刪除
  8. //將圓圖旋轉
    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));
    }

    回覆刪除
  9. 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");
    }

    回覆刪除
  10. 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");
    }

    回覆刪除
  11. 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");
    }

    回覆刪除
  12. //將圓圖旋轉
    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));
    }

    回覆刪除
  13. 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");
    }

    回覆刪除
  14. 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");
    }

    回覆刪除
  15. 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");
    }

    回覆刪除
  16. 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");
    }

    回覆刪除
  17. 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");
    }

    回覆刪除
  18. 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");
    }

    回覆刪除
  19. 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");
    }

    回覆刪除
  20. b10433107 袁婕寧2017年12月13日 下午3:47

    #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;
    }

    回覆刪除
  21. b10433071 雷昕翰2017年12月13日 晚上9:36

    #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;
    }

    回覆刪除
  22. #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;
    }

    回覆刪除
  23. #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;
    }

    回覆刪除
  24. #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;
    }

    回覆刪除
  25. #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;
    }

    回覆刪除
  26. b10533075 陳詔瑋2017年12月27日 下午2:50

    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");
    }

    回覆刪除
  27. b10533029 游淑娥2017年12月27日 下午2:50

    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");
    }

    回覆刪除
  28. B10433088 葉凱文2018年1月2日 下午3:15

    #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;
    }

    回覆刪除
  29. #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;
    }

    回覆刪除
  30. B10533076姜國傑2018年1月3日 下午2:31

    #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;
    }

    回覆刪除
  31. B10533093許永炎2018年1月3日 下午2:35

    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");
    }

    回覆刪除
  32. b10533085羅偉辰2018年1月5日 清晨6:52

    #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;
    }

    回覆刪除

HTML 編輯器