我有一个 PNG 文件存储在我的云中的 blob 存储中,我想下载它并在 WPF 中将其渲染在屏幕上。
我知道调度程序和冻结,但没有任何作用。我不断收到有关“另一个线程拥有它”的错误。
这是我所拥有的:
var decoder = GetDecoder("http://address/image.png");
Dispatcher.Invoke(DispatcherPriority.Send, new Action<BitmapFrame>(SetImage), decoder.Frames[0]);
public void SetImage(BitmapFrame source)
{
var bitmapFrame = BitmapFrame.Create(source); //ERROR HERE!!!!!!!!
LazyImage.Source = bitmapFrame;
}
private BitmapDecoder GetDecoder(object uri)
{
var extension = System.IO.Path.GetExtension((string)uri);
BitmapDecoder decoder = null;
if (extension.ToLower() == ".png")
decoder = BitmapDecoder.Create(new Uri((string)uri, UriKind.Absolute), BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.OnLoad);
return decoder;
}
Run Code Online (Sandbox Code Playgroud)
如果我尝试冻结 Frame[0],我会收到一个异常,提示该 Frame 无法冻结。另外,返回的解码器BitmapDecoder.Create不是a而是 a我真的不知道如何有效使用。PngBitmapDecoderLateBoundBitmapDecoder
我正在尝试过滤位图图像以增加或减少色相、饱和度和亮度值。
我的代码运行完美,但速度很慢。
我在内存中锁定了两个位图:原始源和当前目标。用户可以移动各种轨迹栏控件来修改每个值,然后将其转换为 HSL 值。例如,轨迹栏上的值对应于 -1.0 到 1.0 的范围。
每次引发轨迹栏值更改的事件时,我都会运行一个函数来锁定目标位图并将 HSL 值与源位图一起应用,然后将结果存储在目标位图中。完成后,我解锁目标位图并在屏幕上绘制图像。
以前,我对其他过滤器使用了查找表,因为我正在进行每字节操作。但是我不知道如何使用 HSL 来应用它。这是我正在使用的代码:
byte red, green, blue;
for (int i = 0; i < sourceBytes.Length; i += 3)
{
blue = sourceBytes[i];
green = sourceBytes[i + 1];
red = sourceBytes[i + 2];
Color newColor = Color.FromArgb(red, green, blue);
if (ModifyHue)
newColor = HSL.ModifyHue(newColor, Hue);
if (ModifySaturation)
newColor = HSL.ModifySaturation(newColor, Saturation);
if (ModifyLightness)
newColor = HSL.ModifyBrightness(newColor, Lightness);
destBytes[i] = newColor.B;
destBytes[i + 1] …Run Code Online (Sandbox Code Playgroud) 我的对象通过一些复杂的管道传递,在其中的某些部分,我没有代码,我需要知道Dispose在我的Bitmap!
我正在编写一些函数来在位图上添加噪点效果。我发现类似的问题:Add Noise Effect to a Drawing
位图输出Bitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
BitmapShader shader = new BitmapShader (bitmap, TileMode.REPEAT, TileMode.REPEAT);
Paint paint = new Paint();
paint.setShader(shader);
Canvas c = new Canvas(outputBitmap);
c.drawBitmap(bitmap, 0, 0, paint);
Run Code Online (Sandbox Code Playgroud)
我应该如何添加滤色镜才能得到这样的结果?您能提供简单的代码吗?
我编写了一个 C# 渲染方法,将热图渲染到 Grasshopper 画布上。Grasshopper 是一个 Rhino 插件,支持简单的 GUI 编程界面。
protected override void Render(Grasshopper.GUI.Canvas.GH_Canvas canvas, Graphics graphics, Grasshopper.GUI.Canvas.GH_CanvasChannel channel) {
base.Render(canvas, graphics, channel);
if (channel == Grasshopper.GUI.Canvas.GH_CanvasChannel.Wires) {
var comp = Owner as KT_HeatmapComponent;
if (comp == null)
return;
List<HeatMap> maps = comp.CachedHeatmaps;
if (maps == null)
return;
if (maps.Count == 0)
return;
int x = Convert.ToInt32(Bounds.X + Bounds.Width / 2);
int y = Convert.ToInt32(Bounds.Bottom + 10);
for (int i = 0; i < maps.Count; i++) {
Bitmap image = …Run Code Online (Sandbox Code Playgroud) 我正在使用第三方 DLL,它具有 RGB 缓冲区作为参数。
我使用以下代码读取 RGB 缓冲区Bitmap:
private byte[] GetBGRValues(Bitmap bmp)
{
// Lock the bitmap's bits.
Rectangle rect = new Rectangle(0, 0, bmp.Width, bmp.Height);
System.Drawing.Imaging.BitmapData bmpData = bmp.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);
// Get the address of the first line.
IntPtr ptr = bmpData.Scan0;
// Declare an array to hold the bytes of the bitmap.
int bytes = Math.Abs(bmpData.Stride) * bmp.Height;
byte[] rgbValues = new byte[bytes];
// Copy the RGB values into the array.
System.Runtime.InteropServices.Marshal.Copy(ptr, rgbValues, 0, bytes);
bmp.UnlockBits(bmpData); …Run Code Online (Sandbox Code Playgroud) 我正在编写一些代码来读取位图文件。
这是我用来读取位图标头的结构。也可以看看:
https://msdn.microsoft.com/en-us/library/windows/desktop/dd183374(v=vs.85).aspx
struct BITMAPFILEHEADER
{
WORD bfType; // 2
DWORD bfSize; // 6
WORD bfReserved1; // 8
WORD bfReserved2; // 10
DWORD bfOffBits; // 14
}; // should add to 14 bytes
Run Code Online (Sandbox Code Playgroud)
如果我将以下代码放在我的主函数中:
std::cout << "BITMAPFILEHEADER: " << sizeof(BITMAPFILEHEADER) << std::endl;
Run Code Online (Sandbox Code Playgroud)
该程序打印:
BITMAPFILEHEADER: 16
Run Code Online (Sandbox Code Playgroud)
它似乎是在 4 字节边界上重新对齐结构中的数据,大概是为了效率。当然,这使我无法读取位图......即使微软和其他人,指定这是这样做的方式......
如何防止结构重新对齐?
在我的测试中,Bitmap创建者BitmapFactory.decodeFile()不尊重 EXIF 标头。
例如,对于由设备拍摄的人像图像,它不会根据相机方向旋转实际像素数据,而是将其存储在 EXIF 标头中,当我调用Bitmap.getWidth()and 时Bitmap.getHeight(),它们返回错误值(高度为宽度,反之亦然)。
有没有办法 BitmapFactory.decodeFile()尊重EXIF并产生正确的Bitmap?
如果没有,处理这个问题的推荐模式是什么?
如果没有经验丰富的 Android 开发人员的建议,我所看到的唯一方法是对拍摄的图像进行预处理(加载、根据 EXIF 旋转并保存)。但除了巨大的处理开销之外,这可能会导致OutOfMemoryException大相机分辨率的 s (在您无法通过使用BitmapFactory.Options.inSampleSize加载缩小图像来降低质量的情况下)。
我在网上找到这个代码打印屏幕(截图),但我不知道如何修改它以将结果保存到PNG文件。
我可以将位图保存到剪贴板,但我现在需要保存到 PNG 文件。
到目前为止我的代码是:
#include <iostream>
#include <windows.h>
#include <gdiplus.h>
#include <stdexcept>
using namespace std;
using namespace Gdiplus;
using namespace Gdiplus::DllExports;
using std::runtime_error;
void screenshot(POINT a, POINT b)
{
HDC hScreen = GetDC(NULL);
HDC hDc = CreateCompatibleDC(hScreen);
HBITMAP hBitmap = CreateCompatibleBitmap(hScreen, abs(b.x-a.x), abs(b.y-a.y));
HGDIOBJ old_obj = SelectObject(hDc, hBitmap);
BOOL bRet = BitBlt(hDc, 0, 0, abs(b.x-a.y), abs(b.y-a.y), hScreen, a.x, a.y, SRCCOPY);
OpenClipboard(NULL);
EmptyClipboard();
SetClipboardData(CF_BITMAP, hBitmap);
CloseClipboard();
SelectObject(hDc, old_obj);
DeleteDC(hDc);
ReleaseDC(NULL, hScreen);
DeleteObject(hBitmap);
}
int main() …Run Code Online (Sandbox Code Playgroud) 我需要创建一个假位图图像来测试(JUnit 测试)我的个人添加和获取自定义 LinkedList 的方法,但 Bitmap.createBitmap 返回错误:
java.lang.RuntimeException:未模拟 android.graphics.Bitmap 中的方法 createBitmap。
这是我的 JUnitTest 的代码:
public class TicketsIteratorTest {
Bitmap img_Bmp;
TicketsIterator<Bitmap> TicketsList = new TicketsIterator();
/*
* Test for the add e get methods, check if the element just insert it's the same of the one just extract.
*/
@Test
public void Add_n_Get() throws Exception {
int i = 0, numIMG = 100;
Bitmap[] IMG_Generated;
IMG_Generated = new Bitmap[numIMG];
// Generate numIMG of imagine to insert into the Iterator and it …Run Code Online (Sandbox Code Playgroud)