我想在Win32应用程序上加载图像(.bmp)文件,但我不想使用Windows API中的标准LoadBitmap/LoadImage:我希望它从已经在内存中的缓冲区加载.我可以直接从文件中轻松加载位图并将其打印在屏幕上,但这个问题让我陷入困境.
我正在寻找的功能是这样的:
HBITMAP LoadBitmapFromBuffer(char* buffer, int width, int height);
Run Code Online (Sandbox Code Playgroud) 我在eclipse中使用了更新的willowgarage opencv库.我想将mat变量转换为灰度,我已经尝试了我在网上找到的所有内容,但它们并没有为我工作.
这是我的代码
package com.deneme.deneme;
import android.app.Activity;
import android.os.Bundle;
import android.widget.ImageView;
import org.opencv.android.Utils;
import org.opencv.core.Mat;
import org.opencv.imgproc.Imgproc;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
public class main extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ImageView img=(ImageView) findViewById(R.id.pic);
Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.p26);
Mat imgToProcess=Utils.bitmapToMat(bmp);
//******
//right here I need to convert this imgToProcess to grayscale for future opencv processes
//******
Bitmap bmpOut = Bitmap.createBitmap(imgToProcess.cols(), imgToProcess.rows(), Bitmap.Config.ARGB_8888);
Utils.matToBitmap(imgToProcess, bmpOut);
img.setImageBitmap(bmpOut);
} …Run Code Online (Sandbox Code Playgroud) 我正在寻找如何使用GDI(而不是GDI +)将32位位图转换为灰度的简单解决方案.是否有可能通过更改位图的托盘或其他东西?
当然Delphi中有很多像这样的例子,但是我正在寻找一个WinAPI函数,它可以在没有迭代的情况下完成这个.
我正在尝试创建一个用于创建自定义卡的应用.我想在自定义背景(jpg图像)上添加一些文本.
这样做的最佳方式是什么?在将卡发送到服务器之前,我需要向用户显示卡的预览.
谢谢
我正在尝试从PNG图像加载运动地图.为了在加载位图后节省内存,我做了类似的事情.
`Bitmap mapBmp = tempBmp.copy(Bitmap.Config.ALPHA_8, false);`
Run Code Online (Sandbox Code Playgroud)
如果我绘制mapBmp,我可以看到地图,但是当我使用getPixel()时,我总是得到0(零).
有没有办法从getPixel()以外的位图检索ALPHA信息?
我正在开发一款Android应用程序,它具有摄像头捕捉和照片上传功能.如果设备具有高分辨率相机,则捕获的图像尺寸将非常大(1~3MB或更多).
由于应用程序需要将此图像上传到服务器,因此我需要在上传之前压缩图像.例如,如果相机捕获了1920x1080全分辨率照片,则理想输出是保持图像的16:9比例,将其压缩为640x360图像以降低某些图像质量并使其以字节为单位缩小.
这是我的代码(从谷歌引用):
/**
* this class provide methods that can help compress the image size.
*
*/
public class ImageCompressHelper {
/**
* Calcuate how much to compress the image
* @param options
* @param reqWidth
* @param reqHeight
* @return
*/
public static int calculateInSampleSize(BitmapFactory.Options options, int reqWidth, int reqHeight) {
// Raw height and width of image
final int height = options.outHeight;
final int width = options.outWidth;
int inSampleSize = 1;
if (height > reqHeight || width …Run Code Online (Sandbox Code Playgroud) 在我的代码中,我从字节数组(依次从Kinect)接收WriteableBitmaps,我想把它们变成用于EmguCV的位图.目前这是我的代码:
// Copy the pixel data from the image to a temporary array
colorFrame.CopyPixelDataTo(this.colorPixels);
// Write the pixel data into our bitmap
this.colorBitmap.WritePixels(
new Int32Rect(0, 0, this.colorBitmap.PixelWidth, this.colorBitmap.PixelHeight),
this.colorPixels,
this.colorBitmap.PixelWidth * colorFrame.BytesPerPixel,
0);
BitmapEncoder encoder = new BmpBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(colorBitmap));
MemoryStream ms = new MemoryStream();
encoder.Save(ms);
Bitmap b=new Bitmap(ms);
Image<Gray, Byte> img = new Image<Gray, Byte>(b);
img = img.ThresholdBinary(new Gray(200), new Gray(255));
Run Code Online (Sandbox Code Playgroud)
我从这里得到了代码的下半部分.代码编译和所有内容,但是在我尝试运行程序时挂起(它应该对图像执行一些操作然后将其转换回可以呈现的格式作为一个图像.)暂停我的代码,然后在VS 2013中使用IntelliTrace,我在Image<Gray, Byte> img = new Image<Gray, Byte>(b);"A System.ArgumentException被抛出时得到以下异常:不支持URI格式." 使用替代代码,从我直接从字节到位图的位置给出了同样的错误.(代码可以在这里找到.)
任何人都有关于如何解决此错误或其他方法转换为位图的提示?我是C#和EmguCV的新手,我非常感激.
我正在开发一款游戏
首先我的游戏将非常简单,所以我宁愿不使用库或opengl或canvas,我宁愿用简单的图像视图或普通视图来实现这一点,或者至少以最简单的方式实现.例如,使用android位图平铺模式:
public static void setBackground(Bitmap bmp, ViewGroup layout){
BitmapDrawable bitmapDrawable = new BitmapDrawable(bmp);
bitmapDrawable.setTileModeXY(Shader.TileMode.REPEAT, Shader.TileMode.REPEAT);
layout.setBackgroundDrawable(bitmapDrawable);
}
Run Code Online (Sandbox Code Playgroud)
我想开发一个简单的2D/3D混合太空飞船游戏.屏幕将是太空飞船驾驶舱的视野,你将移动宇宙飞船触摸我已经完成的操纵杆.所以背景将是一个宇宙背景,我的意思是一个巨大的黑色图像与星星,这个图像必须移动到所有方向,操纵杆模拟太空船正在改变它的方向,当你向右移动很多时,例如,背景图像必须从头开始模拟太空船仍在向右移动而没有任何限制
正如我所提到的,我现在有了操纵杆,我知道如何使用操纵杆移动图像视图,问题是我不知道如何正确地创建带有图块的无限图像视图,因为当我移动包含图块的图像时可以移动然后图像从屏幕上消失.
这是使用无限背景的图像示例:

流行游戏Words with Friends在游戏板上绘制字母拼贴作为单个实体 -
您可以在以下屏幕截图中看到应用于所有字母图块的黄色线性渐变,以及边缘上的浮雕效果:

在我的文字游戏中,我希望有类似的效果:

所以我创建了一个游戏板大小mBitmap,然后将所有图块绘制到其中,最后将位图绘制到我的自定义视图中 -
建立:
setLayerType(View.LAYER_TYPE_SOFTWARE, null);
// create yellow linear gradient
mGradStart = new Point(3 * mWidth / 4, mHeight / 3);
mGradEnd = new Point(mWidth / 4, 2 * mHeight / 3);
LinearGradient gradient = new LinearGradient(
mGradStart.x,
mGradStart.y,
mGradEnd.x,
mGradEnd.y,
new int[]{ 0xCCFFCC00, 0xCCFFCC99, 0xCCFFCC00 },
null,
TileMode.CLAMP);
// create the big bitmap holding all tiles
mBitmap = Bitmap.createBitmap(mWidth, mHeight, Bitmap.Config.ARGB_8888);
mCanvas = …Run Code Online (Sandbox Code Playgroud) 我正在使用我在http://brianlagunas.com/wpf-copy-uielement-as-image-to-clipboard/上找到的一些代码来复制渲染的XAML Treeview.如果内容溢出可用高度,则树视图配置为滚动.
const long DPI = 96;
FrameworkElement element = (FrameworkElement)param;
double height = element.ActualHeight;
double width = element.ActualWidth;
RenderTargetBitmap bmp = new RenderTargetBitmap((int)Math.Round(width), (int)Math.Round(height), DPI, DPI, PixelFormats.Default);
DrawingVisual dv = new DrawingVisual();
using (DrawingContext dc = dv.RenderOpen())
{
VisualBrush vb = new VisualBrush(element);
dc.DrawRectangle(vb, null, new Rect(new Point(), new Size(width, height)));
}
bmp.Render(dv);
DataObject _data = new DataObject();
_data.SetImage(bmp);
Run Code Online (Sandbox Code Playgroud)
当我的内容适合客户区域时,这很好用:
但是当内容溢出客户区时会出现问题:
有没有办法让我可以获得整个控件内容,而无需调整屏幕元素的大小?
编辑: 这是Treeview XAML:
<TreeView x:Name="ProjectTree" Grid.Row="1"
ItemContainerStyle="{StaticResource ShinyTreeView}"
HorizontalContentAlignment="Stretch"
MouseDoubleClick="TreeView_OnMouseDoubleClick"
Style="{StaticResource CodeExplorerTreeViewStyle}" BorderThickness="0,1" …Run Code Online (Sandbox Code Playgroud)