我使用以下代码在C中创建一个位图并启用一个位.但问题是,当我正在阅读它时,我获得了比预期更高的位.
#define BITS_PER_WORD (sizeof(uint32_t) * CHAR_BIT)
#define WORD_OFFSET(b) ((b) / BITS_PER_WORD)
#define BIT_OFFSET(b) ((b) % BITS_PER_WORD)
main ()
{
// declarations
int val = 2;
init_bits(&bmp);
set_bit(&bmp,val);
for (id = 0; id < sizeof(bmp); id++)
{
if (bmp & (1 << id))
{
trace(debug, "bit:%x", bmp,);
}
}
}
init_bits(uint32_t *words) {
(void)memset((void*)words, 0, sizeof(uint32_t));
}
set_bit(uint32_t *words, int n) {
words[WORD_OFFSET(n)] |= (1 << BIT_OFFSET(n));
}
Run Code Online (Sandbox Code Playgroud)
所以例如,如果我执行set_bit(&bmp,2)然后我得到4(而不是2)十六进制和10(而不是8)for set_bit(&bmp,4),依此类推.
任何帮助是极大的赞赏!
在我的项目中,一个位图充满了文本和另一个位图,将文本添加到位图的方法返回一个BitmapDrawable。
我想将此BitmapDrawable保存为pdf文件,以便可以通过电子邮件发送原始的位图,并添加文本和其他图像。
为此,我需要一个常规的位图而不是BitmapDrawable。我似乎找不到任何答案,因为我没有在drawable文件夹中对drawable的引用,我只有一个BitmapDrawable可以使用。
有什么想法吗?
我不知道发生了什么,起初它现在正在运行我有这个错误这是我的代码:
我不知道发生了什么,起初它现在正在运行我有这个错误这是我的代码:
我不知道发生了什么,起初它现在正在运行我有这个错误这是我的代码:
public void allFile() {
mTempDir = Environment.getExternalStorageDirectory()
+ "/MyCameraBooth/Photo/";
File mTempFile = new File(mTempDir);
if (!mTempFile.exists()) {
mTempFile.mkdirs();
}
mBackground = Bitmap.createBitmap(1800, 1200, Bitmap.Config.RGB_565);
BitmapFactory.Options options = new BitmapFactory.Options();
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
File f = new File(AppConstant.filepathone);
Bitmap mImageone = decodeFile(f);
File g = new File(AppConstant.filepathtwo);
Bitmap mImagetwo = decodeFile(g);
File h = new File(AppConstant.filepaththree);
Bitmap mImagethree = decodeFile(h);
File i = new File(AppConstant.filepathfour);
Bitmap mImagefour = decodeFile(i);
Map<String, Bitmap> mBgMap = new HashMap<String, Bitmap>();
mBgMap.put("Frame1", BitmapFactory.decodeResource(getResources(), …Run Code Online (Sandbox Code Playgroud) 我有下一个观点:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="350dp"
android:layout_height="350dp"
android:orientation="horizontal">
<LinearLayout
android:layout_width="140dp"
android:layout_height="match_parent"
android:layout_marginRight="2.5dp"
android:orientation="vertical">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="2.5dp"
android:layout_weight="1"
android:longClickable="true"
android:scaleType="matrix"
android:src="@drawable/a1" />
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="2.5dp"
android:layout_weight="1"
android:longClickable="true"
android:scaleType="matrix"
android:src="@drawable/a2" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/transparent">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_marginLeft="2.5dp"
android:longClickable="true"
android:scaleType="matrix"
android:src="@drawable/a4" />
</LinearLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
看起来像: 
在此视图中,用户可以编辑此图片的视图(缩放,旋转)
我必须保存编辑的照片拼贴。如何保存带有缩放和旋转照片的视图?是否可以将位图中的编辑视图保存到应用程序缓存中?
谢谢你的帮助!
我试图实现位图字体渲染.唯一令我困惑的是,我必须在这里问一下,当我为每个焦点绘制四边形时,每次渲染一个新的四边形时,UV都绝对会被破坏.如果我只渲染一个四边形,一切都OK.
(瓦片x = 3,y = 4)
这是多少字母的样子.

这是我的代码来渲染这些东西:
...
rc.translate(getTransform().getPos());
drawTileAt(3, 4);
rc.translate(100, 0, 0);
drawTileAt(5, 5);
rc.translate(200, 0, 0);
drawTileAt(2,6);
rc.translate(300,0,0);
drawTileAt(1, 7);
...
public void drawTileAt(int x, int y)
{
float w = 1f / 16f;
float _x = 1f / 16f * x;
float _y = 1f / 16f * y;
GL11.glBegin(GL11.GL_QUADS);
GL11.glVertex2f(0, 100);GL11.glTexCoord2f(_x,_y);
GL11.glVertex2f(0, 0);GL11.glTexCoord2f(_x + w,_y);
GL11.glVertex2f(100,0);GL11.glTexCoord2f(_x + w,_y + w);
GL11.glVertex2f(100, 100);
GL11.glTexCoord2f(_x,_y + w);
GL11.glEnd();
}
Run Code Online (Sandbox Code Playgroud)
我也用tex-coords绘制VBO四边形,一切看起来都很好......
如何使用canvas使用canvas.drawBitmap()绘制位图的一部分?
例如,我有以下位图

我只需画这部分

是否可以使用canvas.drawBitmap或者我还需要其他东西?
我正在使用BitBlt在我的按钮上显示位图.对于大多数情况,它很好,但有一个内存泄漏导致程序在一段时间后崩溃.我做错了什么?
int Springboard::DrawBasicButtons(DRAWITEMSTRUCT* pdis, HINSTANCE hInstance){
RECT rect;
static HBITMAP hCurrIcon, hIconoff, hIconon;
rect = pdis->rcItem;
HFONT font = CreateFont(13, 0, 0, 0, 300, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH, L"Arial");
TCHAR Txtstr[MAX_PATH];
BOOL isText = FALSE;
int textsize;
if (IDC_HOLD == pdis->CtlID) {
hIconoff = (HBITMAP) LoadBitmap(hInstance, MAKEINTRESOURCE(BASIC_HOLDOFF));
hIconon = (HBITMAP) LoadBitmap(hInstance, MAKEINTRESOURCE(BASIC_HOLDON));
_tcscpy( Txtstr, _T("Hold "));
isText = TRUE;
if (pdis->itemState & ODS_SELECTED) hCurrIcon = hIconon;
else hCurrIcon = hIconoff;
}
HDC hdc = CreateCompatibleDC(pdis->hDC);
SelectObject(hdc, …Run Code Online (Sandbox Code Playgroud) 我想得到任何图像,将其转换为位图,将其大小调整为(1024,16)然后获取每个像素的RGB值.
这是我调整大小的功能
public Bitmap Resize(bitmap image1)
{
Bitmap image2 = new Bitmap(16, 1024);
Graphics gr = Graphics.FromImage(image2);
gr.DrawImage(image1,0,0,image2.Height,image2.Width);
return image2;
}
Run Code Online (Sandbox Code Playgroud)
然后这是我的函数,以获取每个像素的RGB值并将其写入文本文件
for (int y = 0; y < image2.Height; y++)
{
for (int x = 0; x < image2.Width; x++)
{
Color pixelcolor = image2.GetPixel(x,y);
byte weR = pixelcolor.R;
byte weG = pixelcolor.G;
byte weB = pixelcolor.B;
sR.WriteLine(weR.ToString());
sR.WriteLine(weG.ToString());
sR.WriteLine(weB.ToString());
sR.WriteLine();
}
}
Run Code Online (Sandbox Code Playgroud)
但问题是,在循环256次之后,RGB值变为0并且如果像素则不会再次变化.也就是说,它为图像提供正确的RGB值256次,然后一切都变为0.
任何颜色的任何图像都会发生这种情况.
请问我的代码有什么问题?
我正在研究一个小的测试代码.它选择一个图像,根据屏幕密度调整其大小以适应屏幕.当它这样做时,它会以图像的大小xxhdpi显示图像的副本,然后转换为位图,然后转换为字符串.然后将String通过Intent传递到下一个屏幕,在该屏幕中String被转回Bitmap,然后放入ImageButton.
这很好用,直到我添加了一大块代码来调整基于密度的字符串给出的图像大小.奇怪的是我从另一个活动中复制并粘贴了DPI()方法,并且该活动没有任何问题.
package com.example.zachary.imagetesting.Resizing;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.util.Base64;
import android.view.View;
import android.widget.ImageButton;
import android.widget.TextView;
import com.example.zachary.imagetesting.R;
public class PictureDecoded extends Activity {
TextView Text;
ImageButton Image;
String string;
Bitmap picture;
public float DPI(){return getResources().getDisplayMetrics().density;}
float dpi = DPI() * 180;
int size = (int) dpi;
public Bitmap Pic(String string){
try{
byte[] b = Base64.decode(string, Base64.DEFAULT);
Bitmap bitmap = BitmapFactory.decodeByteArray(b, 0, b.length);
return bitmap;
} catch (Exception e) { …Run Code Online (Sandbox Code Playgroud) 我试图用C#调用几个Delphi函数:
MyType =array [1 .. 124] of byte
procedure f(bytes: MyType); stdcall;
external 'my.dll' name 'f';
Run Code Online (Sandbox Code Playgroud)
那是我的第一个问题.我试过了:
[DllImport("Delphi/my.dll",
CallingConvention = CallingConvention.StdCall,
CharSet = CharSet.Auto)]
public static extern
void sygLadSyg([MarshalAs(UnmanagedType.LPArray)] byte[] myArray);
void sygLadSyg([MarshalAs(UnmanagedType.SafeArray)] byte[] myArray);
Run Code Online (Sandbox Code Playgroud)
我得到例外:
对PInvoke函数的调用使堆栈失衡.这很可能是因为托管PInvoke签名与非托管目标签名不匹配.检查PInvoke签名的调用约定和参数是否与目标非托管签名匹配.
我究竟做错了什么?
第二个问题是传递位图.
function sygAnaliz(bitmapa: TBitmap): byte; stdcall;
external 'awSygnat1.dll' name 'sygAnaliz';
[DllImport("Delphi/awSygnat1.dll",
CallingConvention = CallingConvention.StdCall,
CharSet = CharSet.Ansi)]
public static extern
byte sygAnaliz(IntPtr bitmapPtr);
// and call itself
sygAnaliz(firstIMG.GetHbitmap());
Run Code Online (Sandbox Code Playgroud)
我得到异常:尝试读取或写入受保护的内存.这通常表明其他内存已损坏.
这两种功能都是内存安全的,因为它们已经使用了几年而效果很好.也许有一些我想念的东西?