Forum

C# resim kaydetme
 
Bildirimler
Hepsini Temizle

[Çözüldü] C# resim kaydetme

4 Yazılar
2 Üyeler
0 Likes
739 Görüntüleme
Mehmet
(@mehmetikiz)
Gönderiler: 442
Prominent Member
Konu başlatıcı
 

Merhaba;

c# winform uygulamasında mssql veritabanına resim kaydetmek istiyorum. Fakat resmi kaydetmeden önce boyutunu küçültmek istiyorum. Yardımlarınız için şimdiden teşekkürler iyi çalışmalar...

 
Gönderildi : 17/09/2015 21:33

(@eravse)
Gönderiler: 1753
Üye
 

Merhaba Resize için aşağıdaki kodu kullanabilirsin . daha sonra byte arraye çevirip direk db ye binary olarak yazabilirsiniz

 

public Image resizeImage(int newWidth, int newHeight, string stPhotoPath)
 {
     Image imgPhoto = Image.FromFile(stPhotoPath); 

     int sourceWidth = imgPhoto.Width;
     int sourceHeight = imgPhoto.Height;

     //Consider vertical pics
    if (sourceWidth < sourceHeight)
    {
        int buff = newWidth;

        newWidth = newHeight;
        newHeight = buff;
    }

    int sourceX = 0, sourceY = 0, destX = 0, destY = 0;
    float nPercent = 0, nPercentW = 0, nPercentH = 0;

    nPercentW = ((float)newWidth / (float)sourceWidth);
    nPercentH = ((float)newHeight / (float)sourceHeight);
    if (nPercentH < nPercentW)
    {
        nPercent = nPercentH;
        destX = System.Convert.ToInt16((newWidth -
                  (sourceWidth * nPercent)) / 2);
    }
    else
    {
        nPercent = nPercentW;
        destY = System.Convert.ToInt16((newHeight -
                  (sourceHeight * nPercent)) / 2);
    }

    int destWidth = (int)(sourceWidth * nPercent);
    int destHeight = (int)(sourceHeight * nPercent);


    Bitmap bmPhoto = new Bitmap(newWidth, newHeight,
                  PixelFormat.Format24bppRgb);

    bmPhoto.SetResolution(imgPhoto.HorizontalResolution,
                 imgPhoto.VerticalResolution);

    Graphics grPhoto = Graphics.FromImage(bmPhoto);
    grPhoto.Clear(Color.Black);
    grPhoto.InterpolationMode =
        InterpolationMode.HighQualityBicubic;

    grPhoto.DrawImage(imgPhoto,
        new Rectangle(destX, destY, destWidth, destHeight),
        new Rectangle(sourceX, sourceY, sourceWidth, sourceHeight),
        GraphicsUnit.Pixel);

    grPhoto.Dispose();
    imgPhoto.Dispose();
    return bmPhoto;
}

ProfectSoft Yazılım ve Danışmanlık Hizmetleri
LogPusher & Bifyou E-Commerce System
www.profectsoft.com

 
Gönderildi : 18/09/2015 02:43

Mehmet
(@mehmetikiz)
Gönderiler: 442
Prominent Member
Konu başlatıcı
 

teşekkürler hocam

 
Gönderildi : 19/09/2015 01:39

(@eravse)
Gönderiler: 1753
Üye
 

Rica ederim mehmet hocam biraz armut piş ağzıma düş oldu ama idare edersiniz artık 🙂 saygılarımla 

 

ProfectSoft Yazılım ve Danışmanlık Hizmetleri
LogPusher & Bifyou E-Commerce System
www.profectsoft.com

 
Gönderildi : 28/09/2015 01:42

Paylaş: