本文整理汇总了C#中System.Windows.Media.Imaging.WriteableBitmap.Resize方法的典型用法代码示例。如果您正苦于以下问题:C# WriteableBitmap.Resize方法的具体用法?C# WriteableBitmap.Resize怎么用?C# WriteableBitmap.Resize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Media.Imaging.WriteableBitmap
的用法示例。
在下文中一共展示了WriteableBitmap.Resize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SampleOriginalImage
// Sample the original image
private void SampleOriginalImage()
{
originalBitmap = new WriteableBitmap(originalImage);
double ratio = (double)originalBitmap.PixelWidth / (double)originalBitmap.PixelHeight;
double w = Application.Current.RootVisual.RenderSize.Width;
double h = Application.Current.RootVisual.RenderSize.Height;
double previewWidth;
double previewHeight;
if (w / ratio > h)
{
previewHeight = h;
previewWidth = h * ratio;
}
else
{
previewWidth = w;
previewHeight = w / ratio;
}
originalPreviewBitmap = originalBitmap.Resize((int)previewWidth, (int)previewHeight, System.Windows.Media.Imaging.WriteableBitmapExtensions.Interpolation.Bilinear);
currentPreviewBitmap = originalBitmap.Resize((int)previewWidth, (int)previewHeight, System.Windows.Media.Imaging.WriteableBitmapExtensions.Interpolation.Bilinear);
// Create buffer
previewStream = new MemoryStream();
currentPreviewBitmap.SaveJpeg(previewStream, originalPreviewBitmap.PixelWidth, originalPreviewBitmap.PixelHeight, 0, 75);
previewBuffer = previewStream.GetWindowsRuntimeBuffer();
}
示例2: OnPhotoChooserTaskCompleted
private void OnPhotoChooserTaskCompleted(object sender, PhotoResult e)
{
UploadButton.IsEnabled = false;
// Make sure the PhotoChooserTask is resurning OK
if (e.TaskResult == TaskResult.OK)
{
// initialize the result photo stream
photoStream = new MemoryStream();
sendPhotoStream = new MemoryStream();
// Save the stream result (copying the resulting stream)
e.ChosenPhoto.CopyTo(photoStream);
// save the original file name
fileName = e.OriginalFileName;
BitmapImage setImage = new BitmapImage();
setImage.SetSource(photoStream);
WriteableBitmap wb = new WriteableBitmap(setImage);
var resizeHeight=((double)setImage.PixelHeight / (double)setImage.PixelWidth * 640d);
wb=wb.Resize(640, (int)resizeHeight, WriteableBitmapExtensions.Interpolation.Bilinear);
wb.SaveJpeg(sendPhotoStream, wb.PixelWidth, wb.PixelHeight, 0, 100);
setImage.SetSource(sendPhotoStream);
SelectedImage.Source = setImage;
// display the chosen picture
UploadFile();
}
else
{
MessageBox.Show("Error picking picture");
}
UploadButton.IsEnabled = true;
}
示例3: ResizeJpegStream
private void ResizeJpegStream(int maxPixelDimension, int percentQuality, Stream input, Action<Stream> success)
{
var bitmap = new BitmapImage();
bitmap.SetSource(input);
var writeable = new WriteableBitmap(bitmap);
var ratio = 1.0;
if (writeable.PixelWidth > writeable.PixelHeight)
ratio = ((double)maxPixelDimension) / ((double)writeable.PixelWidth);
else
ratio = ((double)maxPixelDimension) / ((double)writeable.PixelHeight);
writeable.Resize((int)Math.Round(ratio * writeable.PixelWidth), (int)Math.Round(ratio * writeable.PixelHeight), WriteableBitmapExtensions.Interpolation.Bilinear);
// not - important - we do *not* use using here - disposing of memoryStream is someone else's problem
var memoryStream = new MemoryStream();
writeable.SaveJpeg(memoryStream, writeable.PixelWidth, writeable.PixelHeight, 0, percentQuality);
memoryStream.Seek(0L, SeekOrigin.Begin);
success(memoryStream);
}
示例4: GenerateGuildEmblemImage
/// <summary>
/// Generates the guild emblem image.
/// </summary>
/// <param name="guildEmblemData">The guild emblem data.</param>
/// <param name="guildSide">The guild side.</param>
/// <param name="width">The width.</param>
/// <param name="height">The height.</param>
/// <returns></returns>
public static BitmapSource GenerateGuildEmblemImage(GuildEmblem guildEmblemData, GuildSide guildSide, int width = 216, int height = 240)
{
WriteableBitmap guildEmblemImage;
try
{
guildEmblemImage = new WriteableBitmap(216, 240);
var factionBackgroundImage = new WriteableBitmap(216, 216).FromResource(String.Format("Images/GuildDetails/Emblem_Background_{0}.png", guildSide));
guildEmblemImage.Blit(new Rect(0, 0, 216, 216), factionBackgroundImage, new Rect(0, 0, 216, 216), WriteableBitmapExtensions.BlendMode.Alpha);
var shadowImage = new WriteableBitmap(179, 210).FromResource("Images/GuildDetails/Emblem_Shadow.png");
guildEmblemImage.Blit(new Rect(18, 27, 179, 210), shadowImage, new Rect(0, 0, 179, 210), WriteableBitmapExtensions.BlendMode.Alpha);
var backgroundColor = GetColorFromHexString(guildEmblemData.BackgroundColor);
var emblemBackgroundImage = new WriteableBitmap(179, 210).FromResource("Images/GuildDetails/Emblem_Background.png");
guildEmblemImage.Blit(new Rect(18, 27, 179, 210), emblemBackgroundImage, new Rect(0, 0, 179, 210), backgroundColor, WriteableBitmapExtensions.BlendMode.Alpha);
var borderColor = GetColorFromHexString(guildEmblemData.BorderColor);
var borderImage = new WriteableBitmap(147, 159).FromResource(String.Format("Images/GuildDetails/Emblem_Border_{0}.png", guildEmblemData.Border));
guildEmblemImage.Blit(new Rect(31, 40, 147, 159), borderImage, new Rect(0, 0, 147, 159), borderColor, WriteableBitmapExtensions.BlendMode.Alpha);
var iconColor = GetColorFromHexString(guildEmblemData.IconColor);
var iconImage = new WriteableBitmap(125, 125).FromResource(String.Format("Images/GuildDetails/Emblems/Emblem_{0}.png", guildEmblemData.Icon.ToString().PadLeft(3, '0')));
guildEmblemImage.Blit(new Rect(33, 57, 125, 125), iconImage, new Rect(0, 0, 125, 125), iconColor, WriteableBitmapExtensions.BlendMode.Alpha);
var hooksImage = new WriteableBitmap(179, 32).FromResource("Images/GuildDetails/Emblem_Hooks.png");
guildEmblemImage.Blit(new Rect(18, 27, 179, 32), hooksImage, new Rect(0, 0, 179, 32), WriteableBitmapExtensions.BlendMode.Alpha);
}
catch (Exception ex)
{
guildEmblemImage = new WriteableBitmap(216, 240).FromResource(String.Format("Images/GuildDetails/Emblem_Default_{0}.png", guildSide));
}
var resized = guildEmblemImage.Resize(width, height, WriteableBitmapExtensions.Interpolation.Bilinear);
return resized;
}
示例5: Scale
/// <summary>
/// Scale image
/// </summary>
/// <param name="srouce"></param>
/// <param name="scale"></param>
/// <returns></returns>
private WriteableBitmap Scale(WriteableBitmap srouce, float scale)
{
WriteableBitmap wb = new WriteableBitmap(srouce);
int w = (int)(wb.PixelWidth * _lastScale);
int h = (int)(wb.PixelHeight * _lastScale);
return wb.Resize(w, h, WriteableBitmapExtensions.Interpolation.Bilinear);
}
示例6: TimerOnTick
private void TimerOnTick(object sender, EventArgs eventArgs)
{
lastCount = count;
count = 0;
int[] pixelData = new int[(int)(camera.PreviewResolution.Width * camera.PreviewResolution.Height)]; //640x480
camera.GetPreviewBufferArgb32(pixelData);
WriteableBitmap freezeWriteableBitmap = new WriteableBitmap((int)camera.PreviewResolution.Width, (int)camera.PreviewResolution.Height);
pixelData.CopyTo(freezeWriteableBitmap.Pixels, 0);
freezeWriteableBitmap.Invalidate();
// timer.Stop();
int[] buffer1 = buffer;
try
{
camera.GetPreviewBufferArgb32(buffer);
// camera.GetPreviewBufferY(bufferr);
}
catch (Exception e)
{
}
//int t = 128;
freezeWriteableBitmap = freezeWriteableBitmap.Resize(t, t,
WriteableBitmapExtensions.Interpolation.Bilinear);
/*
for (int i = 0; i < bufferr.Length; i++)
{
if (bufferLast[i] != bufferr[i])
{
count++;
}
}*/
/*
for (int i = 0; i < t; i++)
{
for (int j = 0; j < t; j++)
{
var a = freezeWriteableBitmap.GetPixel(i, j);
byte d = (byte)((a.R + a.G + a.B)/3);
freezeWriteableBitmap.SetPixel(i,j, d,d,d);
}
}*/
int srednia = 0;
for (int i = 0; i < t; i++)
{
for (int j = 0; j <t; j++)
{
var d = freezeWriteableBitmap.GetPixel(i, j);
srednia += (d.R + d.G + d.B)/ 3;
}
}
srednia = srednia/(128*128);
for (int i = 0; i < t; i++)
{
for (int j = 0; j <t; j++)
{
var a = freezeWriteableBitmap.GetPixel(i, j);
if ((a.R + a.G + a.B)/3 <srednia)
{
freezeWriteableBitmap.SetPixel(i,j,0,0,0);
}
else
{
freezeWriteableBitmap.SetPixel(i,j,255,255,255);
}
}
}
/* int ApetureMin = -(10 / 2);
int ApetureMax = (2 / 2);
for (int x = 0; x < t; ++x)
{
for (int y = 0; y < t; ++y)
{
int RValue = 0;
int GValue = 0;
int BValue = 0;
for (int x2 = ApetureMin; x2 < ApetureMax; ++x2)
{
int TempX = x + x2;
if (TempX >= 0 && TempX < t)
{
for (int y2 = ApetureMin; y2 < ApetureMax; ++y2)
{
int TempY = y + y2;
if (TempY >= 0 && TempY < t)
{
Color TempColor = freezeWriteableBitmap.GetPixel(TempX, TempY);
if (TempColor.R > RValue)
RValue = TempColor.R;
if (TempColor.G > GValue)
GValue = TempColor.G;
if (TempColor.B > BValue)
BValue = TempColor.B;
//.........这里部分代码省略.........
示例7: setFrame
void setFrame()
{
camera.GetPreviewBufferYCbCr(bufferLast);
int[] pixelData = new int[(int)(camera.PreviewResolution.Width * camera.PreviewResolution.Height)]; //640x480
camera.GetPreviewBufferArgb32(pixelData);
zapisany = new WriteableBitmap((int)camera.PreviewResolution.Width, (int)camera.PreviewResolution.Height);
pixelData.CopyTo(zapisany.Pixels, 0);
zapisany.Invalidate();
zapisany = zapisany.Resize(t, t,
WriteableBitmapExtensions.Interpolation.Bilinear);
/* int ApetureMin = -(2 / 2);
int ApetureMax = (2 / 2);
for (int x = 0; x < t; ++x)
{
for (int y = 0; y < t; ++y)
{
int RValue = 0;
int GValue = 0;
int BValue = 0;
for (int x2 = ApetureMin; x2 < ApetureMax; ++x2)
{
int TempX = x + x2;
if (TempX >= 0 && TempX < t)
{
for (int y2 = ApetureMin; y2 < ApetureMax; ++y2)
{
int TempY = y + y2;
if (TempY >= 0 && TempY < t)
{
Color TempColor = zapisany.GetPixel(TempX, TempY);
if (TempColor.R > RValue)
RValue = TempColor.R;
if (TempColor.G > GValue)
GValue = TempColor.G;
if (TempColor.B > BValue)
BValue = TempColor.B;
}
}
}
}
//Color TempPixel = Color.FromArgb(0, (byte) RValue, (byte) GValue, (byte) BValue);
zapisany.SetPixel(x, y, (byte)RValue, (byte)GValue, (byte)BValue);
}
}*/
/* for (int i = 0; i < 128; i++)
{
for (int j = 0; j < 128; j++)
{
var a = zapisany.GetPixel(i, j);
byte d = (byte)((a.R + a.G + a.B) / 3);
zapisany.SetPixel(i, j, d, d, d);
}
}*/
/* for (int i = 0; i < t; i++)
{
for (int j = 0; j < t; j++)
{
var a = zapisany.GetPixel(i, j);
byte d = (byte)((a.R + a.G + a.B) / 3);
zapisany.SetPixel(i, j, d, d, d);
}
}*/
for (int i = 0; i < t; i++)
{
for (int j = 0; j < t; j++)
{
var a = zapisany.GetPixel(i, j);
if ((a.R + a.G + a.B) / 3 < 128)
{
zapisany.SetPixel(i, j, 0, 0, 0);
}
else
{
zapisany.SetPixel(i, j, 255, 255, 255);
}
}
}
}
示例8: Scale
public static WriteableBitmap Scale(WriteableBitmap image, double scale)
{
if (scale == 1)
return image;
if (!_resizes.ContainsKey(image))
_resizes[image] = new Dictionary<double, WriteableBitmap>();
if (!_resizes[image].ContainsKey(scale))
_resizes[image][scale] = image.Resize((int)(image.PixelWidth * scale), (int)(image.PixelHeight * scale), WriteableBitmapExtensions.Interpolation.NearestNeighbor);
return _resizes[image][scale];
}
示例9: GeneratePreview
private WriteableBitmap GeneratePreview(WriteableBitmap WBImage, double maxWidth, double maxHeight)
{
double scaleX = 1;
double scaleY = 1;
if (WBImage.PixelHeight > maxHeight)
scaleY = Math.Min(maxHeight / WBImage.PixelHeight, 1);
if (WBImage.PixelWidth > maxWidth)
scaleX = Math.Min(maxWidth / WBImage.PixelWidth, 1);
// maintain aspect ratio by picking the most severe scale
double scale = Math.Min(scaleY, scaleX);
WriteableBitmap retImage = WBImage.Resize((int)(scale * WBImage.PixelWidth), (int)(scale * WBImage.PixelHeight), WriteableBitmapExtensions.Interpolation.Bilinear);
MessageBox.Show("Dim: " + PreviewImage.PixelHeight + "x" + PreviewImage.PixelWidth);
return retImage;
}
示例10: photoChooserTask_Completed
private void photoChooserTask_Completed(object sender, PhotoResult e)
{
if (e.TaskResult == TaskResult.OK)
{
updateUndoList();
bm = new WriteableBitmap(canvas1, null);
double width = bm.PixelWidth;
double height = bm.PixelHeight;
bm.SetSource(e.ChosenPhoto);
double scaleX = bm.PixelWidth / width;
double scaleY = bm.PixelHeight / height;
//For debugging
//System.Diagnostics.Debug.WriteLine(width + " - " + height);
//System.Diagnostics.Debug.WriteLine(bm.PixelWidth + " :: " + bm.PixelHeight);
//System.Diagnostics.Debug.WriteLine(scaleX + " = " + scaleY);
bm = bm.Resize((int)(bm.PixelWidth / scaleX),
(int)(bm.PixelHeight / scaleY),
WriteableBitmapExtensions.Interpolation.Bilinear);
updateCanvasFromWBM(bm);
makeToast("", "Load Successful");
//Frank: Look into cleaning up this Imagesource mess later with the following trick
//Code to display the photo on the page in an image control named myImage.
//System.Windows.Media.Imaging.BitmapImage bmp = new System.Windows.Media.Imaging.BitmapImage();
//bmp.SetSource(e.ChosenPhoto);
//myImage.Source = bmp;
}
else
{
makeToast("Uh oh!", "Load Failed");
}
}
示例11: GenereateMosaicPicture
public static string GenereateMosaicPicture(IList<BitmapImage> images, string filename)
{
string key = string.Empty;
try
{
// Generate avatar in bitmap.
var bmp = new WriteableBitmap(PICTURE_DIMENSION, PICTURE_DIMENSION);
bmp.Clear();
int x = 0;
int y = 0;
int w = 0;
int h = 0;
if (images.Count == 1)
{
w = PICTURE_DIMENSION;
h = PICTURE_DIMENSION;
}
else if (images.Count == 2)
{
w = PART_DIMENSION;
h = PICTURE_DIMENSION;
}
else
{
w = PART_DIMENSION;
h = PART_DIMENSION;
}
for (int i = 0; i < images.Count && i < 4; )
{
if (images[i] == null)
continue;
var wb = new WriteableBitmap(images[i]);
if (wb.PixelHeight < h || wb.PixelWidth < w)
{
wb = wb.Resize(PICTURE_DIMENSION, PICTURE_DIMENSION, WriteableBitmapExtensions.Interpolation.Bilinear);
}
i++;
bmp.Blit(new Rect(x, y, w, h), wb,
new Rect(0, 0, w, h));
if (w == PART_DIMENSION)
x += w + 2; // Handle empty space between photos
else
x += w;
if (x >= PICTURE_DIMENSION)
{
x = 0;
if (h == PART_DIMENSION)
y += h + 2; // Handle empty space between photos
else
y += h;
}
if (y >= PICTURE_DIMENSION)
break;
}
if (_SaveJpeg(bmp, filename))
key = filename;
}
catch (Exception ex)
{
Debug.WriteLine("GenereateMosaicPicture failed." + ex.Message);
}
return key;
}
示例12: NormalizeBitmapSize
public static WriteableBitmap NormalizeBitmapSize(WriteableBitmap bitmap)
{
float pixelWidth = bitmap.PixelWidth;
int height = Convert.ToInt32((bitmap.PixelHeight / pixelWidth) * 400);
return bitmap.Resize(400, height, WriteableBitmapExtensions.Interpolation.NearestNeighbor);
}
示例13: OnImageLoaded
// Image finished loading
private void OnImageLoaded(object sender, EventArgs e)
{
BitmapImage sourceImage = (BitmapImage)sender;
WriteableBitmap scaledImage = new WriteableBitmap(sourceImage);
scaledImage.Resize((int)Width, (int)Height, WriteableBitmapExtensions.Interpolation.Bilinear);
double w = Width;
double h = Height;
double cellWidth = w;
double cellHeight = h / NumBlinds;
for (int i = 0; i < NumBlinds; i++)
{
// Create the target cell
Image cell = new Image();
Rect rect = new Rect(0, i * cellHeight, cellWidth, cellHeight);
cell.SetValue(Canvas.TopProperty, rect.Y);
cell.SetValue(Canvas.LeftProperty, rect.X);
cell.Width = cellWidth;
cell.Height = cellHeight;
cell.Visibility = Visibility.Collapsed;
contentView.Children.Add(cell);
nextGrid.Add(cell);
WriteableBitmap slice = scaledImage.Crop(rect);
cell.Source = slice;
}
for(int i = 0; i < NumBlinds; i++)
{
animatedCellIndex.Add(i);
}
// Do animation
int firstCellIndex = animatedCellIndex[0];
PerformFlipAnimation(grid[firstCellIndex], nextGrid[firstCellIndex]);
}
示例14: ScaleBitmap
static WriteableBitmap ScaleBitmap(WriteableBitmap bmp, int width, int height)
{
int W = bmp.PixelWidth;
int H = bmp.PixelHeight;
if (W <= width && H <= height)
{
return bmp;
}
int w = width;
int h = height;
if (((double)W) / ((double)H) >= (((double)width) / (double)height))
{
h = (int)Math.Min(H * w / (double)W, height);
}
else
{
w = (int)Math.Min(W * h / (double)H, width);
}
return bmp.Resize(w, h, WriteableBitmapExtensions.Interpolation.Bilinear);
}
示例15: appBtnPaylas_Click
private void appBtnPaylas_Click(object sender, EventArgs e)
{
if (txtUrunFiyat.Text != string.Empty && txtUrunIsim.Text != string.Empty)
{
ucret = Convert.ToDecimal(txtUrunFiyat.Text);
path = "/Assets/sepet.png";
if (fotoDegistimi)
{
path = txtUrunIsim.Text + tbBarkodData.Text + uzanti;
using (MemoryStream ms = new MemoryStream())
{
WriteableBitmap btmMap = new WriteableBitmap(imgUrunResim.Source as BitmapSource);
btmMap = btmMap.Resize(Convert.ToInt32(200), Convert.ToInt32(222), WriteableBitmapExtensions.Interpolation.Bilinear);
btmMap.SaveJpeg(ms, btmMap.PixelWidth, btmMap.PixelHeight, 0, 50);
fotoDizisi = ms.ToArray();
}
al.UploadImageAsync(fotoDizisi, txtUrunIsim.Text + tbBarkodData.Text + uzanti, "urunresimleri");
al.UploadImageCompleted += Al_UploadImageCompleted;
}
if (!BarkodKontrol) // eğer ürün daha önceden eklenmemişse
{
Urunler urun = new Urunler // ürünler veritabanına veri kaydı..
{
Barkod = barkodDatasi,
UrunAd = txtUrunIsim.Text,
UrunIlkEkleyen = KullaniciId,
EnUcuzFiyat = ucret,
MarketId = 1,
UrunResim = path,
BarkodTur = BarkodTur
};
al.UrunlerKayitAsync(urun);
al.UrunlerKayitCompleted += new EventHandler<UrunlerKayitCompletedEventArgs>(al_UrunlerKayitCompleted);
}
if (BarkodKontrol)
{
al.PaylasimUrunTakipKayitAsync(barkodId, ucret, 1, KullaniciId);
al.PaylasimUrunTakipKayitCompleted += Al_PaylasimUrunTakipKayitCompleted;
}
NavigationService.GoBack();
}
}